http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10357
Revision: 10357 Author: drtrigon Date: 2012-06-13 11:59:13 +0000 (Wed, 13 Jun 2012) Log Message: ----------- follow-up; minor changes and bug fixes for r10354
Modified Paths: -------------- trunk/pywikipedia/basic.py trunk/pywikipedia/sum_disc.py trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/basic.py =================================================================== --- trunk/pywikipedia/basic.py 2012-06-13 11:40:44 UTC (rev 10356) +++ trunk/pywikipedia/basic.py 2012-06-13 11:59:13 UTC (rev 10357) @@ -9,7 +9,9 @@
¶ms;
-- +-summary:XYZ Set the summary message text for the edit to XYZ, bypassing + the predefined message texts with original and replacements + inserted.
All other parameters will be regarded as part of the title of a single page, and the bot will only work on that single page. @@ -39,7 +41,7 @@ # The file containing these messages should have the same name as the caller # script (i.e. basic.py in this case)
- def __init__(self, generator, dry): + def __init__(self, generator, dry, summary): """ Constructor. Parameters: @param generator: The page generator that determines on which pages @@ -48,13 +50,18 @@ @param dry: If True, doesn't do any real changes, but only shows what would have been changed. @type dry: boolean. + @param summary: Set the summary message text for the edit. + @type summary: (unicode) string. """ self.generator = generator self.dry = dry # init constants self.site = pywikibot.getSite(code=pywikibot.default_code) # Set the edit summary message - self.summary = i18n.twtranslate(self.site, 'basic-changing') + if summary: + self.summary = summary + else: + self.summary = i18n.twtranslate(self.site, 'basic-changing')
def run(self): for page in self.generator: @@ -137,7 +144,7 @@ _REGEX_eol = re.compile(u'\n')
def __init__(self): - BasicBot.__init__(self, None, None) + BasicBot.__init__(self, None, None, None)
## @since 10326 # @remarks needed by various bots @@ -259,13 +266,18 @@ # This temporary array is used to read the page title if one single # page to work on is specified by the arguments. pageTitleParts = [] + # summary message + editSummary = ''
# Parse command line arguments for arg in pywikibot.handleArgs(): - # check if a standard argument like - # -start:XYZ or -ref:Asdf was given. - if not genFactory.handleArg(arg): - pageTitleParts.append(arg) + if arg.startswith('-summary:'): + editSummary = arg[9:] + else: + # check if a standard argument like + # -start:XYZ or -ref:Asdf was given. + if not genFactory.handleArg(arg): + pageTitleParts.append(arg)
if pageTitleParts != []: # We will only work on a single page. @@ -279,7 +291,7 @@ # The preloading generator is responsible for downloading multiple # pages from the wiki simultaneously. gen = pagegenerators.PreloadingGenerator(gen) - bot = BasicBot(gen, pywikibot.simulate) + bot = BasicBot(gen, pywikibot.simulate, editSummary) bot.run() else: pywikibot.showHelp()
Modified: trunk/pywikipedia/sum_disc.py =================================================================== --- trunk/pywikipedia/sum_disc.py 2012-06-13 11:40:44 UTC (rev 10356) +++ trunk/pywikipedia/sum_disc.py 2012-06-13 11:59:13 UTC (rev 10357) @@ -228,7 +228,6 @@ # debug tools # (look at 'bot_control.py' for more info) debug = [] # no write, all users -#debug.append( 'write2wiki' ) # write to wiki (operational mode) #debug.append( 'user' ) # skip users #debug.append( 'page' ) # skip pages #debug.append( 'write2hist' ) # write history (operational mode) @@ -313,7 +312,7 @@ pywikibot.output(u'\03{lightred}** Receiving Job Queue (Maintenance Messages)\03{default}') page = pywikibot.Page(self.site, bot_config['maintenance_queue']) self.maintenance_msg = self.loadJobQueue(page, bot_config['queue_security'], - reset=('write2wiki' in self._debug)) + reset=(not pywikibot.simulate))
self._wday = time.gmtime().tm_wday
@@ -1054,49 +1053,46 @@ pywikibot.output(u'===='*15 + u'\n' + buf + u'\n' + u'===='*15) pywikibot.output(u'[%i entries]' % count )
- if 'write2wiki' in debug: - head = i18n.twtranslate(self.site, - 'thirdparty-drtrigonbot-sum_disc-summary-head') \ - + u' ' - add = i18n.twtranslate(self.site, - 'thirdparty-drtrigonbot-sum_disc-summary-add') - mod = i18n.twtranslate(self.site, - 'thirdparty-drtrigonbot-sum_disc-summary-mod') - clean = i18n.twtranslate(self.site, - 'thirdparty-drtrigonbot-sum_disc-summary-clean') - if not self._mode: - # default: write direct to user disc page - comment = head + add % {'num':count} - #self.append(self._userPage, buf, comment=comment, minorEdit=False) - (page, text, minEd) = (self._userPage, buf, False) - else: - # enhanced (with template): update user disc page and write to user specified page - tmplsite = pywikibot.Page(self.site, self._tmpl_data) - comment = head + mod % {'num':count, 'page':tmplsite.title(asLink=True)} - self.save(self._userPage, self._content, comment=comment, minorEdit=False) - comment = head + add % {'num':count} - #self.append(tmplsite, buf, comment=comment) - (page, text, minEd) = (tmplsite, buf, True) # 'True' is default - if (self._param['cleanup_count'] < 0): - # default mode, w/o cleanup - try: - self.append(page, text, comment=comment, minorEdit=minEd) - except pywikibot.MaxTriesExceededError: - logging.getLogger('sum_disc').warning( - u'Problem MaxTriesExceededError occurred, thus skipping this user!') - return # skip history write - else: - # append with cleanup - text = self.cleanupDiscSum( self.load(page) or u'', - days=self._param['cleanup_count'] ) + u'\n\n' + text - comment = head + clean % {'num':count} - self.save(page, text, comment=comment, minorEdit=minEd) - purge = self._userPage.purgeCache() - - pywikibot.output(u'\03{lightpurple}*** Discussion updates added to: %s (purge: %s)\03{default}' % (self._userPage.title(asLink=True), purge)) + head = i18n.twtranslate(self.site, + 'thirdparty-drtrigonbot-sum_disc-summary-head') \ + + u' ' + add = i18n.twtranslate(self.site, + 'thirdparty-drtrigonbot-sum_disc-summary-add') + mod = i18n.twtranslate(self.site, + 'thirdparty-drtrigonbot-sum_disc-summary-mod') + clean = i18n.twtranslate(self.site, + 'thirdparty-drtrigonbot-sum_disc-summary-clean') + if not self._mode: + # default: write direct to user disc page + comment = head + add % {'num':count} + #self.append(self._userPage, buf, comment=comment, minorEdit=False) + (page, text, minEd) = (self._userPage, buf, False) else: - pywikibot.output(u'\03{lightyellow}=== ! DEBUG MODE NOTHING WRITTEN TO WIKI ! ===\03{default}') + # enhanced (with template): update user disc page and write to user specified page + tmplsite = pywikibot.Page(self.site, self._tmpl_data) + comment = head + mod % {'num':count, 'page':tmplsite.title(asLink=True)} + self.save(self._userPage, self._content, comment=comment, minorEdit=False) + comment = head + add % {'num':count} + #self.append(tmplsite, buf, comment=comment) + (page, text, minEd) = (tmplsite, buf, True) # 'True' is default + if (self._param['cleanup_count'] < 0): + # default mode, w/o cleanup + try: + self.append(page, text, comment=comment, minorEdit=minEd) + except pywikibot.MaxTriesExceededError: + logging.getLogger('sum_disc').warning( + u'Problem MaxTriesExceededError occurred, thus skipping this user!') + return # skip history write + else: + # append with cleanup + text = self.cleanupDiscSum( self.load(page) or u'', + days=self._param['cleanup_count'] ) + u'\n\n' + text + comment = head + clean % {'num':count} + self.save(page, text, comment=comment, minorEdit=minEd) + purge = self._userPage.purgeCache()
+ pywikibot.output(u'\03{lightpurple}*** Discussion updates added to: %s (purge: %s)\03{default}' % (self._userPage.title(asLink=True), purge)) + if 'write2hist' in debug: self.putHistory(self.pages.hist) else:
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2012-06-13 11:40:44 UTC (rev 10356) +++ trunk/pywikipedia/wikipedia.py 2012-06-13 11:59:13 UTC (rev 10357) @@ -8103,7 +8103,7 @@ elif arg == '-cosmeticchanges' or arg == '-cc': config.cosmetic_changes = not config.cosmetic_changes output(u'NOTE: option cosmetic_changes is %s\n' % config.cosmetic_changes) - elif arg == '-simulate': + elif arg in ['-simulate', '-dry']: simulate = True # global debug option for development purposes. Normally does nothing. elif arg == '-debug': @@ -8188,8 +8188,10 @@ -cc user_config.py to its inverse and overrules it. All other settings and restrictions are untouched.
--simulate Disables writing to the server. Useful for testing - and debugging of new code. +-simulate Disables writing to the server. Useful for testing and +(-dry) debugging of new code (if given, doesn't do any real + changes, but only shows what would have been changed). + DEPRECATED: please use -simulate instead of -dry '''# % moduleName output(globalHelp, toStdout=True) try: