jenkins-bot has submitted this change and it was merged.
Change subject: replace.py: report number of changed pages ......................................................................
replace.py: report number of changed pages
Aligned with compact. Number of saved pages in now reported at end of execution.
Bug: 71828 Change-Id: I862dea5809abac8298efbede9adec463a31205db --- M scripts/replace.py 1 file changed, 14 insertions(+), 2 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/replace.py b/scripts/replace.py index a2fe1d9..b5e4ec7 100755 --- a/scripts/replace.py +++ b/scripts/replace.py @@ -295,6 +295,7 @@ cat_ns + ':' + addedCat) self.sleep = sleep self.summary = summary + self.changed_pages = 0
def isTitleExcepted(self, title): """ @@ -343,6 +344,11 @@ allowoverlap=self.allowoverlap, site=self.site) return new_text + + def count_changes(self, page, err): + """Count succesfully changed pages.""" + if not isinstance(err, Exception): + self.changed_pages += 1
def run(self): """Start the bot.""" @@ -424,12 +430,12 @@ if choice == 'a': self.acceptall = True if choice == 'y': - page.put_async(new_text, self.summary) + page.put_async(new_text, self.summary, callback=self.count_changes) # choice must be 'N' break if self.acceptall and new_text != original_text: try: - page.put(new_text, self.summary) + page.put(new_text, self.summary, callback=self.count_changes) except pywikibot.EditConflict: pywikibot.output(u'Skipping %s because of edit conflict' % (page.title(),)) @@ -714,6 +720,12 @@ pywikibot.Site().login() bot.run()
+ def display_edit_counter(bot): + pywikibot.output(u'\n%s pages changed.' % bot.changed_pages) + + # Queue last request to display number of changed pages. + pywikibot.async_request(display_edit_counter, bot) +
if __name__ == "__main__": main()
pywikibot-commits@lists.wikimedia.org