http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11458
Revision: 11458 Author: drtrigon Date: 2013-04-26 11:25:54 +0000 (Fri, 26 Apr 2013) Log Message: ----------- follow-up to previous output/logging changes (minor improvements and bug fixes)
Modified Paths: -------------- trunk/pywikipedia/catimages.py trunk/pywikipedia/subster.py trunk/pywikipedia/subster_irc.py trunk/pywikipedia/sum_disc.py
Modified: trunk/pywikipedia/catimages.py =================================================================== --- trunk/pywikipedia/catimages.py 2013-04-25 19:56:41 UTC (rev 11457) +++ trunk/pywikipedia/catimages.py 2013-04-26 11:25:54 UTC (rev 11458) @@ -3481,11 +3481,11 @@ # skip if download not possible pywikibot.warning(u"%s, skipped..." % err) continue - except Exception, err: + except: # skip on any unexpected error, but report it - pywikibot.error(u"%s" % err) + pywikibot.exception(tb=True) pywikibot.error(u"was not able to process page %s !!!\n" %\ - image.title(asLink=True)) + image.title(asLink=True)) continue resultCheck = Bot.checkStep() tagged = False @@ -3494,6 +3494,7 @@ if ret: outresult.append( ret ) except AttributeError: + pywikibot.exception(tb=True) pywikibot.error(u"was not able to process page %s !!!\n" %\ image.title(asLink=True)) limit += -1
Modified: trunk/pywikipedia/subster.py =================================================================== --- trunk/pywikipedia/subster.py 2013-04-25 19:56:41 UTC (rev 11457) +++ trunk/pywikipedia/subster.py 2013-04-26 11:25:54 UTC (rev 11458) @@ -138,12 +138,7 @@ 'EditFlags': {'minorEdit': True, 'botflag': True}, }
-# debug tools -# (look at 'bot_control.py' for more info) -debug = [] -#debug.append( 'code' ) # code debugging
- class SubsterBot(basic.AutoBasicBot): ''' Robot which will does substitutions of tags within wiki page content with external or @@ -161,8 +156,6 @@
pywikibot.output(u'\03{lightgreen}* Initialization of bot:\03{default}')
- logging.basicConfig(level=logging.DEBUG if ('code' in debug) else logging.INFO) - basic.AutoBasicBot.__init__(self)
# modification of timezone to be in sync with wiki @@ -182,8 +175,6 @@ if self.site.is_data_repository(): self._bot_config['VerboseMessage'] = self._bot_config['data_VerboseMessage']
- self._debug = debug - # init constants self._userListPage = pywikibot.Page(self.site, self._bot_config['TemplateName']) self._ConfCSSpostprocPage = pywikibot.Page(self.site, self._bot_config['ConfCSSpostproc'])
Modified: trunk/pywikipedia/subster_irc.py =================================================================== --- trunk/pywikipedia/subster_irc.py 2013-04-25 19:56:41 UTC (rev 11457) +++ trunk/pywikipedia/subster_irc.py 2013-04-26 11:25:54 UTC (rev 11458) @@ -39,11 +39,7 @@
# Configuration imported from 'subster.py'.
-# debug tools -# (look at 'bot_control.py' and 'subster.py' for more info) -debug = []
- class SubsterTagModifiedBot(articlenos.ArtNoDisp): # def __init__(self, site, channel, nickname, server, port=6667): # SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname) @@ -146,7 +142,6 @@
def main(): args = pywikibot.handleArgs() - subster.debug = debug site = pywikibot.getSite() site.forceLogin() chan = '#' + site.language() + '.' + site.family.name
Modified: trunk/pywikipedia/sum_disc.py =================================================================== --- trunk/pywikipedia/sum_disc.py 2013-04-25 19:56:41 UTC (rev 11457) +++ trunk/pywikipedia/sum_disc.py 2013-04-26 11:25:54 UTC (rev 11458) @@ -221,16 +221,13 @@ }, }
-# debug tools -# (look at 'bot_control.py' for more info) -debug = [] # no write, all users -#debug.append( 'user' ) # skip users -#debug.append( 'page' ) # skip pages -#debug.append( 'write2hist' ) # write history (operational mode) -#debug.append( 'toolserver' ) # toolserver down -#debug.append( 'code' ) # code debugging -debug_params = {'user': lambda user: (user.name() != u'DrTrigon'), - 'page': lambda page: (page.title() != u'...'),} +# debug switches +_debug_switch = { + #'user': lambda user: (user.name() != u'DrTrigon'), + 'user': lambda user: False, + #'page': lambda page: (page.title() != u'...'), + 'page': lambda page: False, +}
docuReplacements = { # '¶ms;': pagegenerators.parameterHelp @@ -260,9 +257,6 @@
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)
# modification of timezone to be in sync with wiki @@ -276,9 +270,7 @@ self._bot_config['TemplateName'] = pywikibot.Page(self.site, self._bot_config['TemplateName']).title() self._template_regex = re.compile('{{' + self._bot_config['TemplateName'] + '(.*?)}}', re.S)
- self._debug = debug
- lang = locale.locale_alias.get(self.site.lang, locale.locale_alias['en']).split('.')[0] # use e.g. 'de_DE.UTF-8', 'de_DE.utf8' (thus no decode('latin-1') anymore!) locale.setlocale(locale.LC_TIME, lang + '.UTF-8') @@ -326,10 +318,10 @@
pywikibot.output(u'\03{lightgreen}* Processing User List (wishes):\03{default}')
- if 'user' in debug: pywikibot.output(u'\03{lightyellow}=== ! DEBUG MODE USERS WILL BE SKIPPED ! ===\03{default}') - for user in self._user_list: # may be try with PreloadingGenerator?! - if (('user' in debug) and debug_params['user'](user)): continue + if _debug_switch['user'](user): + pywikibot.warning(u'\03{lightyellow}=== ! USER WILL BE SKIPPED ! ===\03{default}') + continue
# set user and init params self.setUser(user) @@ -803,7 +795,9 @@ #gen4 = pagegenerators.RedirectFilterPageGenerator(gen3) # lets hope that no generator loses pages... (since sometimes this may happen) for page in gen3: - if (('page' in debug) and debug_params['page'](page)): continue + if _debug_switch['page'](page): + pywikibot.warning(u'\03{lightyellow}=== ! PAGE WILL BE SKIPPED ! ===\03{default}') + continue
name = page.title() #print ">>>", name, "<<<" @@ -898,8 +892,8 @@ hist = self.pages.hist
# get global wiki notifications (toolserver/merl) - if 'toolserver' in debug: - pywikibot.output(u'\03{lightyellow}=== ! DEBUG MODE TOOLSERVER ACCESS WILL BE SKIPPED ! ===\03{default}') + if pywikibot.simulate: + pywikibot.warning(u'\03{lightyellow}=== ! TOOLSERVER ACCESS WILL BE SKIPPED ! ===\03{default}') globalnotify = [] else: globalnotify = self._globalnotifications() @@ -1088,10 +1082,10 @@
pywikibot.output(u'\03{lightpurple}*** Discussion updates added to: %s (purge: %s)\03{default}' % (self._userPage.title(asLink=True), purge))
- if 'write2hist' in debug: + if not pywikibot.simulate: self.putHistory(self.pages.hist) else: - pywikibot.output(u'\03{lightyellow}=== ! DEBUG MODE NOTHING WRITTEN TO HISTORY ! ===\03{default}') + pywikibot.warning(u'\03{lightyellow}=== ! NOTHING WRITTEN TO HISTORY ! ===\03{default}') else: pywikibot.output(u'\03{lightpurple}*** Discussion up to date: NOTHING TO DO\03{default}')
@@ -1420,8 +1414,7 @@ self._user = user
# code debugging - if 'code' in debug: - pywikibot.output(page.title()) + pywikibot.debug(page.title())
# get content and sections (content was preloaded earlier) #buf = page.get(force=True)
pywikipedia-svn@lists.wikimedia.org