jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/533226 )
Change subject: [doc] ConfigParserBot documentation
......................................................................
[doc] ConfigParserBot documentation
Change-Id: Ia353c95771d7086629420c91f8630c8e94739c46
---
M pywikibot/bot.py
1 file changed, 6 insertions(+), 0 deletions(-)
Approvals:
D3r1ck01: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 6dfb04d..ad1d536 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -19,6 +19,12 @@
set the C{site} property and it's deprecated to request it. Instead site of
the current page should be used. And out of C{run} that sit isn't defined.
+* L{ConfigParserBot}: Bot class which supports reading options from a
+ scripts.ini configuration file. That file consists of sections, led by a
+ C{[section]} header and followed by C{option: value} or C{option=value}
+ entries. The section is the script name without .py suffix. All options
+ identified must be predefined in availableOptions dictionary.
+
* L{Bot}: The previous base class which should be avoided. This class is mainly
used for bots which work with wikibase or together with an image repository.
--
To view, visit https://gerrit.wikimedia.org/r/533226
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia353c95771d7086629420c91f8630c8e94739c46
Gerrit-Change-Number: 533226
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/533244 )
Change subject: [IMPR] Enable inline comment prefixes with Python 3
......................................................................
[IMPR] Enable inline comment prefixes with Python 3
Inline comment prefixes where disabled with Python 3.2.
Enable it with ';' which is the same as in Python 2.
Note: Python 2 cannot set other inline comment prefixes
and has no keyword parameter inline_comment_prefixes.
Change-Id: I790ce04d6489f6004699c80a270f488b01351462
---
M pywikibot/bot.py
1 file changed, 5 insertions(+), 1 deletion(-)
Approvals:
D3r1ck01: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 6dfb04d..d99b41a 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -1756,7 +1756,11 @@
def setOptions(self, **kwargs):
"""Read settings from scripts.ini file."""
- conf = configparser.ConfigParser()
+ if PY2:
+ conf = configparser.ConfigParser()
+ else:
+ conf = configparser.ConfigParser(inline_comment_prefixes=[';'])
+
section = calledModuleName()
if (conf.read(self.INI) == [self.INI] and conf.has_section(section)):
--
To view, visit https://gerrit.wikimedia.org/r/533244
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I790ce04d6489f6004699c80a270f488b01351462
Gerrit-Change-Number: 533244
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/533090 )
Change subject: [doc] Update HISTORY.rst
......................................................................
[doc] Update HISTORY.rst
Change-Id: Iedbd74a788d8e1aa50e918c176b8687b313b66ed
---
M HISTORY.rst
1 file changed, 4 insertions(+), 0 deletions(-)
Approvals:
Zoranzoki21: Looks good to me, but someone else must approve
Huji: Looks good to me, approved
jenkins-bot: Verified
diff --git a/HISTORY.rst b/HISTORY.rst
index d5a3d3d..9f2509a 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -4,6 +4,10 @@
Current release
---------------
+* Enable global args with pwb.py wrapper script (T216825)
+* Add a new ConfigParserBot class to set options from the scripts.ini file (T223778)
+* Check a user's rights rather than group memberships; 'sysopnames' will be deprecated (T229293, T189126, T122705, T119335, T75545)
+* proofreadpage.py: fix footer detection (T230301)
* Add allowusertalk to the User.block() options (T229288)
* botirc module will be removed in next release (T212632)
* weblib module will be removed in next release (T85001)
--
To view, visit https://gerrit.wikimedia.org/r/533090
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Iedbd74a788d8e1aa50e918c176b8687b313b66ed
Gerrit-Change-Number: 533090
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Huji <huji.huji(a)gmail.com>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444(a)gmail.com>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/495479 )
Change subject: [IMPR] Enable global args with pwb.py script
......................................................................
[IMPR] Enable global args with pwb.py script
This can be used for tests to set the default site like
python pwb.py -lang:de bot_tests -v
- Update doc string
- a new method handle_args parses given args and returns the script's
filename and its options and local pwb arguments which can be passed
to pywikibot.handle_args
- check whether local pwb options are valid. Otherwise print an error
and the doc string.
Note: Idf0af67a must be merged first
Bug: T216825
Change-Id: I511604833548f197e8a38dd72c211ebb851db8fb
---
M pwb.py
1 file changed, 34 insertions(+), 10 deletions(-)
Approvals:
D3r1ck01: Looks good to me, but someone else must approve
Huji: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pwb.py b/pwb.py
index 36d2b7b..0a882c7 100755
--- a/pwb.py
+++ b/pwb.py
@@ -4,10 +4,15 @@
Run scripts using:
- python pwb.py <name_of_script> <options>
+ python pwb.py <pwb options> <name_of_script> <options>
and it will use the package directory to store all user files, will fix up
search paths so the package does not need to be installed, etc.
+
+Currently <pwb options> are global options. This can be used for tests
+to set the default site like (see T216825):
+
+ python pwb.py -lang:de bot_tests -v
"""
# (C) Pywikibot team, 2012-2019
#
@@ -114,6 +119,25 @@
return path
+def handle_args(pwb_py, *args):
+ """Handle args and get filename.
+
+ @return: filename, script args, local args for pwb.py
+ @rtype: tuple
+ """
+ fname = None
+ index = 0
+ for arg in args:
+ if arg.startswith('-'):
+ index += 1
+ else:
+ fname = arg
+ if not fname.endswith('.py'):
+ fname += '.py'
+ break
+ return fname, list(args[index + int(bool(fname)):]), args[:index]
+
+
# Establish a normalised path for the directory containing pwb.py.
# Either it is '.' if the user's current working directory is the same,
# or it is the absolute path for the directory of pwb.py
@@ -131,15 +155,7 @@
"Try running 'pip install requests'.".format(e))
del requests
-if len(sys.argv) > 1 and sys.argv[1][0] != '-':
- filename = sys.argv[1]
- if not filename.endswith('.py'):
- filename += '.py'
-else:
- filename = None
-
-# Skip the filename if one was given
-args = sys.argv[(2 if filename else 1):]
+filename, args, local_args = handle_args(*sys.argv)
# Search for user-config.py before creating one.
# If successful, user-config.py already exists in one of the candidate
@@ -221,6 +237,14 @@
if not filename:
return False
+ if local_args: # don't use sys.argv
+ pwb_args = pwb.handle_args(local_args)
+ if pwb_args:
+ print('ERROR: unknown pwb.py argument{}: {}\n'
+ .format('' if len(pwb_args) == 1 else 's',
+ ', '.join(pwb_args)))
+ return False
+
file_package = None
argvu = pwb.argvu[1:]
--
To view, visit https://gerrit.wikimedia.org/r/495479
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I511604833548f197e8a38dd72c211ebb851db8fb
Gerrit-Change-Number: 495479
Gerrit-PatchSet: 5
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: Huji <huji.huji(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot (75)
Gerrit-CC: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-CC: Hashar <hashar(a)free.fr>
Gerrit-CC: Zhuyifei1999 <zhuyifei1999(a)gmail.com>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/532704 )
Change subject: Check a user's rights rather than group memberships
......................................................................
Check a user's rights rather than group memberships
This is a continuation to ee2d6d664c30
Bug: T231263
Change-Id: I5f6d71c0d004b8b13937d7c193d93b79186b2b37
---
M pywikibot/page.py
1 file changed, 2 insertions(+), 2 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index e1cd72c..33176bf 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -1918,8 +1918,8 @@
pywikibot.output('Deleting %s.' % (self.title(as_link=True)))
reason = pywikibot.input('Please enter a reason for the deletion:')
- # If user is a sysop, delete the page
- if self.site.username(sysop=True):
+ # If user has 'delete' right, delete the page
+ if 'delete' in self.site.userinfo['rights']:
answer = 'y'
if prompt and not hasattr(self.site, '_noDeletePrompt'):
answer = pywikibot.input_choice(
--
To view, visit https://gerrit.wikimedia.org/r/532704
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I5f6d71c0d004b8b13937d7c193d93b79186b2b37
Gerrit-Change-Number: 532704
Gerrit-PatchSet: 2
Gerrit-Owner: Huji <huji.huji(a)gmail.com>
Gerrit-Reviewer: JJMC89 <JJMC89.Wikimedia(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/502504 )
Change subject: [IMPR] Improvements for catall.py
......................................................................
[IMPR] Improvements for catall.py
- IsRedirectPage exception is to far away from try statement
- use print statement for heading line only once in the code
- simplify list comparisons
Change-Id: I3b2dfd3aa856ef9804d7c6c20a237d21b14e211f
---
M scripts/catall.py
1 file changed, 9 insertions(+), 8 deletions(-)
Approvals:
D3r1ck01: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/catall.py b/scripts/catall.py
index b019976..a90ed29 100755
--- a/scripts/catall.py
+++ b/scripts/catall.py
@@ -21,7 +21,7 @@
"""
#
# (C) Rob W.W. Hooft, Andre Engels, 2004
-# (C) Pywikibot team, 2004-2018
+# (C) Pywikibot team, 2004-2019
#
# Distributed under the terms of the MIT license.
#
@@ -59,7 +59,7 @@
elif choice == '??':
pywikibot.output(pagetext[0:length])
length = length + 500
- elif choice == 'xx' and chosen == []:
+ elif choice == 'xx' and not chosen:
chosen = None
done = True
elif choice == 'q':
@@ -106,26 +106,27 @@
for p in mysite.allpages(start=start):
try:
text = p.get()
+ except pywikibot.IsRedirectPage:
+ pywikibot.output('{} is a redirect'.format(p.title()))
+ else:
+ pywikibot.output('========== {} =========='.format(p.title()))
cats = p.categories()
+
if not cats:
- pywikibot.output('========== {} =========='.format(p.title()))
pywikibot.output('No categories')
pywikibot.output('-' * 40)
newcats = choosecats(text)
- if newcats != [] and newcats is not None:
+ if newcats:
make_categories(p, newcats, mysite)
elif docorrections:
- pywikibot.output('========== {} =========='.format(p.title()))
for c in cats:
pywikibot.output(c.title())
pywikibot.output('-' * 40)
newcats = choosecats(text)
if newcats is None:
make_categories(p, [], mysite)
- elif newcats != []:
+ elif newcats:
make_categories(p, newcats, mysite)
- except pywikibot.IsRedirectPage:
- pywikibot.output('{} is a redirect'.format(p.title()))
if __name__ == '__main__':
--
To view, visit https://gerrit.wikimedia.org/r/502504
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I3b2dfd3aa856ef9804d7c6c20a237d21b14e211f
Gerrit-Change-Number: 502504
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/511692 )
Change subject: [IMPR] add a new ConfigParserBot class
......................................................................
[IMPR] add a new ConfigParserBot class
ConfigParserBot enables to set options from the scripts.ini setting file.
The setting section for the script is identified by the module name.
All settings in the settings file must be listed in the availabelOptions
dictionary of the bot. The type of the value is identified by the
availabelOptions default.
The script's settings is like this:
[add_text]
summary = Bot: Aggiungo template Categorizzare
[shell]
always=true
Bug: T223778
Change-Id: I601a5bc055239a7848c897b4651ed22f80af2ff0
---
M pywikibot/bot.py
1 file changed, 56 insertions(+), 1 deletion(-)
Approvals:
D3r1ck01: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 954d07f..b7f906b 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -71,7 +71,7 @@
'showHelp', 'suggest_help',
'writeToCommandLogFile', 'open_webbrowser',
'OptionHandler',
- 'BaseBot', 'Bot', 'SingleSiteBot', 'MultipleSitesBot',
+ 'BaseBot', 'Bot', 'ConfigParserBot', 'SingleSiteBot', 'MultipleSitesBot',
'CurrentPageBot', 'AutomaticTWSummaryBot',
'ExistingPageBot', 'FollowRedirectPageBot', 'CreatingPageBot',
'RedirectPageBot', 'NoRedirectPageBot',
@@ -92,6 +92,11 @@
from warnings import warn
import webbrowser
+try:
+ import configparser
+except ImportError: # PY2
+ import ConfigParser as configparser # noqa: N813
+
from textwrap import fill
import pywikibot
@@ -1715,6 +1720,56 @@
return page
+class ConfigParserBot(BaseBot):
+
+ """A bot class that can read options from scripts.ini file.
+
+ All options must be predefined in availableOptions dictionary. The type
+ of these options is responsible for the correct interpretation of the
+ options type given by the .ini file. They can be interpreted as bool,
+ int, float or str (default). The settings file may be like:
+
+ [add_text]
+ # edit summary for the bot.
+ summary = Bot: Aggiungo template Categorizzare
+
+ [shell] ; Shell options
+ always: true
+
+ The option values are interpreted in this order::
+
+ - availableOptions default setting
+ - script.ini options settings
+ - command line arguments
+ """
+
+ INI = 'scripts.ini'
+
+ def setOptions(self, **kwargs):
+ """Read settings from scripts.ini file."""
+ conf = configparser.ConfigParser()
+ section = calledModuleName()
+
+ if (conf.read(self.INI) == [self.INI] and conf.has_section(section)):
+ pywikibot.output('Reading settings from {} file.'.format(self.INI))
+ args = {}
+ for option, value in self.availableOptions.items():
+ if not conf.has_option(section, option):
+ continue
+ # use a convenience parser method, default to get()
+ method = getattr(conf, 'get' + type(value).__name__,
+ getattr(conf, 'get'))
+ args[option] = method(section, option)
+ for opt in set(conf.options(section)) - set(args):
+ pywikibot.warning(
+ opt + ' is not a valid option. It was ignored.')
+ args.update(kwargs)
+ else:
+ args = kwargs
+
+ super(ConfigParserBot, self).setOptions(**args)
+
+
class CurrentPageBot(BaseBot):
"""
--
To view, visit https://gerrit.wikimedia.org/r/511692
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I601a5bc055239a7848c897b4651ed22f80af2ff0
Gerrit-Change-Number: 511692
Gerrit-PatchSet: 10
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/508077 )
Change subject: Remove caret from re.match
......................................................................
Remove caret from re.match
Change-Id: I15f533f78afbdc03040483f40e02511c1cf97e09
---
M pywikibot/date.py
M pywikibot/site.py
M pywikibot/tools/__init__.py
M scripts/casechecker.py
M scripts/reflinks.py
M scripts/upload.py
6 files changed, 7 insertions(+), 7 deletions(-)
Approvals:
Matěj Suchánek: Looks good to me, but someone else must approve
D3r1ck01: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/date.py b/pywikibot/date.py
index aecefd1..efa0609 100644
--- a/pywikibot/date.py
+++ b/pywikibot/date.py
@@ -372,7 +372,7 @@
Returns a compiled regex object and a list of digit decoders.
"""
if pattern not in _escPtrnCache2:
- newPattern = '^' # beginning of the string
+ newPattern = '' # match starts at the beginning of the string
strPattern = ''
decoders = []
for s in _reParameters.split(pattern):
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 59da8df..6ff1b62 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -1392,7 +1392,7 @@
All values of the siteinfo property 'general' are directly available.
"""
- WARNING_REGEX = re.compile(r'^Unrecognized values? for parameter '
+ WARNING_REGEX = re.compile(r'Unrecognized values? for parameter '
r'["\']siprop["\']: (.+?)\.?$')
# Until we get formatversion=2, we have to convert empty-string properties
@@ -2964,7 +2964,7 @@
try:
versionstring = self.siteinfo.get('generator',
expiry=0 if force else 1)
- m = re.match(r'^MediaWiki ([0-9]+)\.([0-9]+)(.*)$', versionstring)
+ m = re.match(r'MediaWiki ([0-9]+)\.([0-9]+)(.*)$', versionstring)
if m:
return (int(m.group(1)), int(m.group(2)), m.group(3))
# May occur if you are not logged in (no API read permissions).
diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py
index 8bd43d5..52d4610 100644
--- a/pywikibot/tools/__init__.py
+++ b/pywikibot/tools/__init__.py
@@ -730,7 +730,7 @@
"""
MEDIAWIKI_VERSION = re.compile(
- r'^(\d+(?:\.\d+)+)(-?wmf\.?(\d+)|alpha|beta(\d+)|-?rc\.?(\d+)|.*)?$')
+ r'(\d+(?:\.\d+)+)(-?wmf\.?(\d+)|alpha|beta(\d+)|-?rc\.?(\d+)|.*)?$')
@classmethod
def from_generator(cls, generator):
diff --git a/scripts/casechecker.py b/scripts/casechecker.py
index 08bd2f4..d49b50e 100755
--- a/scripts/casechecker.py
+++ b/scripts/casechecker.py
@@ -53,7 +53,7 @@
# all letters that may be used as suffixes after roman numbers: "Iый"
romannumSuffixes = localLowerLtr
romanNumSfxPtrn = re.compile(
- '^[' + romanNumChars + ']+[' + localLowerLtr + ']+$')
+ '[{}]+[{}]+$'.format(romanNumChars, localLowerLtr))
whitelists = {
'ru': 'ВП:КЛ/Проверенные',
diff --git a/scripts/reflinks.py b/scripts/reflinks.py
index 97fdba5..cc23e09 100755
--- a/scripts/reflinks.py
+++ b/scripts/reflinks.py
@@ -119,7 +119,7 @@
re.IGNORECASE)
# matches an URL at the index of a website
dirIndex = re.compile(
- r'^\w+://[^/]+/((default|index)\.'
+ r'\w+://[^/]+/((default|index)\.'
r'(asp|aspx|cgi|htm|html|phtml|mpx|mspx|php|shtml|var))?$',
re.IGNORECASE)
# Extracts the domain name
diff --git a/scripts/upload.py b/scripts/upload.py
index 723ac05..79db797 100755
--- a/scripts/upload.py
+++ b/scripts/upload.py
@@ -69,7 +69,7 @@
CHUNK_SIZE_REGEX = re.compile(
- r'^-chunked(?::(\d+(?:\.\d+)?)[ \t]*(k|ki|m|mi)?b?)?$', re.I)
+ r'-chunked(?::(\d+(?:\.\d+)?)[ \t]*(k|ki|m|mi)?b?)?$', re.I)
def get_chunk_size(match):
--
To view, visit https://gerrit.wikimedia.org/r/508077
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I15f533f78afbdc03040483f40e02511c1cf97e09
Gerrit-Change-Number: 508077
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: jenkins-bot (75)