jenkins-bot has submitted this change and it was merged.
Change subject: Upload: mandatory description required for upload
......................................................................
Upload: mandatory description required for upload
upload.py will continue to require a description until a non-empty
string is provided or the user quits.
Also fixed line length > 80.
Bug 60042 - Problem with uploading files
Change-Id: Ida45314a56e7a7db7eacc99b749c01d7730ef667
---
M scripts/upload.py
1 file changed, 41 insertions(+), 23 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
XZise: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/scripts/upload.py b/scripts/upload.py
index 39f9df5..5ab1607 100755
--- a/scripts/upload.py
+++ b/scripts/upload.py
@@ -45,9 +45,11 @@
import tempfile
import re
import math
+
import pywikibot
import pywikibot.data.api
from pywikibot import config
+from pywikibot.bot import QuitKeyboardInterrupt
class UploadRobot:
@@ -79,9 +81,7 @@
self.uploadByUrl = uploadByUrl
def urlOK(self):
- """Return true if self.url looks like an URL or an existing local
file.
-
- """
+ """Return True if self.url is an URL or an existing local
file."""
return "://" in self.url or os.path.exists(self.url)
def read_file_content(self):
@@ -102,7 +102,8 @@
infile = uo.open(self.url)
if 'text/html' in infile.info().getheader('Content-Type'):
- pywikibot.output(u"Couldn't download the image: the requested
URL was not found on server.")
+ pywikibot.output(u"Couldn't download the image: "
+ "the requested URL was not found on server.")
return
content_len = infile.info().getheader('Content-Length')
@@ -134,7 +135,7 @@
dt += 60
else:
pywikibot.log(
- u"WARNING: No check length to retrieved data is
possible.")
+ u"WARNING: length check of retrieved data not possible.")
handle, tempname = tempfile.mkstemp()
t = os.fdopen(handle, "wb")
t.write(_contents)
@@ -174,7 +175,8 @@
invalid = set(forbidden) & set(newfn)
if invalid:
c = "".join(invalid)
- pywikibot.output("Invalid character(s): %s. Please try
again" % c)
+ pywikibot.output(
+ 'Invalid character(s): %s. Please try again' % c)
continue
if ext not in allowed_formats:
choice = pywikibot.inputChoice(
@@ -187,20 +189,34 @@
if newfn != '':
filename = newfn
# A proper description for the submission.
- pywikibot.output(u"The suggested description is:")
- pywikibot.output(self.description)
- if self.verifyDescription:
- newDescription = u''
- choice = pywikibot.inputChoice(
- u'Do you want to change this description?',
- ['Yes', 'No'], ['y', 'N'], 'n')
- if choice == 'y':
- from pywikibot import editor as editarticle
- editor = editarticle.TextEditor()
- newDescription = editor.edit(self.description)
- # if user saved / didn't press Cancel
- if newDescription:
- self.description = newDescription
+ # Empty descriptions are not accepted.
+ pywikibot.output(u'The suggested description is:\n%s'
+ % self.description)
+
+ while not self.description or self.verifyDescription:
+ if not self.description:
+ pywikibot.output(
+ u'\03{lightred}It is not possible to upload a file '
+ 'without a summary/description.\03{default}')
+
+ if not self.description or self.verifyDescription:
+ newDescription = u''
+ # if no description, default is 'yes'
+ default = 'y' if not self.description else 'n'
+ choice = pywikibot.inputChoice(
+ u'Do you want to change this description?',
+ ['Yes', 'No', 'Quit'], ['y',
'n', 'q'], default)
+ if choice == 'y':
+ from pywikibot import editor as editarticle
+ editor = editarticle.TextEditor()
+ newDescription = editor.edit(self.description)
+ elif choice == 'q':
+ raise QuitKeyboardInterrupt
+ # if user saved / didn't press Cancel
+ if newDescription:
+ self.description = newDescription
+ break
+
return filename
def abort_on_warn(self, warn_code):
@@ -240,7 +256,8 @@
chunk_size=self.chunk_size)
except pywikibot.data.api.UploadWarning as warn:
- pywikibot.output(u"We got a warning message:
{0}".format(warn.message))
+ pywikibot.output(
+ u'We got a warning message: {0}'.format(warn.message))
if self.abort_on_warn(warn.code):
answer = "N"
else:
@@ -258,7 +275,7 @@
pywikibot.error("Upload error: ", exc_info=True)
else:
- #No warning, upload complete.
+ # No warning, upload complete.
pywikibot.output(u"Upload successful.")
return filename # data['filename']
@@ -280,7 +297,8 @@
verifyDescription = True
aborts = set()
chunk_size = 0
- chunk_size_regex = re.compile(r'^-chunked(?::(\d+(?:\.\d+)?)[
\t]*(k|ki|m|mi)?b?)?$', re.I)
+ chunk_size_regex = r'^-chunked(?::(\d+(?:\.\d+)?)[ \t]*(k|ki|m|mi)?b?)?$'
+ chunk_size_regex = re.compile(chunk_size_regex, re.I)
# process all global bot args
# returns a list of non-global args, i.e. args for upload.py
--
To view, visit
https://gerrit.wikimedia.org/r/157355
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ida45314a56e7a7db7eacc99b749c01d7730ef667
Gerrit-PatchSet: 5
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Mpaa <mpaa.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: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Nullzero <nullzero.free(a)gmail.com>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>