John Vandenberg has uploaded a new change for review. https://gerrit.wikimedia.org/r/166397
Change subject: Move standard page save exception handling into Bot ...................................................................... Move standard page save exception handling into Bot Most bots wish to continue processing pages from their generator even if a page fails to save, whether because of a page-specific or server related error. This functionality is not enabled by default. reflinks.py has been migrated to use this functionality. Change-Id: I34898b36f915a1399522040201aac84fa8f1324c --- M pywikibot/bot.py M scripts/reflinks.py 2 files changed, 37 insertions(+), 17 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core refs/changes/97/166397/1 diff --git a/pywikibot/bot.py b/pywikibot/bot.py index 8fbf9ad..f669d51 100644 --- a/pywikibot/bot.py +++ b/pywikibot/bot.py @@ -900,6 +900,12 @@ Option used: * 'always' + + Keyword args used: + * 'async' - passed to page.save + * 'comment' - passed to page.save + * 'ignore_save_related_errors' - report and ignore + * 'ignore_server_errors' - report and ignore """ if oldtext == newtext: pywikibot.output(u'No changes were needed on %s' @@ -918,7 +924,34 @@ kwargs['async'] = True page.text = newtext - page.save(**kwargs) + + ignore_save_related_errors = kwargs.pop('ignore_save_related_errors', False) + ignore_server_errors = kwargs.pop('ignore_server_errors', False) + + try: + page.save(**kwargs) + except pywikibot.PageSaveRelatedError as e: + if not ignore_save_related_errors: + raise + if isinstance(e, pywikibot.EditConflict): + pywikibot.output(u'Skipping %s because of edit conflict' + % page.title()) + elif isinstance(e, pywikibot.SpamfilterError): + pywikibot.output( + u'Cannot change %s because of blacklist entry %s' + % (page.title(), e.url)) + elif isinstance(e, pywikibot.LockedPage): + pywikibot.output(u'Skipping %s (locked page)' + % page.title()) + else: + pywikibot.error( + u'Skipping %s because of a save related error: %s' + % (page.title(), e)) + except pywikibot.ServerError as e: + if not ignore_server_errors: + raise + pywikibot.error(u'Server Error while processing %s: %s' + % (page.title(), e)) def quit(self): """Cleanup and quit processing.""" diff --git a/scripts/reflinks.py b/scripts/reflinks.py index 477b668..f0b7d61 100644 --- a/scripts/reflinks.py +++ b/scripts/reflinks.py @@ -744,22 +744,9 @@ new_text = self.deduplicator.process(new_text) - try: - self.userPut(page, page.text, new_text, comment=self.msg) - except pywikibot.EditConflict: - pywikibot.output(u'Skipping %s because of edit conflict' - % page.title()) - except pywikibot.SpamfilterError as e: - pywikibot.output( - u'Cannot change %s because of blacklist entry %s' - % (page.title(), e.url)) - except pywikibot.LockedPage: - pywikibot.output(u'Skipping %s (locked page)' - % page.title()) - except pywikibot.PageNotSaved as error: - pywikibot.error(u'putting page: %s' % (error.args,)) - except pywikibot.ServerError as e: - pywikibot.output(u'Server Error : %s' % e) + self.userPut(page, page.text, new_text, comment=self.msg, + ignore_save_related_errors=True, + ignore_server_errors=True) if new_text == page.text: continue -- To view, visit https://gerrit.wikimedia.org/r/166397 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I34898b36f915a1399522040201aac84fa8f1324c Gerrit-PatchSet: 1 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: John Vandenberg <jay...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits