jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/642653 )
Change subject: [IMPR] remove code duplication in page.__init__.py
......................................................................
[IMPR] remove code duplication in page.__init__.py
Introduce a common BaseDataDict as parent for:
- LanguageDict
- AliasesDict
Change-Id: Ie4f01d57f9274d5f68a1224303f87bb79906a885
---
M pywikibot/page/__init__.py
1 file changed, 20 insertions(+), 42 deletions(-)
Approvals:
Matěj Suchánek: Looks good to me, but someone else must approve
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py
index 9979bdc..63cb14a 100644
--- a/pywikibot/page/__init__.py
+++ b/pywikibot/page/__init__.py
@@ -3356,13 +3356,13 @@
return self.isRegistered() and 'bot' not in self.groups()
-class LanguageDict(MutableMapping):
+class BaseDataDict(MutableMapping):
"""
- A structure holding language data for a Wikibase entity.
+ Base structure holding data for a Wikibase entity.
- Language data are mappings from a language to a string. It can be
- labels, descriptions and others.
+ Data are mappings from a language to a value. It will be
+ specialised in subclasses.
"""
def __init__(self, data=None):
@@ -3372,11 +3372,6 @@
self.update(data)
@classmethod
- def fromJSON(cls, data, repo=None):
- this = cls({key: value['value'] for key, value in data.items()})
- return this
-
- @classmethod
def new_empty(cls, repo):
return cls()
@@ -3409,6 +3404,21 @@
key = key.lang
return key
+
+class LanguageDict(BaseDataDict):
+
+ """
+ A structure holding language data for a Wikibase entity.
+
+ Language data are mappings from a language to a string. It can be
+ labels, descriptions and others.
+ """
+
+ @classmethod
+ def fromJSON(cls, data, repo=None):
+ this = cls({key: value['value'] for key, value in data.items()})
+ return this
+
@classmethod
def normalizeData(cls, data):
norm_data = {}
@@ -3436,7 +3446,7 @@
return data
-class AliasesDict(MutableMapping):
+class AliasesDict(BaseDataDict):
"""
A structure holding aliases for a Wikibase entity.
@@ -3444,12 +3454,6 @@
It is a mapping from a language to a list of strings.
"""
- def __init__(self, data=None):
- super().__init__()
- self._data = {}
- if data:
- self.update(data)
-
@classmethod
def fromJSON(cls, data, repo=None):
this = cls()
@@ -3458,32 +3462,6 @@
return this
@classmethod
- def new_empty(cls, repo):
- return cls()
-
- def __getitem__(self, key):
- key = LanguageDict.normalizeKey(key)
- return self._data[key]
-
- def __setitem__(self, key, value):
- key = LanguageDict.normalizeKey(key)
- self._data[key] = value
-
- def __delitem__(self, key):
- key = LanguageDict.normalizeKey(key)
- del self._data[key]
-
- def __iter__(self):
- return iter(self._data)
-
- def __len__(self):
- return len(self._data)
-
- def __contains__(self, key):
- key = LanguageDict.normalizeKey(key)
- return key in self._data
-
- @classmethod
def normalizeData(cls, data):
norm_data = {}
for key, values in data.items():
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/642653
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: Ie4f01d57f9274d5f68a1224303f87bb79906a885
Gerrit-Change-Number: 642653
Gerrit-PatchSet: 1
Gerrit-Owner: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/586402 )
Change subject: [doc] Make BasicBot example a ConfigParserBot to explain the usage
......................................................................
[doc] Make BasicBot example a ConfigParserBot to explain the usage
Change-Id: I0f644e2975772c1b1886e846bc7b872f0051b0be
---
M scripts/basic.py
1 file changed, 18 insertions(+), 2 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/basic.py b/scripts/basic.py
index 5a767f7..3549691 100755
--- a/scripts/basic.py
+++ b/scripts/basic.py
@@ -23,8 +23,22 @@
-summary: Set the action summary message for the edit.
+All settings can be made either by giving option with the command line
+or with a settings file which is scripts.ini by default. If you don't
+want the default values you can add any option you want to change to
+that settings file below the [basic] section like:
-The following generators and filters are supported:
+ [basic] ; inline comments starts with colon
+ # This is a commend line. Assignments may be done with '=' or ':'
+ text: A text with line break and
+ continuing on next line to be put
+ replace: yes ; yes/no, on/off, true/false and 1/0 is also valid
+ summary = Bot: My first test edit with pywikibot
+
+Every script has its own section with the script name as header.
+
+In addition the following generators and filters are supported but
+cannot be set by settings file:
¶ms;
"""
@@ -37,7 +51,8 @@
from pywikibot import pagegenerators
from pywikibot.bot import (
- SingleSiteBot, ExistingPageBot, NoRedirectPageBot, AutomaticTWSummaryBot)
+ SingleSiteBot, ConfigParserBot, ExistingPageBot, NoRedirectPageBot,
+ AutomaticTWSummaryBot)
from pywikibot.tools import PYTHON_VERSION
if PYTHON_VERSION >= (3, 9):
@@ -53,6 +68,7 @@
class BasicBot(
# Refer pywikobot.bot for generic bot classes
SingleSiteBot, # A bot only working on one site
+ ConfigParserBot, # A bot which reads options from scripts.ini setting file
# CurrentPageBot, # Sets 'current_page'. Process it in treat_page method.
# # Not needed here because we have subclasses
ExistingPageBot, # CurrentPageBot which only treats existing pages
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/586402
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: I0f644e2975772c1b1886e846bc7b872f0051b0be
Gerrit-Change-Number: 586402
Gerrit-PatchSet: 5
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-CC: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-MessageType: merged
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 <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: Hazard-SJ <hazardsjwiki(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-MessageType: merged