jenkins-bot has submitted this change and it was merged.
Change subject: new Bot.current_page property to set and log the working page
......................................................................
new Bot.current_page property to set and log the working page
Nearly every script that 'treats' a page used to print its title
on the screen, sometimes in purple, sometimes prepended with
"Processing..." or "Working on...".
Now the setter uses the standard output for the colorized message
and the logging.VERBOSE level for the %r-formatted string,
improving consistency and semantic value of the console output.
This property also allows to get the current working page
at any time, and to avoid printing the same title twice.
Change-Id: I886c48c7bf7b66917be814df3833f70caa22bd4a
---
M pywikibot/bot.py
M scripts/capitalize_redirects.py
M scripts/claimit.py
M scripts/commons_link.py
M scripts/commonscat.py
M scripts/coordinate_import.py
M scripts/cosmetic_changes.py
M scripts/delete.py
M scripts/harvest_template.py
M scripts/illustrate_wikidata.py
M scripts/movepages.py
M scripts/newitem.py
M scripts/noreferences.py
M scripts/nowcommons.py
M scripts/pagefromfile.py
M scripts/protect.py
M scripts/selflink.py
M scripts/solve_disambiguation.py
M scripts/unlink.py
19 files changed, 48 insertions(+), 48 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 53e3733..b332099 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -796,6 +796,8 @@
'always': False, # ask for confirmation when putting a page?
}
+ _current_page = None
+
def __init__(self, **kwargs):
"""
Only accept options defined in availableOptions.
@@ -836,6 +838,33 @@
except KeyError:
raise pywikibot.Error(u'%s is not a valid bot option.' % option)
+ @property
+ def current_page(self):
+ return self._current_page
+
+ @current_page.setter
+ def current_page(self, page):
+ """Set the current working page as a property.
+
+ When the value is actually changed, the page title is printed
+ to the standard output (highlighted in purple) and logged
+ with a VERBOSE level.
+
+ This also prevents the same title from being printed twice.
+
+ @param page: the working page
+ @type page: pywikibot.Page
+ """
+ if page != self._current_page:
+ self._current_page = page
+ msg = u'Working on %r' % page
+ if config.colorized_output:
+ log(msg)
+ stdout(u'\n\n>>> \03{lightpurple}%s\03{default} <<<'
+ % page.title())
+ else:
+ stdout(msg)
+
def user_confirm(self, question):
""" Obtain user response if bot option 'always' not enabled. """
if self.getOption('always'):
@@ -871,8 +900,7 @@
% page.title(asLink=True))
return
- pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
- % page.title())
+ self.current_page = page
pywikibot.showDiff(oldtext, newtext)
if 'comment' in kwargs:
pywikibot.output(u'Comment: %s' % kwargs['comment'])
diff --git a/scripts/capitalize_redirects.py b/scripts/capitalize_redirects.py
index 4db3e40..0c4c7a9 100644
--- a/scripts/capitalize_redirects.py
+++ b/scripts/capitalize_redirects.py
@@ -54,10 +54,7 @@
if page.isRedirectPage():
page = page.getRedirectTarget()
page_t = page.title()
- # Show the title of the page we're working on.
- # Highlight the title in purple.
- pywikibot.output(u"\n>>> \03{lightpurple}%s\03{default} <<<"
- % page_t)
+ self.current_page = page
if self.getOption('titlecase'):
page_cap = pywikibot.Page(page.site, page_t.title())
else:
diff --git a/scripts/claimit.py b/scripts/claimit.py
index 443f628..39fcf11 100755
--- a/scripts/claimit.py
+++ b/scripts/claimit.py
@@ -90,7 +90,7 @@
if self.exists_arg:
pywikibot.output('\'exists\' argument set to \'%s\'' % self.exists_arg)
for page in self.generator:
- pywikibot.output('Processing %s' % page)
+ self.current_page = page
item = pywikibot.ItemPage.fromPage(page)
if not item.exists():
# TODO FIXME: We should provide an option to create the page
diff --git a/scripts/commons_link.py b/scripts/commons_link.py
index 79b4580..45887c0 100644
--- a/scripts/commons_link.py
+++ b/scripts/commons_link.py
@@ -60,7 +60,7 @@
catmode = (self.getOption('action') == 'categories')
for page in self.generator:
try:
- pywikibot.output(u'\n>>>> %s <<<<' % page.title())
+ self.current_page = page
commons = page.site.image_repository()
commonspage = getattr(pywikibot,
('Page', 'Category')[catmode]
diff --git a/scripts/commonscat.py b/scripts/commonscat.py
index 48f9591..5029830 100755
--- a/scripts/commonscat.py
+++ b/scripts/commonscat.py
@@ -293,7 +293,7 @@
category is found add it to the page.
"""
- pywikibot.output(u'Working on ' + page.title())
+ self.current_page = page
# Get the right templates for this page
primaryCommonscat, commonscatAlternatives = self.getCommonscatTemplate(
page.site.code)
diff --git a/scripts/coordinate_import.py b/scripts/coordinate_import.py
index 1998cf8..322db55 100644
--- a/scripts/coordinate_import.py
+++ b/scripts/coordinate_import.py
@@ -63,7 +63,7 @@
def run(self):
"""Start the robot."""
for page in self.generator:
- pywikibot.output(u'Working on %s' % page.title())
+ self.current_page = page
item = pywikibot.ItemPage.fromPage(page)
if item.exists():
diff --git a/scripts/cosmetic_changes.py b/scripts/cosmetic_changes.py
index b6ba0e1..9e87462 100755
--- a/scripts/cosmetic_changes.py
+++ b/scripts/cosmetic_changes.py
@@ -845,10 +845,7 @@
def treat(self, page):
try:
- # Show the title of the page we're working on.
- # Highlight the title in purple.
- pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
- % page.title())
+ self.current_page = page
ccToolkit = CosmeticChangesToolkit(page.site, debug=True,
namespace=page.namespace(),
pageTitle=page.title())
diff --git a/scripts/delete.py b/scripts/delete.py
index 3211852..2efe8e0 100644
--- a/scripts/delete.py
+++ b/scripts/delete.py
@@ -68,7 +68,7 @@
"""
for page in self.generator:
- pywikibot.output(u'Processing page %s' % page.title())
+ self.current_page = page
if self.getOption('undelete'):
page.undelete(self.summary)
else:
diff --git a/scripts/harvest_template.py b/scripts/harvest_template.py
index fd61850..d26245b 100755
--- a/scripts/harvest_template.py
+++ b/scripts/harvest_template.py
@@ -109,7 +109,7 @@
def processPage(self, page):
"""Process a single page."""
item = pywikibot.ItemPage.fromPage(page)
- pywikibot.output('Processing %s' % page)
+ self.current_page = page
if not item.exists():
pywikibot.output('%s doesn\'t have a wikidata item :(' % page)
#TODO FIXME: We should provide an option to create the page
diff --git a/scripts/illustrate_wikidata.py b/scripts/illustrate_wikidata.py
index a1b25f9..21b1a36 100644
--- a/scripts/illustrate_wikidata.py
+++ b/scripts/illustrate_wikidata.py
@@ -50,7 +50,7 @@
def run(self):
"""Starts the bot."""
for page in self.generator:
- pywikibot.output(u'Working on %s' % page.title())
+ self.current_page = page
item = pywikibot.ItemPage.fromPage(page)
if item.exists():
diff --git a/scripts/movepages.py b/scripts/movepages.py
index 618ac26..3cdc360 100644
--- a/scripts/movepages.py
+++ b/scripts/movepages.py
@@ -89,10 +89,7 @@
pywikibot.output(e.message)
def treat(self, page):
- # Show the title of the page we're working on.
- # Highlight the title in purple.
- pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
- % page.title())
+ self.current_page = page
if self.getOption('skipredirects') and page.isRedirectPage():
pywikibot.output(u'Page %s is a redirect; skipping.' % page.title())
return
diff --git a/scripts/newitem.py b/scripts/newitem.py
index 7169de4..99e83dd 100644
--- a/scripts/newitem.py
+++ b/scripts/newitem.py
@@ -60,7 +60,7 @@
% (self.lastEdit, self.lastEditBefore.isoformat()))
for page in self.generator:
- pywikibot.output('Processing %s' % page)
+ self.current_page = page
if not page.exists():
pywikibot.output(u'%s does not exist anymore. Skipping...'
% page)
diff --git a/scripts/noreferences.py b/scripts/noreferences.py
index dde9bfd..8fece93 100755
--- a/scripts/noreferences.py
+++ b/scripts/noreferences.py
@@ -610,10 +610,7 @@
def run(self):
for page in self.generator:
- # Show the title of the page we're working on.
- # Highlight the title in purple.
- pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
- % page.title())
+ self.current_page = page
try:
text = page.text
except pywikibot.NoPage:
diff --git a/scripts/nowcommons.py b/scripts/nowcommons.py
index 4e5338f..ef6d436 100644
--- a/scripts/nowcommons.py
+++ b/scripts/nowcommons.py
@@ -315,10 +315,7 @@
page = pywikibot.Page(self.site, images_list[0])
else:
# If use_hash is true, we have already print this before, no need
- # Show the title of the page we're working on.
- # Highlight the title in purple.
- pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
- % page.title())
+ self.current_page = page
try:
localImagePage = pywikibot.FilePage(self.site, page.title())
if localImagePage.fileIsShared():
diff --git a/scripts/pagefromfile.py b/scripts/pagefromfile.py
index 7c2f482..7b204c2 100644
--- a/scripts/pagefromfile.py
+++ b/scripts/pagefromfile.py
@@ -94,10 +94,7 @@
mysite = pywikibot.Site()
page = pywikibot.Page(mysite, title)
- # Show the title of the page we're working on.
- # Highlight the title in purple.
- pywikibot.output(u">>> \03{lightpurple}%s\03{default} <<<"
- % page.title())
+ self.current_page = page
if self.getOption('summary'):
comment = self.getOption('summary')
diff --git a/scripts/protect.py b/scripts/protect.py
index f3f4fc5..7a20ed1 100644
--- a/scripts/protect.py
+++ b/scripts/protect.py
@@ -89,7 +89,7 @@
protections.
"""
for page in self.generator:
- pywikibot.output(u'Processing page %s' % page.title())
+ self.current_page = page
if not self.getOption('always'):
choice = pywikibot.inputChoice(
u'Do you want to change the protection level of %s?'
diff --git a/scripts/selflink.py b/scripts/selflink.py
index ee436bc..8ce58e2 100644
--- a/scripts/selflink.py
+++ b/scripts/selflink.py
@@ -138,10 +138,7 @@
return False
def treat(self, page):
- # Show the title of the page we're working on.
- # Highlight the title in purple.
- pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
- % page.title())
+ self.current_page = page
try:
oldText = page.text
# Inside image maps, don't touch selflinks, as they're used
diff --git a/scripts/solve_disambiguation.py b/scripts/solve_disambiguation.py
index a10c069..c6d86a2 100644
--- a/scripts/solve_disambiguation.py
+++ b/scripts/solve_disambiguation.py
@@ -637,11 +637,7 @@
# This loop will run while the user doesn't choose an option
# that will actually change the page
while True:
- # Show the title of the page where the link was found.
- # Highlight the title in purple.
- pywikibot.output(
- u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
- % refPage.title())
+ self.current_page = refPage
if not self.always:
# at the beginning of the link, start red color.
diff --git a/scripts/unlink.py b/scripts/unlink.py
index 862cd36..b9525ce 100755
--- a/scripts/unlink.py
+++ b/scripts/unlink.py
@@ -133,10 +133,7 @@
return text[:match.start()] + new + text[match.end():], False
def treat(self, page):
- # Show the title of the page we're working on.
- # Highlight the title in purple.
- pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
- % page.title())
+ self.current_page = page
try:
oldText = page.get()
text = oldText
--
To view, visit https://gerrit.wikimedia.org/r/151822
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I886c48c7bf7b66917be814df3833f70caa22bd4a
Gerrit-PatchSet: 11
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: Russell Blau <russblau(a)imapmail.org>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Remove unnecessary return in Siteinfo._get_general
......................................................................
Remove unnecessary return in Siteinfo._get_general
Siteinfo._get_general has a return at the end of the 'force'
branch, which is not necessary as the next lines repeat the same
logic in a more generic way. Removing this return simplifies the
flow of the method.
Change-Id: I87dceaa8ed4d4339f54bc63ad00b22bf820c2f6a
---
M pywikibot/site.py
1 file changed, 0 insertions(+), 2 deletions(-)
Approvals:
Mpaa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 13da02c..bc9ce9f 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -1046,8 +1046,6 @@
default_info = self._get_siteinfo(props, expiry)
for prop in props:
self._cache[prop] = default_info[prop]
- if key in default_info:
- return default_info[key]
if key in self._cache['general'][0]:
return self._cache['general'][0][key], self._cache['general']
else:
--
To view, visit https://gerrit.wikimedia.org/r/157991
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I87dceaa8ed4d4339f54bc63ad00b22bf820c2f6a
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: 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: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Split getversion_svn into two utility functions
......................................................................
Split getversion_svn into two utility functions
Change-Id: Ifde44b119a5429b81a9eb7643c1c94dbfdbeaa09
---
M pywikibot/version.py
1 file changed, 44 insertions(+), 4 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/pywikibot/version.py b/pywikibot/version.py
index 8826a4d..1c77acb 100644
--- a/pywikibot/version.py
+++ b/pywikibot/version.py
@@ -87,10 +87,21 @@
return cache
-def getversion_svn(path=None):
- import httplib
- import xml.dom.minidom
- _program_dir = path or _get_program_dir()
+def svn_rev_info(path):
+ """Fetch information about the current revision of an Subversion checkout.
+
+ Returns three strings:
+ * 'tag': name for the repository
+ * 'rev': current Subversion revision identifier
+ * 'date': date of current revision
+
+ @param path: directory of the Subversion checkout
+ @return: tag (name for the repository),
+ rev (current Subversion revision identifier),
+ date (date of current revision)
+ @return: C{tuple} of 3 C{str}
+ """
+ _program_dir = path
entries = open(os.path.join(_program_dir, '.svn/entries'))
version = entries.readline().strip()
# use sqlite table for new entries format
@@ -120,6 +131,19 @@
date = time.strptime(entries.readline()[:19], '%Y-%m-%dT%H:%M:%S')
rev = entries.readline()[:-1]
entries.close()
+ return tag, rev, date
+
+
+def github_svn_rev2hash(tag, rev):
+ """Convert a Subversion revision to a Git hash using Github.
+
+ @param tag: name of the Subversion repo on Github
+ @param rev: Subversion revision identifier
+ @return: the git hash
+ @rtype: str
+ """
+ import httplib
+ import xml.dom.minidom
conn = httplib.HTTPSConnection('github.com')
conn.request('PROPFIND', '/wikimedia/%s/!svn/vcc/default' % tag,
"<?xml version='1.0' encoding='utf-8'?>"
@@ -128,6 +152,22 @@
resp = conn.getresponse()
dom = xml.dom.minidom.parse(resp)
hsh = dom.getElementsByTagName("C:git-commit")[0].firstChild.nodeValue
+ return hsh
+
+
+def getversion_svn(path=None):
+ """Get version info for a Subversion checkout.
+
+ @param path: directory of the Subversion checkout
+ @return: tag (name for the repository),
+ rev (current Subversion revision identifier),
+ date (date of current revision),
+ hash (git hash for the Subversion revision)
+ @return: C{tuple} of 4 C{str}
+ """
+ _program_dir = path or _get_program_dir()
+ tag, rev, date = svn_rev_info(_program_dir)
+ hsh = github_svn_rev2hash(tag, rev)
rev = 's%s' % rev
if (not date or not tag or not rev) and not path:
raise ParseError
--
To view, visit https://gerrit.wikimedia.org/r/152184
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ifde44b119a5429b81a9eb7643c1c94dbfdbeaa09
Gerrit-PatchSet: 4
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(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: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: WikidataBot as subclass of Bot
......................................................................
WikidataBot as subclass of Bot
to take advantage of new methods such as quit(), etc.
The 'always' option is not used by Wikidata bots currently,
but has been retained for future usage.
Change-Id: Icecd762cd44092129106800ac93e772dde3913ef
---
M pywikibot/bot.py
1 file changed, 1 insertion(+), 3 deletions(-)
Approvals:
John Vandenberg: Looks good to me, but someone else must approve
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index d0a20f9..e42b71c 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -914,12 +914,10 @@
self.__class__.__name__)
-class WikidataBot:
+class WikidataBot(Bot):
"""
Generic Wikidata Bot to be subclassed.
-
- Used in claimit.py, coordinate_import.py and harvest_template.py
"""
def cacheSources(self):
--
To view, visit https://gerrit.wikimedia.org/r/157793
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Icecd762cd44092129106800ac93e772dde3913ef
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <ricordisamoa(a)openmailbox.org>
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: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: fixup I84cdc5dcb8626d2cc1d18f963a8d6fdf4c99da6a
......................................................................
fixup I84cdc5dcb8626d2cc1d18f963a8d6fdf4c99da6a
using self.getOption('always') instead of self.options['always']
Change-Id: Ie27946d546425b048cadea8a6ce0bd07b891bc91
---
M pywikibot/bot.py
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
Ladsgroup: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index d0a20f9..3f97014 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -880,7 +880,7 @@
if not self.user_confirm('Do you want to accept these changes?'):
return
- if 'async' not in kwargs and self.options['always']:
+ if 'async' not in kwargs and self.getOption('always'):
kwargs['async'] = True
page.text = newtext
--
To view, visit https://gerrit.wikimedia.org/r/157785
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie27946d546425b048cadea8a6ce0bd07b891bc91
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <ricordisamoa(a)openmailbox.org>
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: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: jenkins-bot <>
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 <>