jenkins-bot has submitted this change and it was merged.
Change subject: upload.py: Allow to ignore warnings
......................................................................
upload.py: Allow to ignore warnings
Added the option -ignorewarn to ignore specific warnings, or all warnings,
using the same logic as the abortonwarn. Useful for batch uploads of files
to replace existing ones.
The UploadRobot already had a boolean ignoreWarning variable in
constructor, which has been extended to allow an array of warning
codes to ignore.
The message shown when a warning is found has been extended to display the
warning code, so the user can know what warning code use to ignore or
abort it.
Change-Id: Idf9e562f5a4fbae8184718c66cedc90042379e81
---
M scripts/upload.py
1 file changed, 34 insertions(+), 9 deletions(-)
Approvals:
XZise: Looks good to me, but someone else must approve
Mpaa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/upload.py b/scripts/upload.py
index 90cb164..ad3f776 100755
--- a/scripts/upload.py
+++ b/scripts/upload.py
@@ -10,7 +10,9 @@
-noverify Do not ask for verification of the upload description if one
is given
-abortonwarn: Abort upload on the specified warning type. If no warning type
- is specified abort on all warnings.
+ is specified, aborts on any warning.
+ -ignorewarn: Ignores specified upload warnings. If no warning type is
+ specified, ignores all warnings. Use with caution
-chunked: Upload the file in chunks (more overhead, but restartable). If
no value is specified the chunk size is 1 MiB. The value must
be a number which can be preceded by a suffix. The units are:
@@ -70,7 +72,8 @@
@param ignoreWarning: Set this to True if you want to upload even if
another file would be overwritten or another mistake would be
- risked.
+ risked. You can also set it to an array of warning codes to
+ selectively ignore specific warnings.
"""
self.url = url
@@ -233,6 +236,13 @@
else:
return warn_code in self.aborts
+ def ignore_on_warn(self, warn_code):
+ """Determine if the warning message should be ignored."""
+ if self.ignoreWarning is True:
+ return True
+ else:
+ return warn_code in self.ignoreWarning
+
def upload_image(self, debug=False):
"""Upload the image at self.url to the target wiki.
@@ -250,24 +260,32 @@
pywikibot.output(u'Uploading file to %s via API....' % site)
try:
+ apiIgnoreWarnings = False
+ if self.ignoreWarning is True:
+ apiIgnoreWarnings = True
if self.uploadByUrl:
site.upload(imagepage, source_url=self.url,
- ignore_warnings=self.ignoreWarning)
+ ignore_warnings=apiIgnoreWarnings)
else:
if "://" in self.url:
temp = self.read_file_content()
else:
temp = self.url
site.upload(imagepage, source_filename=temp,
- ignore_warnings=self.ignoreWarning,
+ ignore_warnings=apiIgnoreWarnings,
chunk_size=self.chunk_size)
except pywikibot.data.api.UploadWarning as warn:
pywikibot.output(
- u'We got a warning message: {0}'.format(warn.message))
- if (not self.abort_on_warn(warn.code) and
- pywikibot.input_yn(u"Do you want to ignore?",
- default=False, automatic_quit=False)):
+ u'We got a warning message: {0} - {1}'.format(warn.code,
warn.message))
+ if self.abort_on_warn(warn.code):
+ answer = False
+ elif self.ignore_on_warn(warn.code):
+ answer = True
+ else:
+ answer = pywikibot.input_yn(u"Do you want to ignore?",
+ default=False,
automatic_quit=False)
+ if answer:
self.ignoreWarning = True
self.keepFilename = True
return self.upload_image(debug)
@@ -328,6 +346,7 @@
useFilename = None
verifyDescription = True
aborts = set()
+ ignorewarn = set()
chunk_size = 0
chunk_size_regex = r'^-chunked(?::(\d+(?:\.\d+)?)[ \t]*(k|ki|m|mi)?b?)?$'
chunk_size_regex = re.compile(chunk_size_regex, re.I)
@@ -347,6 +366,11 @@
aborts.add(arg[len('-abortonwarn:'):])
else:
aborts = True
+ elif arg.startswith('-ignorewarn'):
+ if len(arg) > len('-ignorewarn:') and ignorewarn is not True:
+ ignorewarn.add(arg[len('-ignorewarn:'):])
+ else:
+ ignorewarn = True
elif arg.startswith('-chunked'):
match = chunk_size_regex.match(arg)
if match:
@@ -379,7 +403,8 @@
bot = UploadRobot(url, description=description, useFilename=useFilename,
keepFilename=keepFilename,
verifyDescription=verifyDescription,
- aborts=aborts, chunk_size=chunk_size)
+ aborts=aborts, ignoreWarning=ignorewarn,
+ chunk_size=chunk_size)
bot.run()
if __name__ == "__main__":
--
To view, visit https://gerrit.wikimedia.org/r/168826
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Idf9e562f5a4fbae8184718c66cedc90042379e81
Gerrit-PatchSet: 4
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Martineznovo <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Martineznovo <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: Mpaa <[email protected]>
Gerrit-Reviewer: XZise <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits