jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/458129 )
Change subject: [bugfix] Do not show empty error messages
......................................................................
[bugfix] Do not show empty error messages
Bug: T203462
Change-Id: I161c11194fd6287fee205c0fa03a8b1a5d7096cb
---
M pywikibot/bot.py
1 file changed, 4 insertions(+), 3 deletions(-)
Approvals:
Dvorapa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index d450a6d..e9900eb 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -1084,9 +1084,10 @@
if unknown_parameters:
additional_text = 'Unknown parameter(s) "{0}"\n'.format(
'", "'.join(unknown_parameters)) + additional_text
- if not additional_text.endswith('\n'):
- additional_text += '\n'
- error(additional_text + 'Use -help for further information.')
+ if additional_text:
+ if not additional_text.endswith('\n'):
+ additional_text += '\n'
+ error(additional_text + 'Use -help for further information.')
def writeToCommandLogFile():
--
To view, visit https://gerrit.wikimedia.org/r/458129
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: I161c11194fd6287fee205c0fa03a8b1a5d7096cb
Gerrit-Change-Number: 458129
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
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/457861 )
Change subject: [IMPR] Show the exception message in async mode
......................................................................
[IMPR] Show the exception message in async mode
Bug: T203448
Change-Id: I00a8c23f72b10bf4f061d5d8b2ec06d534c2bff8
---
M pywikibot/page.py
1 file changed, 3 insertions(+), 0 deletions(-)
Approvals:
Framawiki: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 611320c..0771788 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -111,6 +111,9 @@
except pywikibot.Error as edit_err:
err = edit_err # edit_err will be deleted in the end of the scope
link = self.title(as_link=True)
+ if do_async:
+ pywikibot.error('page {} not saved due to {}\n'
+ .format(link, err))
pywikibot.log('Error saving page %s (%s)\n' % (link, err),
exc_info=True)
if not callback and not do_async:
--
To view, visit https://gerrit.wikimedia.org/r/457861
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: I00a8c23f72b10bf4f061d5d8b2ec06d534c2bff8
Gerrit-Change-Number: 457861
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Framawiki <framawiki(a)tools.wmflabs.org>
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/455396 )
Change subject: [bugfix] Fix the extended user-config extraction regex
......................................................................
[bugfix] Fix the extended user-config extraction regex
detached from I68a04e9198dc179f06c6245f1c1aec518603bd34
The current regex is greedy and finds one section only which accidentally
holds all sections which is really unwanted and unnecessary and could
lead to errors for not imported libraries.
generate_user_files.py:
- DISABLED_SECTIONS are still excluded yet because there have malformed parts
which is a script part but not a setting part and uses external libraries
which shouldn't be used in the user-config.py.
- OBSOLETE_SECTIONS are really obsolete either they are named as obsolete
or the settings are already made by this script.
- parse sections of config2.py by a new function and return a list of
namedtuples containing head, info and content of a section. The info
message (not used yet) is extracted from the first few lines after the
header line and delimited by an empty line or an empty comment.
config2.py:
- fix End of configuration section
generate_user_files_tests.py
- tests added
Bug: T145371
Change-Id: I69a02be8723acdb8f08028760edbe8913c459929
---
M generate_user_files.py
M pywikibot/config2.py
M tests/generate_user_files_tests.py
3 files changed, 55 insertions(+), 33 deletions(-)
Approvals:
Dalba: Looks good to me, approved
jenkins-bot: Verified
diff --git a/generate_user_files.py b/generate_user_files.py
index bef3b80..3033a18 100755
--- a/generate_user_files.py
+++ b/generate_user_files.py
@@ -18,6 +18,14 @@
from generate_family_file import _import_with_no_user_config
+# DISABLED_SECTIONS cannot be copied; variables must be set manually
+DISABLED_SECTIONS = {'USER INTERFACE SETTINGS', # uses sys
+ 'EXTERNAL EDITOR SETTINGS', # uses os
+ }
+OBSOLETE_SECTIONS = {'ACCOUNT SETTINGS', # already set
+ 'OBSOLETE SETTINGS', # obsolete
+ }
+
# Disable user-config usage as we are creating it here
pywikibot = _import_with_no_user_config('pywikibot')
config, __url__ = pywikibot.config2, pywikibot.__url__
@@ -230,40 +238,51 @@
{botpasswords}"""
-def copy_sections():
- """Take config sections and copying them to user-config.py.
+def parse_sections():
+ """Parse sections from config2.py file.
config2.py will be in the pywikibot/ directory relative to this
generate_user_files script.
- @return: config text of all sections.
- @rtype: str
+ @return: a list of ConfigSection named tuples.
+ @rtype: list
"""
+ data = []
+ ConfigSection = namedtuple('ConfigSection', 'head, info, section')
+
install = os.path.dirname(os.path.abspath(__file__))
with codecs.open(os.path.join(install, 'pywikibot', 'config2.py'),
'r', 'utf-8') as config_f:
config_file = config_f.read()
result = re.findall(
- '^(# ############# (?:'
- 'LOGFILE|'
- 'EXTERNAL SCRIPT PATH|'
- 'INTERWIKI|'
- 'SOLVE_DISAMBIGUATION|'
- 'IMAGE RELATED|'
- 'TABLE CONVERSION BOT|'
- 'WEBLINK CHECKER|'
- 'DATABASE|'
- 'SEARCH ENGINE|'
- 'COPYRIGHT|'
- 'FURTHER'
- ') SETTINGS .*)^(?=#####|# =====)',
+ '^(?P<section># #{5,} (?P<head>[A-Z][A-Z_ ]+[A-Z]) #{5,}\r?\n'
+ '(?:^#?\r?\n)?' # There may be an empty or short line after header
+ '(?P<comment>(?:^# .+?)+)' # first comment is used as help string
+ '^.*?)' # catch the remaining text
+ '^(?=# #{5,}|# ={5,})', # until section end marker
config_file, re.MULTILINE | re.DOTALL)
- if not result: # Something is wrong with the regex
- return None
+ for section, head, comment in result:
+ info = ' '.join(text.strip('# ') for text in comment.splitlines())
+ data.append(ConfigSection(head, info, section))
+ return data
- return '\n'.join(result)
+
+def copy_sections():
+ """Take config sections and copy them to user-config.py.
+
+ @return: config text of all selected sections.
+ @rtype: str
+ """
+ result = []
+ sections = parse_sections()
+ # copy settings
+ for section in filter(lambda x: x.head not in (DISABLED_SECTIONS
+ | OBSOLETE_SECTIONS),
+ sections):
+ result.append(section.section)
+ return ''.join(result)
def create_user_config(main_family, main_code, main_username, force=False):
diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index 552f060..957ac47 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -894,6 +894,7 @@
# Version 4 is only available for Python 3.4
pickle_protocol = 2
+# ============================
# End of configuration section
# ============================
diff --git a/tests/generate_user_files_tests.py b/tests/generate_user_files_tests.py
index bde7497..f8c4750 100644
--- a/tests/generate_user_files_tests.py
+++ b/tests/generate_user_files_tests.py
@@ -10,7 +10,6 @@
import re
from tests.aspects import unittest, TestCase
-from unittest import expectedFailure
import generate_user_files as guf
@@ -68,22 +67,23 @@
self.assertEqual(code, 'test')
self.assertEqual(user, 'bar')
- @expectedFailure # T145371
- def test_copy_sections_fail(self):
- """Test copy_sections function for sections not in config text."""
- config_text = guf.copy_sections()
- for section in ('HTTP SETTINGS',
- 'REPLICATION BOT SETTINGS',
- ):
- self.assertNotIn(section, config_text)
+ def test_parse_sections(self):
+ """Test parse_sections regex."""
+ sections = guf.parse_sections()
+ self.assertGreater(len(sections), 10)
+ first = sections[0]
+ last = sections[-1]
+ self.assertEqual('ACCOUNT SETTINGS', first.head)
+ self.assertIn(first.head, first.section)
+ self.assertIn(first.info[:10], first.section)
+ self.assertEqual('OBSOLETE SETTINGS', last.head)
+ self.assertIn(last.head, last.section)
+ self.assertIn(last.info[:10], last.section)
def test_copy_sections_not_found(self):
"""Test copy_sections function for sections not in config text."""
config_text = guf.copy_sections()
- for section in ('ACCOUNT SETTINGS',
- 'OBSOLETE SETTINGS',
- 'EXTERNAL EDITOR SETTINGS',
- ):
+ for section in guf.DISABLED_SECTIONS | guf.OBSOLETE_SECTIONS:
self.assertNotIn(section, config_text)
def test_copy_sections_found(self):
@@ -94,6 +94,8 @@
'EXTERNAL SCRIPT PATH SETTINGS',
'INTERWIKI SETTINGS',
'FURTHER SETTINGS',
+ 'HTTP SETTINGS',
+ 'REPLICATION BOT SETTINGS',
):
self.assertIn(section, config_text)
lines = config_text.splitlines()
--
To view, visit https://gerrit.wikimedia.org/r/455396
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: I69a02be8723acdb8f08028760edbe8913c459929
Gerrit-Change-Number: 455396
Gerrit-PatchSet: 5
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
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/457442 )
Change subject: [bugfix] Solve UnicodeDecodeError in site.getredirtarget
......................................................................
[bugfix] Solve UnicodeDecodeError in site.getredirtarget
This partly reverts I4b6d7f32fc1ec
Bug: T126192
Change-Id: Ibf9ee23573c46b291fcfa435b77d7bde830d7911
---
M pywikibot/site.py
1 file changed, 4 insertions(+), 4 deletions(-)
Approvals:
Zhuyifei1999: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 3671dc7..be63f15 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -3204,8 +3204,8 @@
result = query.submit()
if "query" not in result or "redirects" not in result["query"]:
raise RuntimeError(
- "getredirtarget: No 'redirects' found for page %s."
- % title.encode(self.encoding()))
+ "getredirtarget: No 'redirects' found for page {}."
+ .format(title))
redirmap = {item['from']: {'title': item['to'],
'section': '#'
@@ -3223,8 +3223,8 @@
if title not in redirmap:
raise RuntimeError(
- "getredirtarget: 'redirects' contains no key for page %s."
- % title.encode(self.encoding()))
+ "getredirtarget: 'redirects' contains no key for page {}."
+ .format(title))
target_title = u'%(title)s%(section)s' % redirmap[title]
if self.sametitle(title, target_title):
--
To view, visit https://gerrit.wikimedia.org/r/457442
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: Ibf9ee23573c46b291fcfa435b77d7bde830d7911
Gerrit-Change-Number: 457442
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dalba <dalba.wiki(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: Zhuyifei1999 <zhuyifei1999(a)gmail.com>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/457375 )
Change subject: [cleanup] code cleanup config2.py
......................................................................
[cleanup] code cleanup config2.py
- remove any hints to very old python 2.4 and 2.5 releases
- remove preleading "u" from strings
- use single quotes for strings
- use str.format when line is to be changed
- use string concatening if appropriate
- use booleans in common way
Change-Id: I998a728dd9a82e8fd51247c8fd7921bb5fed33ce
---
M pywikibot/config2.py
1 file changed, 30 insertions(+), 32 deletions(-)
Approvals:
Dalba: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index ad97656..1b1bd67 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -233,7 +233,7 @@
available_ssl_project = []
# By default you are asked for a password on the terminal.
-# A password file may be used, e.g. password_file = ".passwd".
+# A password file may be used, e.g. password_file = '.passwd'
# The path to the password file is relative to that of the user_config file.
# The password file should consist of lines containing Python tuples of any
# of the following formats:
@@ -252,7 +252,7 @@
# edit summary to use if not supplied by bot script
# WARNING: this should NEVER be used in practice, ALWAYS supply a more
# relevant summary for bot edits
-default_edit_summary = u'Pywikibot 3.0-dev'
+default_edit_summary = 'Pywikibot 3.0-dev'
# What permissions to use to set private files to it
# such as password file.
@@ -342,16 +342,16 @@
base_dir = os.path.abspath(environ['PYWIKIBOT_DIR_PWB'])
else:
base_dir_cand = []
- home = os.path.expanduser("~")
+ home = os.path.expanduser('~')
if OSWIN32:
- win_version = int(platform.version().split(".")[0])
+ win_version = int(platform.version().split('.')[0])
if win_version == 5:
- sub_dir = ["Application Data"]
+ sub_dir = ['Application Data']
elif win_version in (6, 10):
- sub_dir = ["AppData", "Roaming"]
+ sub_dir = ['AppData', 'Roaming']
else:
- raise WindowsError(u'Windows version %s not supported yet.'
- % win_version)
+ raise WindowsError('Windows version {} not supported yet.'
+ .format(win_version))
base_dir_cand.extend([[home] + sub_dir + ['Pywikibot'],
[home] + sub_dir + ['pywikibot']])
else:
@@ -393,7 +393,7 @@
for arg in sys.argv[1:]:
if arg.startswith(str('-verbose')) or arg == str('-v'):
- output('The base directory is {0}'.format(base_dir))
+ output('The base directory is ' + base_dir)
break
family_files = {}
@@ -409,8 +409,8 @@
def register_families_folder(folder_path):
"""Register all family class files contained in a directory."""
for file_name in os.listdir(folder_path):
- if file_name.endswith("_family.py"):
- family_name = file_name[:-len("_family.py")]
+ if file_name.endswith('_family.py'):
+ family_name = file_name[:-len('_family.py')]
register_family_file(family_name, os.path.join(folder_path,
file_name))
@@ -455,8 +455,8 @@
transliteration_target = None
# The encoding in which textfiles are stored, which contain lists of page
-# titles. The most used is: 'utf-8'. 'utf-8-sig' recognizes BOM but it is
-# available on Python 2.5 or higher. For a complete list please see:
+# titles. The most used is 'utf-8'; 'utf-8-sig' recognizes BOM.
+# For a complete list please see:
# https://docs.python.org/2/library/codecs.html#standard-encodings
textfile_encoding = 'utf-8'
@@ -484,9 +484,7 @@
# Colorization can be used to markup important text parts of the output.
# On Linux/Unix terminals, ANSI escape codes are used for this. On Windows,
-# it is done by a DLL call via ctypes. ctypes is only available since
-# Python 2.5, so if you're using Python 2.4 or lower on Windows, you should
-# upgrade.
+# it is done by a DLL call via ctypes.
# Set this to False if you're using Linux and your tty doesn't support
# ANSI colors.
try:
@@ -626,7 +624,7 @@
# Example:
#
# disambiguation_comment['wikipedia']['en'] = \
-# "Robot-assisted disambiguation ([[WP:DPL|you can help!]]): %s"
+# 'Robot-assisted disambiguation ([[WP:DPL|you can help!]]): %s'
# Sorting order for alternatives. Set to True to ignore case for sorting order.
sort_ignore_case = False
@@ -730,10 +728,10 @@
# Using the Flickr api
flickr = {
- 'api_key': u'', # Provide your key!
- 'api_secret': u'', # Api secret of your key (optional)
+ 'api_key': '', # Provide your key!
+ 'api_secret': '', # Api secret of your key (optional)
'review': False, # Do we use automatically make our uploads reviewed?
- 'reviewer': u'', # If so, under what reviewer name?
+ 'reviewer': '', # If so, under what reviewer name?
}
# ############# COPYRIGHT SETTINGS ##############
@@ -885,7 +883,7 @@
# pages fetched from screen (mostly) have "\r\n". Interwiki and category
# separator settings in family files should use multiplied of this.
# LS is a shortcut alias.
-line_separator = LS = u'\n'
+line_separator = LS = '\n'
# Settings to enable mwparserfromhell
# <https://mwparserfromhell.readthedocs.org/en/latest/>
@@ -910,7 +908,7 @@
panoramio = {
'review': False, # Do we use automatically make our uploads reviewed?
- 'reviewer': u'', # If so, under what reviewer name?
+ 'reviewer': '', # If so, under what reviewer name?
}
special_page_limit = 500
@@ -1156,9 +1154,9 @@
if set(editor) & set('\a\b\f\n\r\t\v'):
warning(
'The editor path contains probably invalid escaped '
- 'characters. Make sure to use a raw-string (r"..." or r\'...\'), '
- 'forward slashs as a path delimiter or to escape the normal '
- 'path delimiter.')
+ 'characters. Make sure to use a raw-string (r"..." or '
+ "r'...'), forward slashs as a path delimiter or to escape the "
+ 'normal path delimiter.')
if userinterface_lang is None:
userinterface_lang = os.getenv('PYWIKIBOT_USERINTERFACE_LANG') \
@@ -1196,11 +1194,11 @@
#
# When called as main program, list all configuration variables
#
-if __name__ == "__main__":
- _all = 1
+if __name__ == '__main__':
+ _all = True
for _arg in sys.argv[1:]:
- if _arg == "modified":
- _all = 0
+ if _arg == 'modified':
+ _all = False
else:
warning('Unknown arg {0} ignored'.format(_arg))
_k = list(globals().keys())
@@ -1215,8 +1213,8 @@
if isinstance(_value, dict):
_value = '{ ...xxxxxxxx... }'
elif hasattr(_value, '__dict__'):
- _value = '%s( ...xxxxxxxx... )' % \
- _value.__class__.__name__
+ _value = (_value.__class__.__name__
+ + '( ...xxxxxxxx... )')
else:
_value = repr('xxxxxxxx')
else:
@@ -1225,7 +1223,7 @@
# cleanup all locally-defined variables
for __var in list(globals().keys()):
- if __var.startswith("_") and not __var.startswith("__"):
+ if __var.startswith('_') and not __var.startswith('__'):
del sys.modules[__name__].__dict__[__var]
del __var
--
To view, visit https://gerrit.wikimedia.org/r/457375
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: I998a728dd9a82e8fd51247c8fd7921bb5fed33ce
Gerrit-Change-Number: 457375
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.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/457082 )
Change subject: Revert "Setup VCR for dry tests"
......................................................................
Revert "Setup VCR for dry tests"
This reverts commit 34ca29a419c96bc1855ca0fae28967f1c15efeff.
Bug: T198454
Bug: T184081
Bug: T196838
Change-Id: Ida8867830068c5e9df200849ea7dc7995d33fec0
---
M dev-requirements.txt
M tests/README.rst
M tests/api_tests.py
M tests/aspects.py
D tests/cassettes/wikidata.test/TestOwnClient.test_own_client_wikidatatest.yaml
D tests/cassettes/wikidata.wikidata/TestOwnClient.test_own_client_wikidata.yaml
D tests/cassettes/wikipedia.en/TestCachedRequest.test_normal_use.yaml
M tests/wikibase_tests.py
M tox.ini
9 files changed, 1 insertion(+), 2,018 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
--
To view, visit https://gerrit.wikimedia.org/r/457082
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: Ida8867830068c5e9df200849ea7dc7995d33fec0
Gerrit-Change-Number: 457082
Gerrit-PatchSet: 2
Gerrit-Owner: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444(a)gmail.com>
Gerrit-Reviewer: jenkins-bot (75)