jenkins-bot submitted this change.

View Change

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

- remove Python 2 code
- simplify imageB.resize parameters
- simplify creating site object for other_family and other_lang
- simplify arg parsing

Change-Id: I19049a56ed47efb75dca979866dbeac98409ab09
---
M scripts/match_images.py
1 file changed, 15 insertions(+), 33 deletions(-)

diff --git a/scripts/match_images.py b/scripts/match_images.py
index 98cb102..5a69099 100755
--- a/scripts/match_images.py
+++ b/scripts/match_images.py
@@ -27,8 +27,6 @@
#
# Distributed under the terms of the MIT license.
#
-from __future__ import absolute_import, division, unicode_literals
-
import io

import pywikibot
@@ -52,9 +50,8 @@
imageA = get_image_from_image_page(imagePageA)
imageB = get_image_from_image_page(imagePageB)

- (imA_width, imA_height) = imageA.size
-
- imageB = imageB.resize((imA_width, imA_height))
+ imageB = imageB.resize(imageA.size)
+ imA_width, imA_height = imageA.size

imageA_topleft = imageA.crop((0, 0, imA_width // 2, imA_height // 2))
imageB_topleft = imageB.crop((0, 0, imA_width // 2, imA_height // 2))
@@ -142,25 +139,21 @@
def main(*args):
"""Extracting file page information and initiate matching."""
images = []
- other_family = ''
- other_lang = ''

# Read commandline parameters.
local_args = pywikibot.handle_args(args)
+ current_site = pywikibot.Site()
+ other_family = current_site.family.name
+ other_lang = current_site.code

for arg in local_args:
- if arg.startswith('-otherfamily:'):
- if len(arg) == len('-otherfamily:'):
- other_family = pywikibot.input(
- 'What family do you want to use?')
- else:
- other_family = arg[len('-otherfamily:'):]
- elif arg.startswith('-otherlang:'):
- if len(arg) == len('-otherlang:'):
- other_lang = pywikibot.input(
- 'What language do you want to use?')
- else:
- other_lang = arg[len('otherlang:'):]
+ option, _, value = arg.partition(':')
+ if option == '-otherfamily':
+ other_family = value or pywikibot.input(
+ 'What family do you want to use?')
+ elif option == '-otherlang':
+ other_lang = value or pywikibot.input(
+ 'What language do you want to use?')
else:
images.append(arg)

@@ -174,20 +167,9 @@
additional_text=additional_text):
return

- imagePageA = pywikibot.page.FilePage(pywikibot.Site(),
- images[0])
- if other_lang:
- if other_family:
- imagePageB = pywikibot.page.FilePage(pywikibot.Site(
- other_lang, other_family),
- images[1])
- else:
- imagePageB = pywikibot.page.FilePage(pywikibot.Site(
- other_lang),
- images[1])
- else:
- imagePageB = pywikibot.page.FilePage(pywikibot.Site(),
- images[1])
+ other_site = pywikibot.Site(other_lang, other_family)
+ imagePageA = pywikibot.page.FilePage(current_site, images[0])
+ imagePageB = pywikibot.page.FilePage(other_site, images[1])

match_image_pages(imagePageA, imagePageB)


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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I19049a56ed47efb75dca979866dbeac98409ab09
Gerrit-Change-Number: 628092
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki@aol.com>
Gerrit-Reviewer: JJMC89 <JJMC89.Wikimedia@gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged