jenkins-bot merged this change.

View Change

Approvals: Dvorapa: Looks good to me, approved jenkins-bot: Verified
[bugfix] Namespace identifier can be ommitted for -start option

- in contrary to the documentation a Namespace identifier like 'File:'
or 'Image:' must be given with the -start command argument.
This patch solves this issue.
- handle global args first. This ensures the right site is used with
-start, -cat and -ref options
- check whether an namespace identifier is given with -start option and
remove it
- use allimages instead of allpages because images are used with this
script only
- print a warning if an unknown option is given and leave the scripts then
- finally return True in main() due to PEP8

Bug: T217824
Change-Id: I83a594947d8b205ca20b978b4c16e1cbb788b4a1
---
M scripts/checkimages.py
1 file changed, 30 insertions(+), 18 deletions(-)

diff --git a/scripts/checkimages.py b/scripts/checkimages.py
index 08a4b55..54c1545 100755
--- a/scripts/checkimages.py
+++ b/scripts/checkimages.py
@@ -38,7 +38,7 @@

-skip[:#] The bot skip the first [:#] images (default: 0)

--start[:#] Use allpages() as generator
+-start[:#] Use allimages() as generator
(it starts already from File:[:#])

-cat[:#] Use a category as generator
@@ -93,11 +93,12 @@

import pywikibot

-from pywikibot import i18n
-from pywikibot import pagegenerators as pg
-
+from pywikibot.bot import suggest_help
from pywikibot.exceptions import ArgumentDeprecationWarning, NotEmailableError
from pywikibot.family import Family
+from pywikibot import i18n
+from pywikibot import pagegenerators as pg
+from pywikibot.site import Namespace
from pywikibot.tools import issue_deprecation_warning

###############################################################################
@@ -1528,9 +1529,12 @@
sendemailActive = False # Use the send-email
logFullError = True # Raise an error when the log is full
generator = None
+ unknown = [] # unknown parameters

- # Here below there are the parameters.
- for arg in pywikibot.handle_args(args):
+ local_args = pywikibot.handle_args(args)
+ site = pywikibot.Site()
+ # Here below there are the local parameters.
+ for arg in local_args:
if arg.startswith('-limit'):
if len(arg) == 6:
limit = int(pywikibot.input(
@@ -1597,9 +1601,11 @@
'From which page do you want to start?')
elif len(arg) > 6:
firstPageTitle = arg[7:]
- firstPageTitle = firstPageTitle.split(':')[1:]
- generator = pywikibot.Site().allpages(start=firstPageTitle,
- namespace=6)
+ namespaces = tuple(ns + ':'
+ for ns in site.namespace(Namespace.FILE, all))
+ if firstPageTitle.startswith(namespaces):
+ firstPageTitle = firstPageTitle.split(':')[1]
+ generator = site.allimages(start=firstPageTitle)
repeat = False
elif arg.startswith('-page'):
if len(arg) == 5:
@@ -1631,7 +1637,7 @@
catName = str(pywikibot.input('In which category do I work?'))
elif len(arg) > 4:
catName = str(arg[5:])
- catSelected = pywikibot.Category(pywikibot.Site(),
+ catSelected = pywikibot.Category(site,
'Category:{}'.format(catName))
generator = catSelected.articles(namespaces=[6])
repeat = False
@@ -1641,23 +1647,28 @@
'The references of what page should I parse?'))
elif len(arg) > 4:
refName = str(arg[5:])
- ref = pywikibot.Page(pywikibot.Site(), refName)
+ ref = pywikibot.Page(site, refName)
generator = ref.getReferences(namespaces=[6])
repeat = False
+ else:
+ unknown.append(arg)

if not generator:
normal = True

- site = pywikibot.Site()
skip = skip_number > 0

- # A little block-statement to ensure that the bot will not start with
- # en-parameters
+ # Ensure that the bot is localized and right command args are given
if site.code not in project_inserted:
- pywikibot.output('Your project is not supported by this script.\n'
- 'To allow your project in the script you have to '
- 'add a localization into the script and add your '
- 'project to the "project_inserted" list!')
+ additional_text = ('Your project is not supported by this script.\n'
+ 'To allow your project in the script you have to '
+ 'add a localization into the script and add your '
+ 'project to the "project_inserted" list!')
+ else:
+ additional_text = ''
+ if unknown or additional_text:
+ suggest_help(unknown_parameters=unknown,
+ additional_text=additional_text)
return False

# Reading the log of the new images if another generator is not given.
@@ -1716,6 +1727,7 @@
pywikibot.sleep(time_sleep)
else:
break
+ return True


if __name__ == '__main__':

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I83a594947d8b205ca20b978b4c16e1cbb788b4a1
Gerrit-Change-Number: 494898
Gerrit-PatchSet: 7
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki@aol.com>
Gerrit-Reviewer: Dalba <dalba.wiki@gmail.com>
Gerrit-Reviewer: Dvorapa <dvorapa@seznam.cz>
Gerrit-Reviewer: Framawiki <framawiki@tools.wmflabs.org>
Gerrit-Reviewer: John Vandenberg <jayvdb@gmail.com>
Gerrit-Reviewer: Lokal Profil <andre.costa@wikimedia.se>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444@gmail.com>
Gerrit-Reviewer: jenkins-bot (75)