jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/639965 )

Change subject: [IMPR] Add -site option as -family -lang shortcut
......................................................................

[IMPR] Add -site option as -family -lang shortcut

- Specifying a site needs -family and -lang option except one of them
  is already set as default in user-config.py. The new -site option
  is able to set config.family and config.mylang together; it is called
  -site:wikipedia:test
- use the new opion in replacebot_tests.py
- update docs in several scripts

Change-Id: I74654ff4ca463d399795d4da2c1fc828e9e3fda5
---
M generate_user_files.py
M pywikibot/bot.py
M pywikibot/page/__init__.py
M scripts/coordinate_import.py
M scripts/login.py
M tests/README.rst
M tests/replacebot_tests.py
7 files changed, 26 insertions(+), 18 deletions(-)

Approvals:
  Hazard-SJ: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/generate_user_files.py b/generate_user_files.py
index b2b7e51..3940991 100755
--- a/generate_user_files.py
+++ b/generate_user_files.py
@@ -440,9 +440,9 @@
     """
     # set the config family and mylang values to an invalid state so that
     # the script can detect that the command line arguments -family & -lang
-    # were used and and handle_args has updated these config values,
+    # or -site were used and handle_args has updated these config values,
     # and 'force' mode can be activated below.
-    (config.family, config.mylang) = ('wikipedia', None)
+    config.family, config.mylang = 'wikipedia', None

     local_args = pywikibot.handle_args(args)
     if local_args:
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index dc5599d..b2be383 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -131,9 +131,11 @@
 from pywikibot.tools.formatter import color_format

 if PYTHON_VERSION >= (3, 9):
+    from collections.abc import Iterable
     Dict = dict
+    List = list
 else:
-    from typing import Dict
+    from typing import Dict, Iterable, List

 # Note: all output goes through python std library "logging" module
 _logger = 'bot'
@@ -156,10 +158,14 @@

 -lang:xx          Set the language of the wiki you want to work on, overriding
                   the configuration in user-config.py. xx should be the
-                  language code.
+                  site code.

 -family:xyz       Set the family of the wiki you want to work on, e.g.
-                  wikipedia, wiktionary, wikitravel, ...
+                  wikipedia, wiktionary, wikivoyage, ...
+                  This will override the configuration in user-config.py.
+
+-site:xyz:xx      Set the wiki site you want to work on, e.g.
+                  wikipedia:test, wiktionary:de, wikivoyage:en, ...
                   This will override the configuration in user-config.py.

 -user:xyz         Log in as user 'xyz' instead of the default username.
@@ -724,7 +730,8 @@
     return Path(pywikibot.argvu[0]).stem


-def handle_args(args=None, do_help=True):
+def handle_args(args: Optional[Iterable[str]] = None,
+                do_help: bool = True) -> List[str]:
     """
     Handle standard command line arguments, and return the rest as a list.

@@ -738,11 +745,8 @@
     args may be passed as an argument, thereby overriding sys.argv

     @param args: Command line arguments
-    @type args: typing.Iterable
     @param do_help: Handle parameter '-help' to show help and invoke sys.exit
-    @type do_help: bool
     @return: list of arguments not recognised globally
-    @rtype: list of str
     """
     if pywikibot._sites:
         warn('Site objects have been created before arguments were handled',
@@ -767,6 +771,8 @@
             do_help = value or True
         elif option == '-dir':
             pass
+        elif option == '-site':
+            config.family, config.mylang = value.split(':')
         elif option == '-family':
             config.family = value
         elif option == '-lang':
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py
index 23ae11c..5ffb5a4 100644
--- a/pywikibot/page/__init__.py
+++ b/pywikibot/page/__init__.py
@@ -321,8 +321,9 @@
         @param as_filename: (not used with as_link) if true, replace any
             characters that are unsafe in filenames
         @param insite: (only used if as_link is true) a site object where the
-            title is to be shown. default is the current family/lang given by
-            -family and -lang option i.e. config.family and config.mylang
+            title is to be shown. Default is the current family/lang given by
+            -family and -lang or -site option i.e. config.family and
+            config.mylang
         @param without_brackets: (cannot be used with as_link) if true, remove
             the last pair of brackets(usually removes disambiguation brackets).
         """
diff --git a/scripts/coordinate_import.py b/scripts/coordinate_import.py
index 915c963..cccd77c 100755
--- a/scripts/coordinate_import.py
+++ b/scripts/coordinate_import.py
@@ -5,7 +5,7 @@

 Usage:

-    python pwb.py coordinate_import -lang:en -family:wikipedia \
+    python pwb.py coordinate_import -site:wikipedia:en \
         -cat:Category:Coordinates_not_on_Wikidata

 This will work on all pages in the category "coordinates not on Wikidata" and
@@ -23,10 +23,10 @@

 You can also run over a set of items on the repo without coordinates and
 try to import them from any connected page. To do this, you have to
-explicitly provide the repo as the site using -lang and -family arguments.
+explicitly provide the repo as the site using -site argument.
 Example:

-    python pwb.py coordinate_import -lang:wikidata -family:wikidata \
+    python pwb.py coordinate_import -site:wikidata:wikidata \
         -namespace:0 -querypage:Deadendpages


diff --git a/scripts/login.py b/scripts/login.py
index 21f3995..b67b09b 100755
--- a/scripts/login.py
+++ b/scripts/login.py
@@ -13,6 +13,8 @@
                 Example: -family:wiktionary -lang:fr will log you in at
                 fr.wiktionary.org.

+   -site:FF:LL  Log in to the LL language of the FF family
+
    -all         Try to log in on all sites where a username is defined in
                 user-config.py.

diff --git a/tests/README.rst b/tests/README.rst
index 7f84377..c824192 100644
--- a/tests/README.rst
+++ b/tests/README.rst
@@ -67,7 +67,7 @@
 --------------

 Individual test components can be run using unittest, nosetests, or pwb.
-With -lang and -family options pwb can be used to specify a site.
+With -lang and -family or -site options pwb can be used to specify a site.


 unittest
diff --git a/tests/replacebot_tests.py b/tests/replacebot_tests.py
index 126fe4f..d24e0b3 100644
--- a/tests/replacebot_tests.py
+++ b/tests/replacebot_tests.py
@@ -92,9 +92,8 @@
     def _run(self, *args):
         """Run the L{replace.main} with the given args and summary and page."""
         # -page to not have an empty generator
-        # -lang and -family as it will use Site() otherwise
-        return replace.main(*(args + ('-lang:test', '-family:wikipedia',
-                                      '-page:TEST')))
+        # -site as it will use Site() otherwise
+        return replace.main(*(args + ('-site:wikipedia:test', '-page:TEST')))

     def test_invalid_replacements(self):
         """Test invalid command line replacement configurations."""

--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/639965
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I74654ff4ca463d399795d4da2c1fc828e9e3fda5
Gerrit-Change-Number: 639965
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: D3r1ck01 <[email protected]>
Gerrit-Reviewer: Hazard-SJ <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: Mpaa <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to