jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/348448 )
Change subject: upload.py + specialbots.py: Authorize the use of an edit summary
......................................................................
upload.py + specialbots.py: Authorize the use of an edit summary
Adds an option to enter a specific upload summary (edit summary for the upload action).
It uses the "comment" argument of site.upload() instead of using page.text.
I added a "summary" argument for UploadRobot of specialbots to do this.
Bug: T162527
Change-Id: Ifc3fc7cb853f81735d98e9fceef341f0df87d39e
---
M pywikibot/specialbots.py
M scripts/upload.py
2 files changed, 15 insertions(+), 5 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/pywikibot/specialbots.py b/pywikibot/specialbots.py
index 4694857..72e079c 100644
--- a/pywikibot/specialbots.py
+++ b/pywikibot/specialbots.py
@@ -43,7 +43,7 @@
useFilename=None, keepFilename=False,
verifyDescription=True, ignoreWarning=False,
targetSite=None, uploadByUrl=False, aborts=[], chunk_size=0,
- **kwargs):
+ summary=None, **kwargs):
"""
Constructor.
@@ -60,6 +60,8 @@
@param keepFilename: Set to True to keep original names of urls and
files, otherwise it will ask to enter a name for each file.
@type keepFilename: bool
+ @param summary: Summary of the upload
+ @type summary: string
@param verifyDescription: Set to False to not proofread the description.
@type verifyDescription: bool
@param ignoreWarning: Set this to True to upload even if another file
@@ -91,7 +93,7 @@
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 '
+ raise ValueError('When always is set to True, the description must '
'be set.')
self.url = url
if isinstance(self.url, basestring):
@@ -105,6 +107,7 @@
self.ignoreWarning = ignoreWarning
self.aborts = aborts
self.chunk_size = chunk_size
+ self.summary = summary
if config.upload_to_commons:
self.targetSite = targetSite or pywikibot.Site('commons',
'commons')
@@ -407,7 +410,8 @@
if self.uploadByUrl:
success = site.upload(imagepage, source_url=file_url,
ignore_warnings=apiIgnoreWarnings,
- _file_key=_file_key, _offset=_offset)
+ _file_key=_file_key, _offset=_offset,
+ comment=self.summary)
else:
if "://" in file_url:
temp = self.read_file_content(file_url)
@@ -416,7 +420,8 @@
success = site.upload(imagepage, source_filename=temp,
ignore_warnings=apiIgnoreWarnings,
chunk_size=self.chunk_size,
- _file_key=_file_key, _offset=_offset)
+ _file_key=_file_key, _offset=_offset,
+ comment=self.summary)
except pywikibot.data.api.APIError as error:
if error.code == u'uploaddisabled':
diff --git a/scripts/upload.py b/scripts/upload.py
index 0eee51d..2d306e4 100755
--- a/scripts/upload.py
+++ b/scripts/upload.py
@@ -29,6 +29,7 @@
the 'exists' warning.
-recursive When the filename is a directory it also uploads the files from
the subdirectories.
+ -summary Pick a custom edit summary for the bot.
It is possible to combine -abortonwarn and -ignorewarn so that if the specific
warning is given it won't apply the general one but more specific one. So if it
@@ -75,6 +76,7 @@
"""
url = u''
description = []
+ summary = None
keepFilename = False
always = False
useFilename = None
@@ -100,6 +102,8 @@
keepFilename = True
elif arg.startswith('-filename:'):
useFilename = arg[10:]
+ elif arg.startswith('-summary'):
+ summary = arg[9:]
elif arg.startswith('-noverify'):
verifyDescription = False
elif arg.startswith('-abortonwarn'):
@@ -184,7 +188,8 @@
keepFilename=keepFilename,
verifyDescription=verifyDescription,
aborts=aborts, ignoreWarning=ignorewarn,
- chunk_size=chunk_size, always=always)
+ chunk_size=chunk_size, always=always,
+ summary=summary)
bot.run()
if __name__ == "__main__":
--
To view, visit
https://gerrit.wikimedia.org/r/348448
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ifc3fc7cb853f81735d98e9fceef341f0df87d39e
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Gerrit Patch Uploader <gerritpatchuploader(a)gmail.com>
Gerrit-Reviewer: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: Gerrit Patch Uploader <gerritpatchuploader(a)gmail.com>
Gerrit-Reviewer: Magul <tomasz.magulski(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>