jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/351776 )
Change subject: [PEP8] keep line length below 80 chars
......................................................................
[PEP8] keep line length below 80 chars
Change-Id: I3eb06f004817f2202d04c60c84786a8981e11c16
---
M pywikibot/bot.py
1 file changed, 33 insertions(+), 27 deletions(-)
Approvals:
Dalba: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index edd32d1..861a02b 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -27,8 +27,8 @@
use C{treat_page} instead of C{treat} and C{put_current} instead of C{userPut}.
It by default subclasses the C{BaseBot} class.
-With L{CurrentPageBot} it's possible to subclass one of the following classes to
-filter the pages which are ultimately handled by C{treat_page}:
+With L{CurrentPageBot} it's possible to subclass one of the following classes
+to filter the pages which are ultimately handled by C{treat_page}:
* L{ExistingPageBot}: Only handle pages which do exist.
* L{CreatingPageBot}: Only handle pages which do not exist.
@@ -39,9 +39,9 @@
It is possible to combine filters by subclassing multiple of them. They are
new-style classes so when a class is first subclassing L{ExistingPageBot} and
-then L{FollowRedirectPageBot} it will also work on pages which do not exist when
-a redirect pointed to that. If the order is inversed it'll first follow them and
-then check whether they exist.
+then L{FollowRedirectPageBot} it will also work on pages which do not exist
+when a redirect pointed to that. If the order is inversed it'll first follow
+them and then check whether they exist.
Additionally there is the L{AutomaticTWSummaryBot} which subclasses
L{CurrentPageBot} and automatically defines the summary when C{put_current} is
@@ -120,7 +120,8 @@
'Choice', 'AlwaysChoice',
'QuitKeyboardInterrupt',
'InteractiveReplace',
- 'calledModuleName', 'handle_args', 'handleArgs', 'showHelp', 'suggest_help',
+ 'calledModuleName', 'handle_args', 'handleArgs',
+ 'showHelp', 'suggest_help',
'writeToCommandLogFile', 'open_webbrowser',
'OptionHandler',
'BaseBot', 'Bot', 'SingleSiteBot', 'MultipleSitesBot',
@@ -374,9 +375,10 @@
ver = version.get_module_version(module)
mtime = version.get_module_mtime(module)
if filename and ver and mtime:
- # it's explicitly using str() to bypass unicode_literals in Python 2
+ # it's explicitly using str() to bypass unicode_literals in py2
# isoformat expects a char not a unicode in Python 2
- log(u' {0} {1} {2}'.format(filename, ver[:7], mtime.isoformat(str(' '))))
+ log(u' {0} {1} {2}'.format(filename, ver[:7],
+ mtime.isoformat(str(' '))))
if config.log_pywiki_repo_version:
log(u'PYWIKI REPO VERSION: %s' % version.getversion_onlinerepo())
@@ -495,8 +497,8 @@
@param answers: a list of strings that represent the options.
@type answers: list of basestring
@param hotkeys: a list of one-letter strings, one for each answer.
- @param default: an element of hotkeys, or None. The default choice that will
- be returned when the user just presses Enter.
+ @param default: an element of hotkeys, or None. The default choice that
+ will be returned when the user just presses Enter.
@return: a one-letter string in lowercase.
@rtype: str
"""
@@ -598,7 +600,8 @@
if self.replacer.current_link.anchor is None:
kwargs['label'] = self.replacer.current_groups['title']
if self.replacer.current_groups['section']:
- kwargs['label'] += '#' + self.replacer.current_groups['section']
+ kwargs['label'] += '#' + \
+ self.replacer.current_groups['section']
else:
kwargs['label'] = self.replacer.current_link.anchor
return pywikibot.Link.create_separated(
@@ -650,9 +653,9 @@
option to increase C{context} by the given amount each time the option is
selected.
- Additional choices can be defined using the 'additional_choices' and will be
- amended to the choices defined by this class. This list is mutable and the
- Choice instance returned and created by this class are too.
+ Additional choices can be defined using the 'additional_choices' and will
+ be amended to the choices defined by this class. This list is mutable and
+ the Choice instance returned and created by this class are too.
"""
def __init__(self, old_link, new_link, default=None, automatic_quit=True):
@@ -664,8 +667,8 @@
@type old_link: Link or Page
@param new_link: The new link with which it should be replaced.
Depending on the replacement mode it'll use this link's label and
- section. If False it'll unlink all and the attributes beginning with
- allow_replace are ignored.
+ section. If False it'll unlink all and the attributes beginning
+ with allow_replace are ignored.
@type new_link: Link or Page or False
@param default: The default answer as the shortcut
@type default: None or str
@@ -701,8 +704,8 @@
self._own_choices += [
('replace', LinkChoice('Change link target', 't', self,
False, False)),
- ('replace_section', LinkChoice('Change link target and section',
- 's', self, True, False)),
+ ('replace_section', LinkChoice(
+ 'Change link target and section', 's', self, True, False)),
('replace_label', LinkChoice('Change link target and label',
'l', self, False, True)),
('replace_all', LinkChoice('Change complete link', 'c', self,
@@ -858,8 +861,8 @@
# not the one in pywikibot.bot.
args = pywikibot.argvu[1:]
# get the name of the module calling this function. This is
- # required because the -help option loads the module's docstring and because
- # the module name will be used for the filename of the log.
+ # required because the -help option loads the module's docstring and
+ # because the module name will be used for the filename of the log.
moduleName = calledModuleName()
if not moduleName:
moduleName = "terminal-interface"
@@ -1104,7 +1107,7 @@
def writeToCommandLogFile():
"""
- Save name of the called module along with all parameters to logs/commands.log.
+ Save name of the called module along with all params to logs/commands.log.
This can be used by user later to track errors or report bugs.
"""
@@ -1563,8 +1566,8 @@
"""
A bot only working on one site and ignoring the others.
- If no site is given from the start it'll use the first page's site. Any page
- after the site has been defined and is not on the defined site will be
+ If no site is given from the start it'll use the first page's site. Any
+ page after the site has been defined and is not on the defined site will be
ignored.
"""
@@ -1727,9 +1730,11 @@
if not kwargs.get('summary'):
if self.summary_key is None:
raise ValueError('The summary_key must be set.')
- summary = i18n.twtranslate(self.current_page.site, self.summary_key,
+ summary = i18n.twtranslate(self.current_page.site,
+ self.summary_key,
self.summary_parameters)
- pywikibot.log('Use automatic summary message "{0}"'.format(summary))
+ pywikibot.log(
+ 'Use automatic summary message "{0}"'.format(summary))
kwargs['summary'] = summary
super(AutomaticTWSummaryBot, self).put_current(*args, **kwargs)
@@ -1855,8 +1860,9 @@
self.source_values = json.loads(page.get())
for family_code, family in self.source_values.items():
for source_lang in family:
- self.source_values[family_code][source_lang] = pywikibot.ItemPage(
- self.repo, family[source_lang])
+ self.source_values[
+ family_code][source_lang] = pywikibot.ItemPage(
+ self.repo, family[source_lang])
def get_property_by_name(self, property_name):
"""
--
To view, visit https://gerrit.wikimedia.org/r/351776
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3eb06f004817f2202d04c60c84786a8981e11c16
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
Build Update for wikimedia/pywikibot-core
-------------------------------------
Build: #4040
Status: Passed
Duration: 2 hours, 18 minutes, and 44 seconds
Commit: a8aa142 (master)
Author: dalba
Message: weblinkchecker.py: Retry get_memento_info if there is a ConnectionError
`get_memento_info` sometimes fails to connect to the server. Retrying
should mitigate the issue.
Skip the related test on ConnectionError. `max_retries` is reduced to 1 during
tests and thus the test might still fail.
Bug: T164365
Change-Id: I0db18b7a3e5fa67de4132f73c58a15b76725edc3
View the changeset: https://github.com/wikimedia/pywikibot-core/compare/b06357485f41...a8aa1423…
View the full build log and details: https://travis-ci.org/wikimedia/pywikibot-core/builds/228621403?utm_source=…
--
You can configure recipients for build notifications in your .travis.yml file. See https://docs.travis-ci.com/user/notifications
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/351773 )
Change subject: [PEP8] Keep line length below 80 chars
......................................................................
[PEP8] Keep line length below 80 chars
Change-Id: I5dafc68ec0bb81ea82b856eb4cd0a01bb12d8aea
---
M pywikibot/specialbots.py
1 file changed, 18 insertions(+), 16 deletions(-)
Approvals:
Dalba: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/specialbots.py b/pywikibot/specialbots.py
index b778dfb..68b8f70 100644
--- a/pywikibot/specialbots.py
+++ b/pywikibot/specialbots.py
@@ -63,7 +63,7 @@
@type keepFilename: bool
@param summary: Summary of the upload
@type summary: string
- @param verifyDescription: Set to False to not proofread the description.
+ @param verifyDescription: Set to True to proofread the description.
@type verifyDescription: bool
@param ignoreWarning: Set this to True to upload even if another file
would be overwritten or another mistake would be risked. Set it to
@@ -72,16 +72,16 @@
@param targetSite: Set the site to upload to. If target site is not
given it's taken from user-config.py.
@type targetSite: object
- @param aborts: List of the warning types to abort upload on. Set to True
- to abort on any warning.
+ @param aborts: List of the warning types to abort upload on. Set to
+ True to abort on any warning.
@type aborts: bool or list
@param chunk_size: Upload the file in chunks (more overhead, but
restartable) specified in bytes. If no value is specified the file
will be uploaded as whole.
@type chunk_size: integer
- @param always: Disables any input, requires that either ignoreWarning or
- aborts are set to True and that the description is also set. It will
- overwrite verifyDescription to False and keepFilename to True.
+ @param always: Disables any input, requires that either ignoreWarning
+ or aborts are set to True and that the description is also set. It
+ overwrites verifyDescription to False and keepFilename to True.
@type always: bool
@deprecated: Using upload_image() is deprecated, use upload_file() with
@@ -91,11 +91,11 @@
super(UploadRobot, self).__init__(**kwargs)
always = self.getOption('always')
if (always and ignoreWarning is not True and aborts is not True):
- raise ValueError('When always is set to True, either ignoreWarning '
- 'or aborts must be set to True.')
+ raise ValueError('When always is set to True, either '
+ 'ignoreWarning or aborts must be set to True.')
if always and not description:
- raise ValueError('When always is set to True, the description must '
- 'be set.')
+ raise ValueError('When always is set to True, the description '
+ 'must be set.')
self.url = url
if isinstance(self.url, basestring):
pywikibot.warning("url as string is deprecated. "
@@ -300,7 +300,8 @@
if potential_file_page.exists():
overwrite = self._handle_warning('exists')
if overwrite is False:
- pywikibot.output("File exists and you asked to abort. Skipping.")
+ pywikibot.output(
+ 'File exists and you asked to abort. Skipping.')
return None
if potential_file_page.canBeEdited():
if overwrite is None:
@@ -321,9 +322,9 @@
else:
try:
if potential_file_page.fileIsShared():
- pywikibot.output(u"File with name %s already exists in shared "
- "repository and cannot be overwritten."
- % filename)
+ pywikibot.output(
+ 'File with name %s already exists in shared '
+ 'repository and cannot be overwritten.' % filename)
continue
else:
break
@@ -422,8 +423,9 @@
comment=self.summary)
except pywikibot.data.api.APIError as error:
if error.code == u'uploaddisabled':
- pywikibot.error("Upload error: Local file uploads are disabled on %s."
- % site)
+ pywikibot.error(
+ 'Upload error: Local file uploads are disabled on %s.'
+ % site)
else:
pywikibot.error("Upload error: ", exc_info=True)
return None
--
To view, visit https://gerrit.wikimedia.org/r/351773
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I5dafc68ec0bb81ea82b856eb4cd0a01bb12d8aea
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Magul <tomasz.magulski(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/324144 )
Change subject: [IMPR] Use FilePage.upload inside UploadRobot
......................................................................
[IMPR] Use FilePage.upload inside UploadRobot
- use the new FilePage.upload method to upload a file
- move setting out of the try block
- uploadByUrl was never used by any bot script. Replace its behavior
by checking upload rights. Use read_file_content only if has no
'upload_by_url' right; the file from url is cached locally then.
Otherwise upload the file by url directly.
- deprecate unused debug parameter for upload_file and upload_image
- None is returned from that method in some cases which means null
- return upload_file's result in upload_image which was the previous behavior
- omit compat style "via API" message part
Change-Id: I1346ec6f90f1ff405afd0f9097659583dde52752
---
M pywikibot/specialbots.py
1 file changed, 20 insertions(+), 29 deletions(-)
Approvals:
Dalba: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/specialbots.py b/pywikibot/specialbots.py
index 317c4da..b778dfb 100644
--- a/pywikibot/specialbots.py
+++ b/pywikibot/specialbots.py
@@ -22,7 +22,7 @@
from pywikibot import config
from pywikibot.bot import BaseBot, QuitKeyboardInterrupt
-from pywikibot.tools import PY2, deprecated
+from pywikibot.tools import PY2, deprecated, deprecated_args
from pywikibot.tools.formatter import color_format
if not PY2:
@@ -39,10 +39,11 @@
"""Upload bot."""
+ @deprecated_args(uploadByUrl=None)
def __init__(self, url, urlEncoding=None, description=u'',
useFilename=None, keepFilename=False,
verifyDescription=True, ignoreWarning=False,
- targetSite=None, uploadByUrl=False, aborts=[], chunk_size=0,
+ targetSite=None, aborts=[], chunk_size=0,
summary=None, **kwargs):
"""
Constructor.
@@ -114,7 +115,6 @@
else:
self.targetSite = targetSite or pywikibot.Site()
self.targetSite.login()
- self.uploadByUrl = uploadByUrl
@deprecated()
def urlOK(self):
@@ -385,17 +385,18 @@
return warn_code in self.ignoreWarning
@deprecated('UploadRobot.upload_file()')
- def upload_image(self, debug=False):
+ @deprecated_args(debug=None)
+ def upload_image(self):
"""Upload image."""
- self.upload_file(self.url, debug)
+ return self.upload_file(self.url)
- def upload_file(self, file_url, debug=False, _file_key=None, _offset=0):
+ @deprecated_args(debug=None)
+ def upload_file(self, file_url, _file_key=None, _offset=0):
"""Upload the image at file_url to the target wiki.
Return the filename that was used to upload the image.
If the upload fails, ask the user whether to try again or not.
- If the user chooses not to retry, return null.
-
+ If the user chooses not to retry, return None.
"""
filename = self.process_filename(file_url)
if not filename:
@@ -405,30 +406,20 @@
imagepage = pywikibot.FilePage(site, filename) # normalizes filename
imagepage.text = self.description
- pywikibot.output(u'Uploading file to %s via API...' % site)
+ pywikibot.output('Uploading file to {0}...'.format(site))
success = False
- try:
- if self.ignoreWarning is True:
- apiIgnoreWarnings = True
- else:
- apiIgnoreWarnings = self._handle_warnings
- if self.uploadByUrl:
- success = site.upload(imagepage, source_url=file_url,
- ignore_warnings=apiIgnoreWarnings,
- _file_key=_file_key, _offset=_offset,
- comment=self.summary)
- else:
- if "://" in file_url:
- temp = self.read_file_content(file_url)
- else:
- temp = file_url
- success = site.upload(imagepage, source_filename=temp,
- ignore_warnings=apiIgnoreWarnings,
- chunk_size=self.chunk_size,
- _file_key=_file_key, _offset=_offset,
- comment=self.summary)
+ ignore_warnings = self.ignoreWarning is True or self._handle_warnings
+ if ('://' in file_url and
+ 'upload_by_url' not in site.userinfo['rights']):
+ file_url = self.read_file_content(file_url)
+ try:
+ success = imagepage.upload(file_url,
+ ignore_warnings=ignore_warnings,
+ chunk_size=self.chunk_size,
+ _file_key=_file_key, _offset=_offset,
+ comment=self.summary)
except pywikibot.data.api.APIError as error:
if error.code == u'uploaddisabled':
pywikibot.error("Upload error: Local file uploads are disabled on %s."
--
To view, visit https://gerrit.wikimedia.org/r/324144
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I1346ec6f90f1ff405afd0f9097659583dde52752
Gerrit-PatchSet: 9
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
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: Lokal Profil <lokal.profil(a)gmail.com>
Gerrit-Reviewer: Magul <tomasz.magulski(a)gmail.com>
Gerrit-Reviewer: Multichill <maarten(a)mdammers.nl>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/350846 )
Change subject: [doc] use epydoc for parameter description
......................................................................
[doc] use epydoc for parameter description
Change-Id: Iabf811a277ec41274353b7957e3eb127792a65a8
---
M scripts/claimit.py
M scripts/harvest_template.py
M scripts/replace.py
M scripts/template.py
4 files changed, 28 insertions(+), 23 deletions(-)
Approvals:
Dalba: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/claimit.py b/scripts/claimit.py
index 19142df..bf1edc3 100755
--- a/scripts/claimit.py
+++ b/scripts/claimit.py
@@ -77,11 +77,12 @@
"""
Constructor.
- Arguments:
- * generator - A generator that yields Page objects.
- * claims - A list of wikidata claims
- * exists_arg - String specifying how to handle duplicate claims
-
+ @param generator: A generator that yields Page objects.
+ @type generator: iterator
+ @param claims: A list of wikidata claims
+ @type claims: list
+ @param exists_arg: String specifying how to handle duplicate claims
+ @type exists_arg: str
"""
self.availableOptions['always'] = True
super(ClaimRobot, self).__init__(use_from_page=None)
diff --git a/scripts/harvest_template.py b/scripts/harvest_template.py
index 309705e..dfe413d 100755
--- a/scripts/harvest_template.py
+++ b/scripts/harvest_template.py
@@ -65,11 +65,12 @@
"""
Constructor.
- Arguments:
- * generator - A generator that yields Page objects.
- * templateTitle - The template to work on
- * fields - A dictionary of fields that are of use to us
-
+ @param generator: A generator that yields Page objects
+ @type generator: iterator
+ @param templateTitle: The template to work on
+ @type templateTitle: str
+ @param fields: A dictionary of fields that are of use to us
+ @type fields: dict
"""
self.availableOptions['always'] = True
super(HarvestRobot, self).__init__()
diff --git a/scripts/replace.py b/scripts/replace.py
index f235c95..1328baa 100755
--- a/scripts/replace.py
+++ b/scripts/replace.py
@@ -403,15 +403,17 @@
Iterator that will yield Pages that might contain text to replace.
These pages will be retrieved from a local XML dump file.
- Arguments:
- * xmlFilename - The dump's path, either absolute or relative
- * xmlStart - Skip all articles in the dump before this one
- * replacements - A list of 2-tuples of original text (as a
- compiled regular expression) and replacement
- text (as a string).
- * exceptions - A dictionary which defines when to ignore an
- occurrence. See docu of the ReplaceRobot
- constructor below.
+
+ @param xmlFilename: The dump's path, either absolute or relative
+ @type xmlFilename: str
+ @param xmlStart: Skip all articles in the dump before this one
+ @type xmlStart: str
+ @param replacements: A list of 2-tuples of original text (as a
+ compiled regular expression) and replacement text (as a string).
+ @type replacements: list of 2-tuples
+ @param exceptions: A dictionary which defines when to ignore an
+ occurrence. See docu of the ReplaceRobot constructor below.
+ @type exceptions: dict
"""
def __init__(self, xmlFilename, xmlStart, replacements, exceptions, site):
diff --git a/scripts/template.py b/scripts/template.py
index b4bd2aa..76df5ac 100755
--- a/scripts/template.py
+++ b/scripts/template.py
@@ -144,10 +144,11 @@
"""
Constructor.
- Arguments:
- * templateNames - A list of Page object representing the searched
- templates
- * xmlfilename - The dump's path, either absolute or relative
+ @param templateNames: A list of Page objects representing the searched
+ templates
+ @type templateNames: list
+ @param xmlfilename: The dump's path, either absolute or relative
+ @type xmlfilename: str
"""
self.templates = templates
--
To view, visit https://gerrit.wikimedia.org/r/350846
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iabf811a277ec41274353b7957e3eb127792a65a8
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Magul <tomasz.magulski(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>