jenkins-bot has submitted this change and it was merged.

Change subject: archivebot: consistent handling of on-site configuration errors
......................................................................


archivebot: consistent handling of on-site configuration errors

All ending of a run on a page will cause a sleep, with a configurable duration.

Previously a normal return from run() causes a 10-sec sleep,
while an exception causes no sleep and a stack trace will be printed.

Change-Id: I2cbb4026e331d0e23e07c1c8aef344ca194daaaa
---
M scripts/archivebot.py
1 file changed, 21 insertions(+), 8 deletions(-)

Approvals:
  John Vandenberg: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/scripts/archivebot.py b/scripts/archivebot.py
index 1e82623..37ca904 100755
--- a/scripts/archivebot.py
+++ b/scripts/archivebot.py
@@ -112,12 +112,17 @@
 ZERO = datetime.timedelta(0)
 
 
-class MalformedConfigError(pywikibot.Error):
+class ArchiveBotSiteConfigError(pywikibot.Error):
+
+    """There is an error originated by archivebot's on-site configuration."""
+
+
+class MalformedConfigError(ArchiveBotSiteConfigError):
 
     """There is an error in the configuration template."""
 
 
-class MissingConfigError(pywikibot.Error):
+class MissingConfigError(ArchiveBotSiteConfigError):
 
     """
     The config is missing in the header.
@@ -131,7 +136,7 @@
     """Invalid specification of archiving algorithm."""
 
 
-class ArchiveSecurityError(pywikibot.Error):
+class ArchiveSecurityError(ArchiveBotSiteConfigError):
 
     """
     Page title is not a valid archive of page being archived.
@@ -473,7 +478,7 @@
         else:
             raise MissingConfigError(u'Missing or malformed template')
         if not self.get_attr('algo', ''):
-            raise MissingConfigError(u'Missing algo')
+            raise MissingConfigError('Missing argument "algo" in template')
 
     def feed_archive(self, archive, thread, max_archive_size, params=None):
         """Feed the thread to one of the archives.
@@ -554,8 +559,9 @@
             rx = re.compile(r'\{\{%s\s*?\n.*?\n\}\}'
                             % (template_title_regex(self.tpl).pattern), 
re.DOTALL)
             if not rx.search(self.page.header):
-                pywikibot.error("Couldn't find the template in the header")
-                return
+                raise MalformedConfigError(
+                    "Couldn't find the template in the header"
+                )
 
             pywikibot.output(u'Archiving %d thread(s).' % 
self.archived_threads)
             # Save the archives first (so that bugs don't cause a loss of data)
@@ -595,6 +601,7 @@
     salt = None
     force = False
     calc = None
+    sleep = 10
     args = []
 
     def if_arg_value(arg, name):
@@ -624,6 +631,8 @@
             pagename = v
         for v in if_arg_value(arg, '-namespace'):
             namespace = v
+        for v in if_arg_value(arg, '-sleep'):
+            sleep = int(v)
         if not arg.startswith('-'):
             args.append(arg)
 
@@ -678,11 +687,15 @@
             try:
                 archiver = PageArchiver(pg, a, salt, force)
                 archiver.run()
-                time.sleep(10)
+            except ArchiveBotSiteConfigError as e:
+                # no stack trace for errors originated by pages on-site
+                pywikibot.error('Missing or malformed template in page %s: %s'
+                                % (pg, e))
             except Exception:
                 pywikibot.error(u'Error occurred while processing page %s' % 
pg)
                 pywikibot.exception(tb=True)
-
+            finally:
+                time.sleep(sleep)
 
 if __name__ == '__main__':
     main()

-- 
To view, visit https://gerrit.wikimedia.org/r/222727
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I2cbb4026e331d0e23e07c1c8aef344ca194daaaa
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Whym <w...@whym.org>
Gerrit-Reviewer: John Vandenberg <jay...@gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgr...@gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhall...@arctus.nl>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to