Xqt has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/349903 )
Change subject: Use global option -code instead of -lang ...................................................................... Use global option -code instead of -lang Also change option -tolang to -tocode in transferbot.py site.code is the identifying code of a site presumed to be equal to the wiki prefix whereas site language is the ISO language code for a site. e.g. 'als' is a site code whereas its site language is 'gsw' 'meta' is a site code whereas its language is 'en' The global option should follow this difference. Change-Id: I145c0dc283ff597a697752aec901c1a14e6b1416 --- M ChangeLog M generate_user_files.py M pywikibot/bot.py M pywikibot/page.py M pywikibot/site.py M scripts/coordinate_import.py M scripts/create_categories.py M scripts/harvest_template.py M scripts/login.py M scripts/replicate_wiki.py M scripts/table2wiki.py M scripts/transferbot.py M tests/replacebot_tests.py M tox.ini 14 files changed, 56 insertions(+), 45 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core refs/changes/03/349903/1 diff --git a/ChangeLog b/ChangeLog index 00fa7f1..3f0ff28 100644 --- a/ChangeLog +++ b/ChangeLog @@ -146,7 +146,7 @@ - added ISBN support - added redirect support - Optionally uses external library for improved isbn validation -- Automatically generating user files when -user, -family and -lang are +- Automatically generating user files when -user, -family and -code are provided to a script - Page.content_model added - Page.contributors() and Page.revision_count() added diff --git a/generate_user_files.py b/generate_user_files.py index 74837a1..ccffcd4 100755 --- a/generate_user_files.py +++ b/generate_user_files.py @@ -314,7 +314,7 @@ global base_dir # set the config family and mylang values to an invalid state so that - # the script can detect that the command line arguments -family & -lang + # the script can detect that the command line arguments -family & -code # were used and and handle_args has updated these config values, # and 'force' mode can be activated below. (config.family, config.mylang) = ('wikipedia', None) diff --git a/pywikibot/bot.py b/pywikibot/bot.py index eea0052..9e5aa0c 100644 --- a/pywikibot/bot.py +++ b/pywikibot/bot.py @@ -90,6 +90,7 @@ ListOption, OutputProxyOption, HighlightContextOption, ChoiceException, QuitKeyboardInterrupt, ) +from pywikibot.exceptions import ArgumentDeprecationWarning from pywikibot.logging import ( CRITICAL, ERROR, INFO, WARNING, ) @@ -100,7 +101,8 @@ ) from pywikibot.logging import critical from pywikibot.tools import ( - deprecated, deprecate_arg, deprecated_args, PY2, PYTHON_VERSION, + deprecated, deprecate_arg, deprecated_args, issue_deprecation_warning, + PY2, PYTHON_VERSION, ) from pywikibot.tools._logging import ( LoggingFormatter as _LoggingFormatter, @@ -832,7 +834,7 @@ Handle standard command line arguments, and return the rest as a list. Takes the command line arguments as Unicode strings, processes all - global parameters such as -lang or -log, initialises the logging layer, + global parameters such as -code or -log, initialises the logging layer, which emits startup information into log at level 'verbose'. This makes sure that global arguments are applied first, @@ -873,7 +875,10 @@ pass elif option == '-family': config.family = value - elif option == '-lang': + elif option in ('-lang', '-code'): + if option == '-lang': + issue_deprecation_warning( + option, '-code', 1, ArgumentDeprecationWarning) config.mylang = value elif option == '-user': username = value @@ -996,9 +1001,9 @@ -dir:PATH Read the bot's configuration data from directory given by PATH, instead of from the default directory. --lang:xx Set the language of the wiki you want to work on, overriding +-code:xx Set the code 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, ... diff --git a/pywikibot/page.py b/pywikibot/page.py index 3794ee0..deb60c1 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -324,7 +324,7 @@ characters that are unsafe in filenames @param insite: (only used if asLink 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 + -family and -code option i.e. config.family and config.mylang @rtype: unicode """ title = self._link.canonical_title() diff --git a/pywikibot/site.py b/pywikibot/site.py index a16bdea..494b866 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -811,7 +811,7 @@ @property def code(self): """ - The identifying code for this Site. + The identifying code for this Site equal to the wiki prefix. By convention, this is usually an ISO language code, but it does not have to be. @@ -822,7 +822,7 @@ def lang(self): """The ISO language code for this Site. - Presumed to be equal to the wiki prefix, but this can be overridden. + Presumed to be equal to the site code, but this can be overridden. """ return self.__code diff --git a/scripts/coordinate_import.py b/scripts/coordinate_import.py index 7ed163d..9d44824 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 -code:en -family:wikipedia \ -cat:Category:Coordinates_not_on_Wikidata This will work on all pages in the category "coordinates not on Wikidata" and @@ -18,14 +18,14 @@ You can use any typical pagegenerator to provide with a list of pages: - python pwb.py coordinate_import -lang:it -family:wikipedia \ + python pwb.py coordinate_import -code:it -family:wikipedia \ -namespace:0 -transcludes:Infobox_stazione_ferroviaria ¶ms; """ # # (C) Multichill, 2014 -# (C) Pywikibot team, 2013-2016 +# (C) Pywikibot team, 2013-2017 # # Distributed under the terms of MIT License. # diff --git a/scripts/create_categories.py b/scripts/create_categories.py index 0696d9e..426c1a5 100755 --- a/scripts/create_categories.py +++ b/scripts/create_categories.py @@ -19,7 +19,7 @@ Example: python pwb.py create_categories \ - -lang:commons \ + -code:commons \ -family:commons \ -links:User:Multichill/Wallonia \ -parent:"Cultural heritage monuments in Wallonia" \ @@ -35,8 +35,8 @@ __version__ = '$Id$' # # (C) Multichill, 2011 -# (C) xqt, 2011-2016 -# (c) Pywikibot team, 2016 +# (C) xqt, 2011-2017 +# (c) Pywikibot team, 2017 # # Distributed under the terms of the MIT license. # diff --git a/scripts/harvest_template.py b/scripts/harvest_template.py index 309705e..ffd6230 100755 --- a/scripts/harvest_template.py +++ b/scripts/harvest_template.py @@ -19,7 +19,7 @@ Examples: - python pwb.py harvest_template -lang:nl -cat:Sisoridae -namespace:0 \ + python pwb.py harvest_template -code:nl -cat:Sisoridae -namespace:0 \ -template:"Taxobox straalvinnige" orde P70 familie P71 geslacht P74 """ diff --git a/scripts/login.py b/scripts/login.py index 67efa1b..7f0c0ce 100755 --- a/scripts/login.py +++ b/scripts/login.py @@ -9,15 +9,15 @@ Parameters: -family:FF - -lang:LL Log in to the LL language of the FF family. - Example: -family:wiktionary -lang:fr will log you in at + -code:LL Log in to the LL site code of the FF family. + Example: -family:wiktionary -code:fr will log you in at fr.wiktionary.org. -all Try to log in on all sites where a username is defined in user-config.py. -logout Log out of the curren site. Combine with -all to log out of - all sites, or with -family and -lang to log out of a specific + all sites, or with -family and -code to log out of a specific site. -force Ignores if the user is already logged in, and tries to log in. @@ -53,7 +53,7 @@ """ # # (C) Rob W.W. Hooft, 2003 -# (C) Pywikibot team, 2003-2014 +# (C) Pywikibot team, 2003-2017 # # Distributed under the terms of the MIT license. # diff --git a/scripts/replicate_wiki.py b/scripts/replicate_wiki.py index 85b808c..4da855d 100755 --- a/scripts/replicate_wiki.py +++ b/scripts/replicate_wiki.py @@ -9,7 +9,7 @@ or - python pwb.py replicate_wiki [-r] -ns 10 -family:wikipedia -lang:nl li fy + python pwb.py replicate_wiki [-r] -ns 10 -family:wikipedia -code:nl li fy to copy all templates from an nlwiki to liwiki and fywiki. It will show which pages have to be changed if -r is not present, and will only actually write @@ -30,7 +30,7 @@ --replace you will only get an overview page) -o original wiki ---original (you may use -lang:<code> option instead) +--original (you may use -code:<code> option instead) destination_wiki destination wiki(s) @@ -42,7 +42,7 @@ """ # # (C) Kasper Souren, 2012-2013 -# (C) Pywikibot team, 2013-2016 +# (C) Pywikibot team, 2013-2017 # # Distributed under the terms of the MIT license. # diff --git a/scripts/table2wiki.py b/scripts/table2wiki.py index 87aa6dc..30159e2 100644 --- a/scripts/table2wiki.py +++ b/scripts/table2wiki.py @@ -36,7 +36,7 @@ Example: - pwb.py table2wiki -xml:20050713_pages_current.xml -lang:de + pwb.py table2wiki -xml:20050713_pages_current.xml -code:de FEATURES Save against missing </td> @@ -48,7 +48,7 @@ """ # # (C) 2003 Thomas R. Koll, <tom...@tomk32.de> -# (C) Pywikibot team, 2003-2013 +# (C) Pywikibot team, 2003-2017 # # Distributed under the terms of the MIT license. # diff --git a/scripts/transferbot.py b/scripts/transferbot.py index e6ece36..5c06491 100755 --- a/scripts/transferbot.py +++ b/scripts/transferbot.py @@ -5,7 +5,7 @@ It also copies edit history to a subpage. --tolang: The target site code. +-tocode: The target site code. -tosite: The target site family. @@ -25,18 +25,18 @@ Transfer all pages in category "Query service" from the English Wikipedia to the Arabic Wiktionary, adding "Wiktionary:Import enwp/" as prefix: - python pwb.py transferbot -family:wikipedia -lang:en -cat:"Query service" \ - -tofamily:wiktionary -tolang:ar -prefix:"Wiktionary:Import enwp/" + python pwb.py transferbot -family:wikipedia -code:en -cat:"Query service" \ + -tofamily:wiktionary -tocode:ar -prefix:"Wiktionary:Import enwp/" Copy the template "Query service" from the Toolserver wiki to wikitech: - python pwb.py transferbot -family:wikipedia -lang:en \ - -tofamily:wiktionary -tolang:ar -page:"Template:Query service" + python pwb.py transferbot -family:wikipedia -code:en \ + -tofamily:wiktionary -tocode:ar -page:"Template:Query service" """ # # (C) Merlijn van Deen, 2014 -# (C) Pywikibot team, 2015 +# (C) Pywikibot team, 2017 # # Distributed under the terms of the MIT license. # @@ -47,6 +47,8 @@ import pywikibot from pywikibot import pagegenerators +from pywikibot.exceptions import ArgumentDeprecationWarning +from pywikibot.tools import issue_deprecation_warning docuReplacements = { '¶ms;': pagegenerators.parameterHelp, @@ -103,16 +105,20 @@ genFactory = pagegenerators.GeneratorFactory() for arg in local_args: + option, sep, value = arg.partition(':') if genFactory.handleArg(arg): gen_args.append(arg) continue - if arg.startswith('-tofamily'): - tofamily = arg[len('-tofamily:'):] - elif arg.startswith('-tolang'): - tolang = arg[len('-tolang:'):] - elif arg.startswith('-prefix'): - prefix = arg[len('-prefix:'):] - elif arg == "-overwrite": + if option == '-tofamily': + tofamily = value + elif option in ('-tolang', '-tocode'): + if option == '-tolang': + issue_deprecation_warning( + option, '-tocode', 1, ArgumentDeprecationWarning) + tolang = value + elif option == '-prefix': + prefix = value + elif option == '-overwrite': overwrite = True tosite = pywikibot.Site(tolang, tofamily) diff --git a/tests/replacebot_tests.py b/tests/replacebot_tests.py index 938574d..47b76e6 100644 --- a/tests/replacebot_tests.py +++ b/tests/replacebot_tests.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Tests for the replace script and ReplaceRobot class.""" # -# (C) Pywikibot team, 2015 +# (C) Pywikibot team, 2015-2017 # # Distributed under the terms of the MIT license. # @@ -89,8 +89,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:test', + # -code and -family as it will use Site() otherwise + return replace.main(*(args + ('-code:test', '-family:test', '-page:TEST'))) def test_invalid_replacements(self): diff --git a/tox.ini b/tox.ini index d702afe..e6c194e 100644 --- a/tox.ini +++ b/tox.ini @@ -68,7 +68,7 @@ [testenv:nose] commands = - python -W error::UserWarning -m generate_user_files -family:test -lang:test -v + python -W error::UserWarning -m generate_user_files -family:test -code:test -v nosetests --version nosetests --with-detecthttp -v -a '!net' tests deps = @@ -80,7 +80,7 @@ [testenv:nose34] basepython = python3 commands = - python -W error::UserWarning -m generate_user_files -family:test -lang:test -v + python -W error::UserWarning -m generate_user_files -family:test -code:test -v nosetests --version nosetests --with-detecthttp -v -a '!net' tests deps = @@ -93,7 +93,7 @@ [testenv:doctest] commands = - python -W error::UserWarning -m generate_user_files -family:test -lang:test -v + python -W error::UserWarning -m generate_user_files -family:test -code:test -v nosetests --version nosetests --with-doctest pywikibot {[params]doctest_skip} basepython = -- To view, visit https://gerrit.wikimedia.org/r/349903 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I145c0dc283ff597a697752aec901c1a14e6b1416 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