Xqt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/283407

Change subject: [IMPR] Simplify arg parsing
......................................................................

[IMPR] Simplify arg parsing

- Also initialize xmlStart

Change-Id: Ie1b2044ff25b7e46e8e2b2e38cb1fd3df1816534
---
M scripts/reflinks.py
1 file changed, 18 insertions(+), 27 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/07/283407/1

diff --git a/scripts/reflinks.py b/scripts/reflinks.py
index 17c9465..d35d188 100755
--- a/scripts/reflinks.py
+++ b/scripts/reflinks.py
@@ -746,6 +746,7 @@
     @type args: list of unicode
     """
     xmlFilename = None
+    xmlStart = None
     options = {}
     namespaces = []
     generator = None
@@ -755,39 +756,29 @@
     genFactory = pagegenerators.GeneratorFactory()
 
     for arg in local_args:
-        if arg.startswith('-namespace:'):
+        arg, sep, value = arg.partition(':')
+        option = arg[1:]
+        if option == 'namespace':
             try:
-                namespaces.append(int(arg[11:]))
+                namespaces.append(int(value))
             except ValueError:
-                namespaces += arg[11:].split(',')
-        elif arg.startswith('-summary:'):
-            options['summary'] = arg[9:]
-        elif arg == '-always':
-            options['always'] = True
-        elif arg == '-ignorepdf':
-            options['ignorepdf'] = True
-        elif arg.startswith('-limit:'):
-            options['limit'] = int(arg[7:])
-        elif arg.startswith('-xmlstart'):
-            if len(arg) == 9:
-                xmlStart = pywikibot.input(
-                    u'Please enter the dumped article to start with:')
-            else:
-                xmlStart = arg[10:]
-        elif arg.startswith('-xml'):
-            if len(arg) == 4:
-                xmlFilename = pywikibot.input(
-                    u'Please enter the XML dump\'s filename:')
-            else:
-                xmlFilename = arg[5:]
+                namespaces += value.split(',')
+        elif option == 'summary':
+            options[option] = value
+        elif option in ('always', 'ignorepdf'):
+            options[option] = True
+        elif option == 'limit':
+            options[option] = int(value)
+        elif option == 'xmlstart':
+            xmlStart = value or pywikibot.input(
+                'Please enter the dumped article to start with:')
+        elif option == 'xml':
+            xmlFilename = value or pywikibot.input(
+                "Please enter the XML dump's filename:")
         else:
             genFactory.handleArg(arg)
 
     if xmlFilename:
-        try:
-            xmlStart
-        except NameError:
-            xmlStart = None
         generator = XmlDumpPageGenerator(xmlFilename, xmlStart, namespaces)
     if not generator:
         generator = genFactory.getCombinedGenerator()

-- 
To view, visit https://gerrit.wikimedia.org/r/283407
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie1b2044ff25b7e46e8e2b2e38cb1fd3df1816534
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <i...@gno.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to