jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/820708 )
Change subject: [IMPR] Add -sort option to sort archives by (latest) timestamp ......................................................................
[IMPR] Add -sort option to sort archives by (latest) timestamp
Change-Id: Ic80d4512aee5e3342c156bb97ff09fff8c490255 --- M scripts/archivebot.py 1 file changed, 19 insertions(+), 10 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/archivebot.py b/scripts/archivebot.py index b4f5b1a..c0e2f37 100755 --- a/scripts/archivebot.py +++ b/scripts/archivebot.py @@ -104,11 +104,14 @@ -salt:SALT specify salt -keep Preserve thread order in archive even if threads are archived later + -sort Sort archive by timestamp; should not be used with -keep
.. versionchanged:: 7.6 Localized variables for "archive" template parameter are supported. `User:MiszaBot/config` is the default template. `-keep` option was added. +.. versionchanged:: 7.7 + `-sort` option was added. """ # # (C) Pywikibot team, 2006-2022 @@ -460,7 +463,7 @@ algo = 'none'
def __init__(self, page, template, salt: str, force: bool = False, - keep=False) -> None: + keep: bool = False, sort: bool = False) -> None: """Initializer.
:param page: a page object to be archived @@ -478,6 +481,7 @@ ]) self.salt = salt self.force = force + self.sort = sort self.site = page.site self.tpl = template self.timestripper = TimeStripper(site=self.site) @@ -769,7 +773,7 @@ comment = i18n.twtranslate(self.site.code, 'archivebot-archive-summary', self.comment_params) - archive.update(comment) + archive.update(comment, sort_threads=self.sort)
# Save the page itself self.page.header = rx.sub(self.attr2text(), self.page.header) @@ -797,31 +801,33 @@ self.page.update(comment)
-def process_page(pg, tmpl, salt: str, force: bool, keep: bool) -> bool: +def process_page(page, *args: Any) -> bool: """Call PageArchiver for a single page.
:return: Return True to continue with the next page, False to break the loop.
.. versionadded:: 7.6 + .. versionchanged:: 7.7 + pass an unspecified number of arguments to the bot using ``*args`` """ - if not pg.exists(): - pywikibot.info('{} does not exist, skipping...'.format(pg)) + if not page.exists(): + pywikibot.info('{} does not exist, skipping...'.format(page)) return True
- pywikibot.info('\n\n>>> <<lightpurple>>{}<<default>> <<<'.format(pg)) + pywikibot.info('\n\n>>> <<lightpurple>>{}<<default>> <<<'.format(page)) # Catching exceptions, so that errors in one page do not bail out # the entire process try: - archiver = PageArchiver(pg, tmpl, salt, force, keep) + archiver = PageArchiver(page, *args) 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)) + .format(page, e)) except Exception: pywikibot.exception('Error occurred while processing page {}' - .format(pg)) + .format(page)) except KeyboardInterrupt: pywikibot.info('\nUser quit bot run...') return False @@ -843,6 +849,7 @@ force = False calc = None keep = False + sort = False templates = []
local_args = pywikibot.handle_args(args) @@ -874,6 +881,8 @@ namespace = value elif option == 'keep': keep = True + elif option == 'sort': + sort = True
site = pywikibot.Site()
@@ -911,7 +920,7 @@ namespaces=ns, content=True) for pg in gen: - if not process_page(pg, tmpl, salt, force, keep): + if not process_page(pg, tmpl, salt, force, keep, sort): return