jenkins-bot has submitted this change and it was merged.
Change subject: use ImportWarning for missing package __init__
......................................................................
use ImportWarning for missing package __init__
If a script is located in a directory without an __init__,
a warning was printed on stderr.
Script creators complained about this on pywikipedia-l, as
stderr can be used to contain data to be piped to other
processes.
Also add main().
Change-Id: Ia4aa8dab7203fa1498c0684759641d6ef7c8e139
---
M pwb.py
1 file changed, 12 insertions(+), 3 deletions(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pwb.py b/pwb.py
index b96b002..45415c0 100755
--- a/pwb.py
+++ b/pwb.py
@@ -28,6 +28,8 @@
import sys
import types
+from warnings import warn
+
pwb = None
@@ -182,7 +184,9 @@
[])
sys.exit(1)
-if __name__ == "__main__":
+
+def main():
+ """Command line entry point."""
if len(sys.argv) > 1 and not re.match('-{1,2}help', sys.argv[1]):
file_package = None
tryimport_pwb()
@@ -223,9 +227,14 @@
try:
__import__(file_package)
except ImportError as e:
- print('Parent module %s not found: %s'
- % (file_package, e), file=sys.stderr)
+ warn('Parent module %s not found: %s'
+ % (file_package, e), ImportWarning)
run_python_file(filename, argv, argvu, file_package)
+ return True
else:
+ return False
+
+if __name__ == '__main__':
+ if not main():
print(__doc__)
--
To view, visit https://gerrit.wikimedia.org/r/209428
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia4aa8dab7203fa1498c0684759641d6ef7c8e139
Gerrit-PatchSet: 4
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: wikimedia username moved into Travis-CI settings
......................................................................
wikimedia username moved into Travis-CI settings
Bug: T98189
Change-Id: I4eb4ed6f9a2cfecb23e71b3e0cdc0c433a8bc5b2
---
M .travis.yml
1 file changed, 1 insertion(+), 4 deletions(-)
Approvals:
John Vandenberg: Looks good to me, but someone else must approve
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/.travis.yml b/.travis.yml
index 5123197..07d15b0 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -32,10 +32,7 @@
pip install httplib2 ;
fi
-
- - if [[ "$GITHUB_USER" == "wikimedia" ]]; then
- PYWIKIBOT2_USERNAME="Pywikibot-test" ;
- else
+ - if [[ "$GITHUB_USER" != "wikimedia" ]]; then
export PYWIKIBOT2_TEST_WRITE_FAIL=1 ;
fi
--
To view, visit https://gerrit.wikimedia.org/r/209139
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I4eb4ed6f9a2cfecb23e71b3e0cdc0c433a8bc5b2
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: [FIX] http_tests: Reset version number
......................................................................
[FIX] http_tests: Reset version number
After 65450196 has been implemented it changed the version number to an
invalid value which worked for the test but not for subsequent tests.
This is caching the old value and restoring it after the tests.
Change-Id: I9523f715b930194eff347ed5a9abb8b95226f965
---
M tests/http_tests.py
1 file changed, 11 insertions(+), 7 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/http_tests.py b/tests/http_tests.py
index a42557b..f3255fd 100644
--- a/tests/http_tests.py
+++ b/tests/http_tests.py
@@ -330,13 +330,17 @@
self.assertEqual('%E2%81%82', http.user_agent_username(u'⁂'))
def test_version(self):
- pywikibot.version.cache = None
- http.user_agent(format_string='version does not appear')
- self.assertIsNone(pywikibot.version.cache)
- pywikibot.version.cache = {'rev': 'dummy'}
- self.assertEqual(http.user_agent(format_string='{version} does appear'),
- 'dummy does appear')
- self.assertIsNotNone(pywikibot.version.cache)
+ old_cache = pywikibot.version.cache
+ try:
+ pywikibot.version.cache = None
+ http.user_agent(format_string='version does not appear')
+ self.assertIsNone(pywikibot.version.cache)
+ pywikibot.version.cache = {'rev': 'dummy'}
+ self.assertEqual(http.user_agent(format_string='{version} does appear'),
+ 'dummy does appear')
+ self.assertIsNotNone(pywikibot.version.cache)
+ finally:
+ pywikibot.version.cache = old_cache
class DefaultUserAgentTestCase(TestCase):
--
To view, visit https://gerrit.wikimedia.org/r/209185
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I9523f715b930194eff347ed5a9abb8b95226f965
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: [bugfix] Fix ISBN formatting
......................................................................
[bugfix] Fix ISBN formatting
- update ISBN group numbers for group 1 + 3 + 5
- remove obsolete code stuff
- updated some doc strings from core
bug: T97887
Change-Id: I0f120a3e639e45f08c8a21f84af9a7d835f6a635
---
M isbn.py
1 file changed, 53 insertions(+), 67 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/isbn.py b/isbn.py
index 19ef5d4..b38c36d 100644
--- a/isbn.py
+++ b/isbn.py
@@ -1,9 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-
"""
-This script goes over multiple pages of the home wiki, and reports invalid
-ISBN numbers.
+This script reports and fixes invalid ISBN numbers.
Additionally, it can convert all ISBN-10 codes to the ISBN-13 format, and
correct the ISBN format by placing hyphens.
@@ -36,7 +34,7 @@
"""
#
-# (C) Pywikibot team, 2006-2014
+# (C) Pywikibot team, 2006-2015
#
# Distributed under the terms of the MIT license.
#
@@ -53,7 +51,7 @@
}
# Maps each group number to the list of its publisher number ranges.
-# Taken from http://www.isbn-international.org/converter/ranges.htm
+# Taken from https://www.isbn-international.org/converter/ranges.htm
ranges = {
'0': [ # English speaking area
('00', '19'),
@@ -69,6 +67,7 @@
('4000', '5499'),
('55000', '86979'),
('869800', '998999'),
+ ('9990000', '9999999'),
],
'2': [ # French speaking area
('00', '19'),
@@ -90,7 +89,11 @@
('7000', '8499'),
('85000', '89999'),
('900000', '949999'),
- ('9500000', '9999999'),
+ ('9500000', '9539999'),
+ ('95400', '96999'),
+ ('9700000', '9899999'),
+ ('99000', '99499'),
+ ('99500', '99999'),
],
'4': [ # Japan
('00', '19'),
@@ -101,15 +104,24 @@
('9500000', '9999999'),
],
'5': [ # Russian Federation
+ ('00000', '00499'),
+ ('0050', '0099'),
('00', '19'),
- ('200', '699'),
+ ('200', '420'),
+ ('4200', '4299'),
+ ('430', '430'),
+ ('4310', '4399'),
+ ('440', '440'),
+ ('4410', '4499'),
+ ('450', '699'),
('7000', '8499'),
('85000', '89999'),
('900000', '909999'),
('91000', '91999'),
('9200', '9299'),
('93000', '94999'),
- ('9500', '9799'),
+ ('9500000', '9500999'),
+ ('9501', '9799'),
('98000', '98999'),
('9900000', '9909999'),
('9910', '9999'),
@@ -1160,40 +1172,17 @@
}
-class IsbnBot:
- def __init__(self, generator):
- self.generator = generator
-
- def run(self):
- for page in self.generator:
- try:
- text = page.get(get_redirect=self.touch_redirects)
- # convert ISBN numbers
- page.put(text)
- except pywikibot.NoPage:
- pywikibot.output(u"Page %s does not exist?!"
- % page.title(asLink=True))
- except pywikibot.IsRedirectPage:
- pywikibot.output(u"Page %s is a redirect; skipping."
- % page.title(asLink=True))
- except pywikibot.LockedPage:
- pywikibot.output(u"Page %s is locked?!"
- % page.title(asLink=True))
-
-
class InvalidIsbnException(pywikibot.Error):
- """Invalid ISBN"""
+
+ """Invalid ISBN."""
class ISBN:
- """
- Abstract superclass
- """
+
+ """Abstract superclass."""
def format(self):
- """
- Puts hyphens into this ISBN number.
- """
+ """Put hyphens into this ISBN number."""
result = ''
rest = ''
for digit in self.digits():
@@ -1219,7 +1208,7 @@
# Determine the publisher
for (start, end) in publisherRanges:
length = len(start) # NOTE: start and end always have equal length
- if rest[:length] > start and rest[:length] <= end:
+ if rest[:length] >= start and rest[:length] <= end:
result += rest[:length] + '-'
rest = rest[length:]
break
@@ -1233,6 +1222,9 @@
class ISBN13(ISBN):
+
+ """ISBN 13."""
+
def __init__(self, code, checksumMissing=False):
self.code = code
if checksumMissing:
@@ -1243,9 +1235,7 @@
return ['978', '979']
def digits(self):
- """
- Returns a list of the digits in the ISBN code.
- """
+ """Return a list of the digits in the ISBN code."""
result = []
for c in self.code:
if c.isdigit():
@@ -1264,7 +1254,7 @@
% self.code)
def calculateChecksum(self):
- # See http://en.wikipedia.org/wiki/ISBN#Check_digit_in_ISBN_13
+ # See https://en.wikipedia.org/wiki/ISBN#Check_digit_in_ISBN_13
sum = 0
for i in range(0, 13 - 1, 2):
sum += self.digits()[i]
@@ -1274,6 +1264,9 @@
class ISBN10(ISBN):
+
+ """ISBN 10."""
+
def __init__(self, code):
self.code = code
self.checkValidity()
@@ -1282,9 +1275,7 @@
return []
def digits(self):
- """
- Returns a list of the digits and Xs in the ISBN code.
- """
+ """Return a list of the digits and Xs in the ISBN code."""
result = []
for c in self.code:
if c.isdigit() or c in 'Xx':
@@ -1295,19 +1286,13 @@
return result
def checkChecksum(self):
- """
- Raises an InvalidIsbnException if the checksum shows that the
- ISBN is incorrect.
- """
- # See http://en.wikipedia.org/wiki/ISBN#Check_digit_in_ISBN_10
+ """Raise an InvalidIsbnException if the ISBN checksum is incorrect."""
+ # See https://en.wikipedia.org/wiki/ISBN#Check_digit_in_ISBN_10
sum = 0
for i in range(0, 9):
sum += (i + 1) * int(self.digits()[i])
- #print sum
checksum = sum % 11
- #print checksum
lastDigit = self.digits()[-1]
- #print lastDigit
if not ((checksum == 10 and lastDigit in 'Xx') or
(lastDigit.isdigit() and checksum == int(lastDigit))):
raise InvalidIsbnException('The ISBN checksum of %s is incorrect.'
@@ -1325,15 +1310,13 @@
def toISBN13(self):
"""
- Creates a 13-digit ISBN from this 10-digit ISBN by prefixing the GS1
- prefix '978' and recalculating the checksum.
+ Create a 13-digit ISBN from this 10-digit ISBN.
+
+ Adds the GS1 prefix '978' and recalculates the checksum.
The hyphenation structure is taken from the format of the original
ISBN number.
"""
code = '978-' + self.code[:-1]
-
- #cs = self.calculateChecksum()
- #code += str(cs)
return ISBN13(code, checksumMissing=True)
def format(self):
@@ -1345,21 +1328,20 @@
def getIsbn(code):
+ """Return an ISBN object for the code."""
try:
i = ISBN13(code)
- except InvalidIsbnException, e13:
+ except InvalidIsbnException as e13:
try:
i = ISBN10(code)
- except InvalidIsbnException, e10:
+ except InvalidIsbnException as e10:
raise InvalidIsbnException(u'ISBN-13: %s / ISBN-10: %s'
% (e13, e10))
return i
def _hyphenateIsbnNumber(match):
- """
- Helper function to deal with a single ISBN
- """
+ """Helper function to deal with a single ISBN."""
code = match.group('code')
try:
i = getIsbn(code)
@@ -1377,9 +1359,7 @@
def _isbn10toIsbn13(match):
- """
- Helper function to deal with a single ISBN
- """
+ """Helper function to deal with a single ISBN."""
code = match.group('code')
try:
i = getIsbn(code)
@@ -1391,12 +1371,15 @@
def convertIsbn10toIsbn13(text):
+ """Helper function to convert ISBN 10 to ISBN 13."""
isbnR = re.compile(r'(?<=ISBN )(?P<code>[\d\-]+[Xx]?)')
text = isbnR.sub(_isbn10toIsbn13, text)
return text
class IsbnBot:
+
+ """ISBN bot."""
def __init__(self, generator, to13=False, format=False, always=False):
self.generator = generator
@@ -1413,7 +1396,7 @@
code = match.group('code')
try:
getIsbn(code)
- except InvalidIsbnException, e:
+ except InvalidIsbnException as e:
pywikibot.output(e)
newText = oldText
@@ -1424,7 +1407,7 @@
newText = self.isbnR.sub(_hyphenateIsbnNumber, newText)
self.save(page, newText)
except pywikibot.NoPage:
- pywikibot.output(u"Page %s does not exist?!"
+ pywikibot.output(u"Page %s does not exist"
% page.title(asLink=True))
except pywikibot.IsRedirectPage:
pywikibot.output(u"Page %s is a redirect; skipping."
@@ -1471,6 +1454,9 @@
def main():
+ """
+ Process command line arguments and invoke bot.
+ """
#page generator
gen = None
# This temporary array is used to read the page title if one single
--
To view, visit https://gerrit.wikimedia.org/r/208377
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I0f120a3e639e45f08c8a21f84af9a7d835f6a635
Gerrit-PatchSet: 5
Gerrit-Project: pywikibot/compat
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Allow automatic cmdline mode with wikipedia:en
......................................................................
Allow automatic cmdline mode with wikipedia:en
2b07db2 allowed command line arguments for -family and -lang
to put generate_user_files into automatic generation mode.
However it didnt detect when -family:wikipedia -lang:en
was used, as this was the default before arguments were parsed.
Change-Id: I34fc2c0553e742bb487baef59142e5ddee6051e6
---
M generate_user_files.py
1 file changed, 4 insertions(+), 3 deletions(-)
Approvals:
John Vandenberg: Looks good to me, but someone else must approve
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/generate_user_files.py b/generate_user_files.py
index 7c99c11..8abd8c5 100755
--- a/generate_user_files.py
+++ b/generate_user_files.py
@@ -341,9 +341,6 @@
@type args: list of unicode
"""
global base_dir
- # Force default
- if config.family == 'wikipedia' and config.mylang == 'language':
- config.mylang = 'en'
default_args = (config.family, config.mylang, None)
@@ -361,6 +358,10 @@
else:
force = False
+ # Force default
+ if config.family == 'wikipedia' and config.mylang == 'language':
+ args = ('wikipedia', 'en', username)
+
while not force or config.verbose_output:
pywikibot.output(u'\nYour default user directory is "%s"' % base_dir)
if pywikibot.input_yn("Do you want to use that directory?",
--
To view, visit https://gerrit.wikimedia.org/r/209017
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I34fc2c0553e742bb487baef59142e5ddee6051e6
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: [FEAT] http: Get revision/version if necessary
......................................................................
[FEAT] http: Get revision/version if necessary
This changes pywikibot.comms.http to always use the version number even
if it's not cached. The pywikibot.version module is now always using a
custom user-agent to avoid that {version} or {revision} appears in it
and creating an infinite recursion.
To avoid defining the version and revision if they are not appearing in
the user-agent it is using a custom formatter which handles those two
special so that they don't have to appear in format's args and kwargs.
Instead they will be only defined if the formatter finds those in the
string.
Change-Id: Ia7a31cfba4d467118713fbb0122dad932b3a5c39
---
M pywikibot/comms/http.py
M pywikibot/version.py
M tests/http_tests.py
3 files changed, 29 insertions(+), 9 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index 54549f1..e45c52b 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -27,6 +27,7 @@
import time
from distutils.version import StrictVersion
+from string import Formatter
from warnings import warn
# Verify that a working httplib2 is present.
@@ -137,6 +138,22 @@
}
+class _UserAgentFormatter(Formatter):
+
+ """User-agent formatter to load version/revision only if necessary."""
+
+ def get_value(self, key, args, kwargs):
+ """Get field as usual except for version and revision."""
+ # This is the Pywikibot revision; also map it to {version} at present.
+ if key == 'version' or key == 'revision':
+ return pywikibot.version.getversiondict()['rev']
+ else:
+ return super(_UserAgentFormatter, self).get_value(key, args, kwargs)
+
+
+_USER_AGENT_FORMATTER = _UserAgentFormatter()
+
+
def user_agent_username(username=None):
"""
Reduce username to a representation permitted in HTTP headers.
@@ -180,13 +197,6 @@
"""
values = USER_AGENT_PRODUCTS.copy()
- # This is the Pywikibot revision; also map it to {version} at present.
- if pywikibot.version.cache:
- values['revision'] = pywikibot.version.cache['rev']
- else:
- values['revision'] = ''
- values['version'] = values['revision']
-
values['script'] = pywikibot.calledModuleName()
# TODO: script_product should add the script version, if known
@@ -216,7 +226,7 @@
if not format_string:
format_string = config.user_agent_format
- formatted = format_string.format(**values)
+ formatted = _USER_AGENT_FORMATTER.format(format_string, **values)
# clean up after any blank components
formatted = formatted.replace(u'()', u'').replace(u' ', u' ').strip()
return formatted
diff --git a/pywikibot/version.py b/pywikibot/version.py
index b3ba9eb..8de383e 100644
--- a/pywikibot/version.py
+++ b/pywikibot/version.py
@@ -359,7 +359,8 @@
from pywikibot.comms import http
url = repo or 'https://git.wikimedia.org/feed/pywikibot/core'
- buf = http.fetch(url).content.splitlines()
+ buf = http.fetch(uri=url,
+ headers={'user-agent': '{pwb}'}).content.splitlines()
try:
hsh = buf[13].split('/')[5][:-1]
return hsh
diff --git a/tests/http_tests.py b/tests/http_tests.py
index 7692acb..a42557b 100644
--- a/tests/http_tests.py
+++ b/tests/http_tests.py
@@ -329,6 +329,15 @@
self.assertEqual('%E2%81%82', http.user_agent_username(u'⁂'))
+ def test_version(self):
+ pywikibot.version.cache = None
+ http.user_agent(format_string='version does not appear')
+ self.assertIsNone(pywikibot.version.cache)
+ pywikibot.version.cache = {'rev': 'dummy'}
+ self.assertEqual(http.user_agent(format_string='{version} does appear'),
+ 'dummy does appear')
+ self.assertIsNotNone(pywikibot.version.cache)
+
class DefaultUserAgentTestCase(TestCase):
--
To view, visit https://gerrit.wikimedia.org/r/209053
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia7a31cfba4d467118713fbb0122dad932b3a5c39
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot <>