jenkins-bot submitted this change.

View Change


Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[IMPR] Improvements for archivebot.py

- add preload_pages() to PageArchiver to avoid deeply nested control flow
- add show_md5_key() function to show the MD5 key only

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

diff --git a/scripts/archivebot.py b/scripts/archivebot.py
index 07f4771..a530410 100755
--- a/scripts/archivebot.py
+++ b/scripts/archivebot.py
@@ -635,6 +635,16 @@
params['monthnameshort'] = monthnames['short']
return params

+ def preload_pages(self, counter: int, thread, pattern) -> None:
+ """Preload pages if counter matters."""
+ if counter < 25:
+ return
+
+ for c in range(counter):
+ params = self.get_params(thread.timestamp, c + 1)
+ self.get_archive_page(pattern % params, params)
+ list(self.site.preloadpages(self.archives.values()))
+
def analyze_page(self) -> Set[ShouldArchive]:
"""Analyze DiscussionPage."""
max_size = self.get_attr('maxarchivesize')
@@ -712,13 +722,7 @@

if counter_matters:

- # preload pages
- if counter >= 25:
- for c in range(counter):
- params = self.get_params(thread.timestamp, c + 1)
- self.get_archive_page(pattern % params, params)
- list(self.site.preloadpages(self.archives.values()))
-
+ self.preload_pages(counter, thread, pattern)
while not counter_found and counter > 1 \
and not archive.exists():
# This may happen when either:
@@ -847,6 +851,24 @@
return True


+def show_md5_key(calc, salt, site) -> bool:
+ """Show calculated MD5 hexdigest."""
+ if not calc:
+ return False
+
+ if not salt:
+ pywikibot.bot.suggest_help(missing_parameters=['-salt'])
+ else:
+ page = pywikibot.Page(site, calc)
+ if page.exists():
+ calc = page.title()
+ else:
+ pywikibot.info(
+ f'NOTE: the specified page "{calc}" does not (yet) exist.')
+ pywikibot.info(f'key = {calc_md5_hexdigest(calc, salt)}')
+ return True
+
+
def main(*args: str) -> None:
"""
Process command line arguments and invoke bot.
@@ -902,18 +924,7 @@

site = pywikibot.Site()

- if calc:
- if not salt:
- pywikibot.bot.suggest_help(missing_parameters=['-salt'])
- return
- page = pywikibot.Page(site, calc)
- if page.exists():
- calc = page.title()
- else:
- pywikibot.info(
- 'NOTE: the specified page "{}" does not (yet) exist.'
- .format(calc))
- pywikibot.info(f'key = {calc_md5_hexdigest(calc, salt)}')
+ if show_md5_key(calc, salt, site):
return

if not templates:

To view, visit change 904829. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Iaa84ebd3b73b9f513eeae7ce34d71af0f0fef1b7
Gerrit-Change-Number: 904829
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki@aol.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged