http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10302
Revision: 10302 Author: xqt Date: 2012-06-06 15:38:28 +0000 (Wed, 06 Jun 2012) Log Message: ----------- New option -async enables asynchron saving the page, request bug #3532278 update from rewrite r10301
Modified Paths: -------------- trunk/pywikipedia/cosmetic_changes.py
Modified: trunk/pywikipedia/cosmetic_changes.py =================================================================== --- trunk/pywikipedia/cosmetic_changes.py 2012-06-06 15:36:59 UTC (rev 10301) +++ trunk/pywikipedia/cosmetic_changes.py 2012-06-06 15:38:28 UTC (rev 10302) @@ -11,6 +11,8 @@ -always Don't prompt you for each replacement. Warning (see below) has not to be confirmed. ATTENTION: Use this with care!
+-async Put page on queue to be saved to wiki asynchronously. + -summary:XYZ Set the summary message text for the edit to XYZ, bypassing the predefined message texts with original and replacements inserted. @@ -804,12 +806,13 @@ return text
class CosmeticChangesBot: - def __init__(self, generator, acceptall = False, - comment=u'Robot: Cosmetic changes'): + def __init__(self, generator, acceptall=False, + comment=u'Robot: Cosmetic changes', async=False): self.generator = generator self.acceptall = acceptall self.comment = comment self.done = False + self.async = async
def treat(self, page): try: @@ -832,7 +835,10 @@ self.done = True return if self.acceptall or choice == 'y': - page.put(changedText, comment=self.comment) + if self.async: + page.put_async(changedText, comment=self.comment) + else: + page.put(changedText, comment=self.comment) else: pywikibot.output('No changes were necessary in %s' % page.title()) @@ -863,6 +869,7 @@ editSummary = '' answer = 'y' always = False + async = False # This factory is responsible for processing command line arguments # that are also used by other scripts and that determine on which pages # to work on. @@ -873,6 +880,8 @@ editSummary = arg[len('-summary:'):] elif arg == '-always': always = True + elif arg == '-async': + async = True elif not genFactory.handleArg(arg): pageTitle.append(arg)
@@ -895,7 +904,7 @@ if answer == 'y': preloadingGen = pagegenerators.PreloadingGenerator(gen) bot = CosmeticChangesBot(preloadingGen, acceptall=always, - comment=editSummary) + comment=editSummary, async=async) bot.run()
if __name__ == "__main__":
pywikipedia-svn@lists.wikimedia.org