jenkins-bot has submitted this change and it was merged.
Change subject: editarticle: move from optparse to argparse
......................................................................
editarticle: move from optparse to argparse
Changes editarticle.py to use argparse, as optparse was deprecated in
python 2.7/3.2.
Behaviour is identical to optparse except for a nicer help message.
Updated script_tests to account for the argparse requirement in python
2.7.
Bug: T70617
Change-Id: I0614674840c96205fe7c8ff48e3bea1273a886cb
---
M scripts/editarticle.py
M tests/script_tests.py
2 files changed, 30 insertions(+), 15 deletions(-)
Approvals:
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/editarticle.py b/scripts/editarticle.py
index 0ee678c..97656d9 100755
--- a/scripts/editarticle.py
+++ b/scripts/editarticle.py
@@ -8,6 +8,18 @@
- minor edits
- watch/unwatch
- ...
+
+The following parameters are supported:
+
+-r Edit redirect pages without following them
+--edit_redirect automatically.
+--edit-redirect
+
+-p P Choose which page to edit.
+--page P This argument can be passed positionally.
+
+-w Add the page to the user's watchlist after editing.
+--watch
"""
#
# (C) Gerrit Holl, 2004
@@ -19,7 +31,8 @@
#
import os
-import optparse
+import sys
+import argparse
import tempfile
import pywikibot
@@ -42,21 +55,22 @@
def set_options(self, *args):
"""Parse commandline and set options attribute."""
- my_args = []
- for arg in pywikibot.handle_args(args):
- my_args.append(arg)
- parser = optparse.OptionParser()
- parser.add_option("-r", "--edit_redirect", action="store_true",
- default=False, help="Ignore/edit redirects")
- parser.add_option("-p", "--page", help="Page to edit")
- parser.add_option("-w", "--watch", action="store_true", default=False,
- help="Watch article after edit")
- (self.options, args) = parser.parse_args(args=my_args)
+ my_args = pywikibot.handle_args(args)
- # for convenience, if we have an arg, stuff it into the opt, so we
- # can act like a normal editor.
- if (len(args) == 1):
- self.options.page = args[0]
+ parser = argparse.ArgumentParser(add_help=False)
+ parser.add_argument("-r", "--edit_redirect", "--edit-redirect",
+ action="store_true", help="Ignore/edit redirects")
+ parser.add_argument("-p", "--page", help="Page to edit")
+ parser.add_argument("-w", "--watch", action="store_true",
+ help="Watch article after edit")
+ # convenience positional argument so we can act like a normal editor
+ parser.add_argument("wikipage", nargs="?", help="Page to edit")
+ self.options = parser.parse_args(my_args)
+
+ if self.options.page and self.options.wikipage:
+ pywikibot.error(u"Multiple pages passed. Please specify a single
page to edit.")
+ sys.exit(1)
+ self.options.page = self.options.page or self.options.wikipage
def setpage(self):
"""Set page and page title."""
diff --git a/tests/script_tests.py b/tests/script_tests.py
index 8536715..a276593 100644
--- a/tests/script_tests.py
+++ b/tests/script_tests.py
@@ -34,6 +34,7 @@
}
if sys.version_info < (2, 7):
script_deps['replicate_wiki'] = ['argparse']
+ script_deps['editarticle'] = ['argparse']
def check_script_deps(script_name):
--
To view, visit https://gerrit.wikimedia.org/r/176747
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I0614674840c96205fe7c8ff48e3bea1273a886cb
Gerrit-PatchSet: 9
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Mloc-gci <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: Mloc-gci <[email protected]>
Gerrit-Reviewer: XZise <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits