jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/445767 )
Change subject: [IMPR] template parameter is a Page object already ......................................................................
[IMPR] template parameter is a Page object already
- remove superfluous generate_transclusions function - rename PageArchiver's tpl parameter to template - rename "a" variable to template_name - rename "a" template variable to tmpl - fix doc strings - fix tests accordingly
Change-Id: Ia4851cf3df3618c6416e8c4c2bf51fd39fe302cd --- M scripts/archivebot.py M tests/archivebot_tests.py 2 files changed, 26 insertions(+), 34 deletions(-)
Approvals: Dalba: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/archivebot.py b/scripts/archivebot.py index 8839a79..a596d00 100755 --- a/scripts/archivebot.py +++ b/scripts/archivebot.py @@ -269,24 +269,6 @@ return val, unit
-def generate_transclusions(site, template, namespaces=[]): - """ - Generate transclusions. - - @param site: the site for the template transclusions - @type site: Site - @param template: normalized title of the template - @type template: unicode - @param namespace: namespace filter for transcluded pages - @type ns: list - """ - pywikibot.output(u'Fetching template transclusions...') - transclusion_page = pywikibot.Page(site, template, ns=10) - return transclusion_page.getReferences(only_template_inclusion=True, - follow_redirects=False, - namespaces=namespaces) - - def template_title_regex(tpl_page): """ Return a regex that matches to variations of the template title. @@ -518,17 +500,22 @@
class PageArchiver(object):
- """ - A class that encapsulates all archiving methods. - - __init__ expects a pywikibot.Page object. - Execute by running the .run() method. - """ + """A class that encapsulates all archiving methods."""
algo = 'none'
- def __init__(self, page, tpl, salt, force=False): - """Initializer.""" + def __init__(self, page, template, salt, force=False): + """Initializer. + + param page: a page object to be archived + type page: pywikibot.Page + param template: a template with configuration settings + type template: pywikibot.Page + param salt: salt value + type salt: str + param force: override security value + type force: bool + """ self.attributes = { 'algo': ['old(24h)', False], 'archive': ['', False], @@ -539,7 +526,7 @@ self.salt = salt self.force = force self.site = page.site - self.tpl = pywikibot.Page(self.site, tpl) + self.tpl = template self.timestripper = TimeStripper(site=self.site) self.page = DiscussionPage(page, self) self.load_config() @@ -667,7 +654,7 @@ return set(whys)
def run(self): - """Run the bot.""" + """Process a single DiscussionPage object.""" if not self.page.botMayEdit(): return whys = self.analyze_page() @@ -779,15 +766,18 @@ additional_text='No template was specified.') return False
- for a in templates: + for template_name in templates: pagelist = [] - a = pywikibot.Page(site, a, ns=10).title() + tmpl = pywikibot.Page(site, template_name, ns=10) if not filename and not pagename: if namespace is not None: ns = [str(namespace)] else: ns = [] - for pg in generate_transclusions(site, a, ns): + pywikibot.output('Fetching template transclusions...') + for pg in tmpl.getReferences(only_template_inclusion=True, + follow_redirects=False, + namespaces=ns): pagelist.append(pg) if filename: for pg in open(filename, 'r').readlines(): @@ -800,7 +790,7 @@ # Catching exceptions, so that errors in one page do not bail out # the entire process try: - archiver = PageArchiver(pg, a, salt, force) + archiver = PageArchiver(pg, tmpl, salt, force) archiver.run() except ArchiveBotSiteConfigError as e: # no stack trace for errors originated by pages on-site diff --git a/tests/archivebot_tests.py b/tests/archivebot_tests.py index 05b6bdd..4b60636 100644 --- a/tests/archivebot_tests.py +++ b/tests/archivebot_tests.py @@ -257,9 +257,11 @@ == B == foo bar bar bar """ - page = pywikibot.Page(self.get_site(), 'Talk:For-pywikibot-archivebot') + site = self.get_site() + page = pywikibot.Page(site, 'Talk:For-pywikibot-archivebot') + tmpl = pywikibot.Page(site, 'User:MiszaBot/config') archiver = archivebot.PageArchiver( - page=page, tpl='User:MiszaBot/config', salt='', force=False) + page=page, template=tmpl, salt='', force=False) page = archivebot.DiscussionPage(page, archiver) page.load_page() self.assertEqual([x.title for x in page.threads], ['A', 'B'])
pywikibot-commits@lists.wikimedia.org