jenkins-bot has submitted this change and it was merged.
Change subject: harvest_template.py: template error handling ......................................................................
harvest_template.py: template error handling
- do not process pages if the template doesnt exist - catch and warn when extract_templates_and_params cant detect template name correctly - do not process page template invocation when field or value is empty
Change-Id: Id83cbe01e553655f3aedbb989dd675bcae2a7327 --- M scripts/harvest_template.py 1 file changed, 14 insertions(+), 3 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/harvest_template.py b/scripts/harvest_template.py index 0d4979f..c494355 100755 --- a/scripts/harvest_template.py +++ b/scripts/harvest_template.py @@ -64,8 +64,12 @@ """ Fetches redirects of the title, so we can check against them """ - pywikibot.output('Finding redirects...') # Put some output here since it can take a while temp = pywikibot.Page(pywikibot.Site(), title, ns=10) + if not temp.exists(): + pywikibot.error(u'Template %s does not exist.' % temp.title()) + exit() + + pywikibot.output('Finding redirects...') # Put some output here since it can take a while if temp.isRedirectPage(): temp = temp.getRedirectTarget() titles = [page.title(withNamespace=False) @@ -88,13 +92,20 @@ templates = pywikibot.extract_templates_and_params(pagetext) for (template, fielddict) in templates: # Clean up template - template = pywikibot.Page(page.site, template, - ns=10).title(withNamespace=False) + try: + template = pywikibot.Page(page.site, template, + ns=10).title(withNamespace=False) + except pywikibot.exceptions.InvalidTitle as e: + pywikibot.error(u"Failed parsing template; '%s' should be the template name." % template) + continue # We found the template we were looking for if template in self.templateTitles: for field, value in fielddict.items(): field = field.strip() value = value.strip() + if not field or not value: + continue + # This field contains something useful for us if field in self.fields: # Check if the property isn't already set
pywikibot-commits@lists.wikimedia.org