Murfel has uploaded a new change for review.

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

Change subject: T70664 Added global options support
......................................................................

T70664 Added global options support

Change-Id: I41bc6b8175f34867cfe50c6b890892045c32b4c4
---
M scripts/replicate_wiki.py
1 file changed, 60 insertions(+), 21 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/16/177216/1

diff --git a/scripts/replicate_wiki.py b/scripts/replicate_wiki.py
index f417541..84bd133 100644
--- a/scripts/replicate_wiki.py
+++ b/scripts/replicate_wiki.py
@@ -19,6 +19,25 @@
 
 to replace all occurences of 'Hoofdpagina' with 'Veurblaad' when writing to
 liwiki. Note that this does not take the origin wiki into account.
+
+The following parameters are supported:
+
+-f                wiki family
+--family
+
+-r                actually replace pages (without this option
+--replace         you will only get an overview page)
+
+-o                original wiki
+--original
+
+destination_wiki  destination wiki(s)
+
+-ns               specify namespace
+--namespace
+
+-dns              destination namespace (if different)
+--dest-namespace
 """
 #
 # (C) Kasper Souren, 2012-2013
@@ -30,6 +49,7 @@
 #
 
 import sys
+import argparse
 
 import pywikibot
 from pywikibot import config, Page
@@ -53,8 +73,8 @@
 
     """Work is done in here."""
 
-    def __init__(self, options):
-        self.options = options
+    def __init__(self, *args):
+        self.set_options(*args)
 
         if options.original_wiki:
             original_wiki = options.original_wiki
@@ -87,6 +107,31 @@
             self.user_diff[s] = []
             pywikibot.output(str(s), newline=False)
         pywikibot.output('')
+
+    def set_options(self, *args):
+        """Parse commandline and set options attribute."""
+        my_args = pywikibot.handle_args(args)
+
+        parser = argparse.ArgumentParser(add_help=False)
+        parser.add_argument("-f", "--family", dest="family",
+                            help="wiki family")
+
+        parser.add_argument("-r", "--replace", action="store_true",
+                            help="actually replace pages (without this option 
you will only get an overview page)")
+        parser.add_argument("-o", "--original", dest="original_wiki",
+                            help="original wiki")
+        parser.add_argument('destination_wiki', metavar='destination', 
type=str, nargs='+',
+                            help='destination wiki(s)')
+        parser.add_argument("-ns", "--namespace", dest="namespace",
+                            help="specify namespace")
+        parser.add_argument("-dns", "--dest-namespace", dest="dest_namespace",
+                            help="destination namespace (if different)")
+        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 check_sysops(self):
         """Check if sysops are the same on all wikis."""
@@ -211,29 +256,23 @@
             sys.stdout.write('.')
             sys.stdout.flush()
 
+def main(*args):
+    """
+    Process command line arguments and invoke bot.
 
-if __name__ == '__main__':
-    from argparse import ArgumentParser
+    If args is an empty list, sys.argv is used.
 
-    parser = ArgumentParser()
-    parser.add_argument("-f", "--family", dest="family",
-                        help="wiki family")
-
-    parser.add_argument("-r", "--replace", action="store_true",
-                        help="actually replace pages (without this option you 
will only get an overview page)")
-    parser.add_argument("-o", "--original", dest="original_wiki",
-                        help="original wiki")
-    parser.add_argument('destination_wiki', metavar='destination', type=str, 
nargs='+',
-                        help='destination wiki(s)')
-    parser.add_argument("-ns", "--namespace", dest="namespace",
-                        help="specify namespace")
-    parser.add_argument("-dns", "--dest-namespace", dest="dest_namespace",
-                        help="destination namespace (if different)")
-
-    (options, args) = parser.parse_known_args()
+    @param args: command line arguments
+    @type args: list of unicode
+    """  
+    app = SyncSites(*args)
+    app.run()
 
     # sync is global for convenient IPython debugging
     sync = SyncSites(options)
     sync.check_sysops()
     sync.check_namespaces()
-    sync.generate_overviews()
+    sync.generate_overviews() 
+
+if __name__ == "__main__":
+    main()

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I41bc6b8175f34867cfe50c6b890892045c32b4c4
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Murfel <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to