jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/820660 )

Change subject: [IMPR] detach process_page function from main
......................................................................

[IMPR] detach process_page function from main

Change-Id: I542c06e3b2ab1e10509794a33a7000e75d115d07
---
M scripts/archivebot.py
1 file changed, 32 insertions(+), 19 deletions(-)

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



diff --git a/scripts/archivebot.py b/scripts/archivebot.py
index 305e7fa..69fa1d6 100755
--- a/scripts/archivebot.py
+++ b/scripts/archivebot.py
@@ -787,6 +787,37 @@
             self.page.update(comment)


+def process_page(pg, tmpl, salt: str, force: bool, keep: bool) -> bool:
+    """Call PageArchiver for a single page.
+
+    :return: Return True to continue with the next page, False to break
+        the loop.
+
+    .. versionadded:: 7.6
+    """
+    if not pg.exists():
+        pywikibot.info('{} does not exist, skipping...'.format(pg))
+        return True
+
+    pywikibot.info('\n\n>>> <<lightpurple>>{}<<default>> <<<'.format(pg))
+    # Catching exceptions, so that errors in one page do not bail out
+    # the entire process
+    try:
+        archiver = PageArchiver(pg, tmpl, salt, force, keep)
+        archiver.run()
+    except ArchiveBotSiteConfigError as e:
+        # no stack trace for errors originated by pages on-site
+        pywikibot.error('Missing or malformed template in page {}: {}'
+                        .format(pg, e))
+    except Exception:
+        pywikibot.exception('Error occurred while processing page {}'
+                            .format(pg))
+    except KeyboardInterrupt:
+        pywikibot.info('\nUser quit bot run...')
+        return False
+    return True
+
+
 def main(*args: str) -> None:
     """
     Process command line arguments and invoke bot.
@@ -870,25 +901,7 @@
                                      namespaces=ns,
                                      content=True)
         for pg in gen:
-            if not pg.exists():
-                pywikibot.info('{} does not exist, skipping...'.format(pg))
-                continue
-            pywikibot.info('\n\n>>> <<lightpurple>>{}<<default>> <<<'
-                           .format(pg.title()))
-            # Catching exceptions, so that errors in one page do not bail out
-            # the entire process
-            try:
-                archiver = PageArchiver(pg, tmpl, salt, force, keep)
-                archiver.run()
-            except ArchiveBotSiteConfigError as e:
-                # no stack trace for errors originated by pages on-site
-                pywikibot.error('Missing or malformed template in page {}: {}'
-                                .format(pg, e))
-            except Exception:
-                pywikibot.exception('Error occurred while processing page {}'
-                                    .format(pg))
-            except KeyboardInterrupt:
-                pywikibot.info('\nUser quit bot run...')
+            if not process_page(pg, tmpl, salt, force, keep):
                 return



--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/820660
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I542c06e3b2ab1e10509794a33a7000e75d115d07
Gerrit-Change-Number: 820660
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to