jenkins-bot has submitted this change and it was merged.
Change subject: image.py/template.py: improved site use and line length formatting. ......................................................................
image.py/template.py: improved site use and line length formatting.
Change-Id: I66f64bf8c1201d663bfba6655c5e16218052c343 --- M scripts/image.py M scripts/template.py 2 files changed, 19 insertions(+), 25 deletions(-)
Approvals: John Vandenberg: Looks good to me, but someone else must approve XZise: Looks good to me, approved Mpaa: Looks good to me, but someone else must approve jenkins-bot: Verified
diff --git a/scripts/image.py b/scripts/image.py index 512e863..16026c3 100755 --- a/scripts/image.py +++ b/scripts/image.py @@ -116,19 +116,15 @@ super(ImageRobot, self).__init__(**kwargs)
self.generator = generator - self.site = pywikibot.Site() self.old_image = old_image self.new_image = new_image
if not self.getOption('summary'): - if self.new_image: - self.options['summary'] = i18n.translate(self.site, self.msg_replace, - fallback=True) \ - % (self.old_image, self.new_image) - else: - self.options['summary'] = i18n.translate(self.site, self.msg_remove, - fallback=True) \ - % self.old_image + self.options['summary'] = i18n.translate( + self.site, self.msg_replace, + (self.old_image, self.new_image) if self.new_image + else self.old_image, + fallback=True)
def run(self): """Start the bot's action.""" @@ -140,7 +136,8 @@
replacements = []
- if self.site.namespaces[6].case == 'first-letter': + namespace = self.site.namespaces[6] + if namespace.case == 'first-letter': case = re.escape(self.old_image[0].upper() + self.old_image[0].lower()) escaped = '[' + case + ']' + re.escape(self.old_image[1:]) @@ -152,7 +149,7 @@ if not self.getOption('loose') or not self.new_image: image_regex = re.compile( r'[[ *(?:%s)\s*:\s*%s *(?P<parameters>|[^\n]+|) *]]' - % ('|'.join(self.site.namespace(6, all=True)), escaped)) + % ('|'.join(namespace), escaped)) else: image_regex = re.compile(r'' + escaped)
diff --git a/scripts/template.py b/scripts/template.py index f145fdc..999b22f 100755 --- a/scripts/template.py +++ b/scripts/template.py @@ -146,7 +146,7 @@ pywikibot.output(u'Skipping %s' % page.title(asLink=True))
-class XmlDumpTemplatePageGenerator: +class XmlDumpTemplatePageGenerator(object):
""" Generator which yields Pages that transclude a template. @@ -248,10 +248,9 @@
replacements = [] exceptions = {} - site = pywikibot.Site() + namespace = self.site.namespaces[10] for old, new in self.templates.items(): - namespaces = list(site.namespace(10, all=True)) - if site.namespaces[10].case == 'first-letter': + if namespace.case == 'first-letter': pattern = '[' + \ re.escape(old[0].upper()) + \ re.escape(old[0].lower()) + \ @@ -259,7 +258,7 @@ else: pattern = re.escape(old) pattern = re.sub(r'_|\ ', r'[_ ]', pattern) - templateRegex = re.compile(r'{{ *(' + ':|'.join(namespaces) + + templateRegex = re.compile(r'{{ *(' + ':|'.join(namespace) + r':|[mM][sS][gG]:)?' + pattern + r'(?P<parameters>\s*|.+?|) *}}', re.DOTALL) @@ -275,7 +274,7 @@ elif self.getOption('remove'): replacements.append((templateRegex, '')) else: - template = pywikibot.Page(site, new, ns=10) + template = pywikibot.Page(self.site, new, ns=10) if not template.exists(): pywikibot.warning(u'Template "%s" does not exist.' % new) if not pywikibot.input_yn('Do you want to proceed anyway?', @@ -311,6 +310,7 @@
# read command line parameters local_args = pywikibot.handle_args(args) + site = pywikibot.Site() genFactory = pagegenerators.GeneratorFactory() for arg in local_args: if arg == '-remove': @@ -340,10 +340,8 @@ timestamp = arg[len('-timestamp:'):] else: if not genFactory.handleArg(arg): - templateNames.append( - pywikibot.Page(pywikibot.Site(), arg, - ns=10 - ).title(withNamespace=False)) + templateName = pywikibot.Page(site, arg, ns=10) + templateNames.append(templateName.title(withNamespace=False))
if not templateNames: pywikibot.showHelp() @@ -357,14 +355,13 @@ for i in range(0, len(templateNames), 2): templates[templateNames[i]] = templateNames[i + 1] except IndexError: - pywikibot.output( -u'Unless using solely -subst or -remove, you must give an even number of template names.') + pywikibot.output('Unless using solely -subst or -remove, ' + 'you must give an even number of template names.') return
oldTemplates = [] for templateName in templates.keys(): - oldTemplate = pywikibot.Page(pywikibot.Site(), templateName, - ns=10) + oldTemplate = pywikibot.Page(site, templateName, ns=10) oldTemplates.append(oldTemplate)
if xmlfilename: