http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11397
Revision: 11397 Author: drtrigon Date: 2013-04-20 12:20:45 +0000 (Sat, 20 Apr 2013) Log Message: ----------- bug fix; proper support of -debug by logging, follow-up to r11390 and r11395
Modified Paths: -------------- trunk/pywikipedia/blockreview.py trunk/pywikipedia/patrol.py trunk/pywikipedia/sum_disc.py trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/blockreview.py =================================================================== --- trunk/pywikipedia/blockreview.py 2013-04-20 09:11:14 UTC (rev 11396) +++ trunk/pywikipedia/blockreview.py 2013-04-20 12:20:45 UTC (rev 11397) @@ -140,7 +140,8 @@ talkComment = pywikibot.translate(self.site.lang, self.msg_user % self.parts)
# some test stuff - if pywikibot.debug and self.site().loggedInAs() == u'Xqbot:': + if pywikibot.logger.isEnabledFor(pywikibot.DEBUG) \ + and self.site().loggedInAs() == u'Xqbot:': testPage = pywikibot.Page(self.site, 'Benutzer:Xqt/Test') test = testPage.get() test += note
Modified: trunk/pywikipedia/patrol.py =================================================================== --- trunk/pywikipedia/patrol.py 2013-04-20 09:11:14 UTC (rev 11396) +++ trunk/pywikipedia/patrol.py 2013-04-20 12:20:45 UTC (rev 11397) @@ -150,8 +150,7 @@ # is registered as the user the rest of the structure # refers to. def process_children(obj,current_user): - if pywikibot.debug: - pywikibot.output(u'parsing node: %s' % obj) + pywikibot.debug(u'parsing node: %s' % obj) for c in obj.children: temp = process_node(c,current_user) if temp and not current_user: @@ -227,8 +226,7 @@ if author_ns: author_ns_prefix = self.site.namespace(author_ns)
- if pywikibot.debug: - pywikibot.output(u'Author ns: %d; name: %s' % (author_ns, author_ns_prefix)) + pywikibot.debug(u'Author ns: %d; name: %s' % (author_ns, author_ns_prefix))
if title.find(author_ns_prefix+':') == 0: return True
Modified: trunk/pywikipedia/sum_disc.py =================================================================== --- trunk/pywikipedia/sum_disc.py 2013-04-20 09:11:14 UTC (rev 11396) +++ trunk/pywikipedia/sum_disc.py 2013-04-20 12:20:45 UTC (rev 11397) @@ -260,6 +260,7 @@
pywikibot.output(u'\03{lightgreen}* Initialization of bot:\03{default}')
+ # code debugging logging.basicConfig(level=logging.DEBUG if ('code' in debug) else logging.INFO)
basic.AutoBasicBot.__init__(self) @@ -315,9 +316,6 @@
# init variable/dynamic objects
- # code debugging - pywikibot.debug = ('code' in debug) - ## @todo re-write some functions to be pagegenerators and use pagegenerators.CombinedPageGenerator() # and others to combine and use them # \n[ JIRA: ticket? ]
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2013-04-20 09:11:14 UTC (rev 11396) +++ trunk/pywikipedia/wikipedia.py 2013-04-20 12:20:45 UTC (rev 11397) @@ -5053,7 +5053,7 @@ def run(self): if self.pages: # Sometimes query does not contains revisions - if self.site.has_api() and debug: + if self.site.has_api() and logger.isEnabledFor(DEBUG): while True: try: data = self.getDataApi() @@ -5441,8 +5441,10 @@ # TODO: why isn't this a Site method? pages = list(pages) # if pages is an iterator, we need to make it a list output(u'Getting %d page%s %sfrom %s...' - % (len(pages), (u'', u's')[len(pages) != 1], - (u'', u'via API ')[site.has_api() and debug], site)) + %(len(pages), + (u'', u's')[len(pages) != 1], + (u'', u'via API ')[site.has_api() and logger.isEnabledFor(DEBUG)], + site)) limit = config.special_page_limit / 4 # default is 500/4, but It might have good point for server. if len(pages) > limit: # separate export pages for bulk-retrieve @@ -8831,7 +8833,7 @@ args may be passed as an argument, thereby overriding sys.argv
""" - global default_code, default_family, verbose, debug, simulate + global default_code, default_family, verbose, simulate # get commandline arguments if necessary if not args: args = sys.argv[1:] @@ -8888,7 +8890,9 @@ simulate = True # global debug option for development purposes. Normally does nothing. elif arg == '-debug': - debug = True + if not logger: + setLogfileStatus(False) + logging.getLogger().setLevel(DEBUG) config.special_page_limit = 500 else: # the argument is not global. Let the specific bot script care @@ -8999,7 +9003,6 @@ exec "import %s_interface as uiModule" % config.userinterface ui = uiModule.UI() verbose = 0 -debug = False simulate = False
# TEST for bug #3081100 @@ -9084,7 +9087,7 @@ # NOTE-2: enable 'logger.addHandler(ch)' below in order output to console # also (e.g. for simplifying 'pywikibot.output') global logger - if enabled: + if not logger: if not logname: logname = '%s.log' % calledModuleName() if pywikibot.throttle.pid > 1: @@ -9095,7 +9098,7 @@ if logger.handlers: # init just once (if re-called) logger = logging.getLogger('pywiki') return - logger.setLevel(logging.DEBUG) + logger.setLevel(INFO) # create file handler which logs even debug messages if config.loghandler.upper() == 'RFH': fh = logging.handlers.RotatingFileHandler(filename=logfn, @@ -9118,10 +9121,10 @@ if os.path.exists(logfn) and (ver == int('0206')): t = os.stat(logfn).st_mtime fh.rolloverAt = fh.computeRollover(t) - fh.setLevel(DEBUG if debug else INFO) + fh.setLevel(DEBUG) # create console handler with a higher log level ch = logging.StreamHandler() - ch.setLevel(INFO) + ch.setLevel(DEBUG) # create formatter and add it to the handlers (using LogRecord attributes) formatter = logging.Formatter( fmt='%(asctime)s %(name)18s: %(levelname)-8s %(message)s', @@ -9139,12 +9142,9 @@
if header: writeLogfileHeader() - else: - # disable the log file - if logging.root: # resethandlers of root logger - del logging.root.handlers[:] - logger = logging.getLogger() # root logger
+ logger.propagate = enabled + writeToCommandLogFile()
colorTagR = re.compile('\03{.*?}', re.UNICODE) @@ -9190,7 +9190,8 @@ # instead of logging handler for output to console (StreamHandler) if _level <> INFO: text = u'%s: %s' % (logging.getLevelName(_level), text) - _outputOld(text, decoder, newline, (_level == STDOUT), **kwargs) + if log.isEnabledFor(_level): + _outputOld(text, decoder, newline, (_level == STDOUT), **kwargs)
def _outputOld(text, decoder=None, newline=True, toStdout=False, **kwargs): """Output a message to the user via the userinterface.
pywikipedia-svn@lists.wikimedia.org