jenkins-bot has submitted this change and it was merged.
Change subject: page.py: base isEmptyCategory on cat.categoryinfo
......................................................................
page.py: base isEmptyCategory on cat.categoryinfo
No change of functionality.
Test is based on check of properties rather than try to retrieve
content.
Tests added.
Change-Id: I6070c72882fbcd94a5526a158a9827738386bf51
---
M pywikibot/page.py
M tests/page_tests.py
2 files changed, 13 insertions(+), 3 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index e77b23e..5d8c8f7 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -2121,9 +2121,8 @@
def isEmptyCategory(self):
"""Return True if category has no members (including subcategories)."""
- for member in self.site.categorymembers(self, total=1):
- return False
- return True
+ ci = self.categoryinfo
+ return sum(ci[k] for k in ['files', 'pages', 'subcats']) == 0
def isHiddenCategory(self):
"""Return True if the category is hidden."""
diff --git a/tests/page_tests.py b/tests/page_tests.py
index ebc37d6..05d3228 100644
--- a/tests/page_tests.py
+++ b/tests/page_tests.py
@@ -400,6 +400,17 @@
# def contributingUsers(self):
+class TestCategoryObject(PywikibotTestCase):
+
+ def test_isEmptyCategory(self):
+ """Test if category is empty or not"""
+ site = pywikibot.Site('en', 'wikipedia')
+ cat_empty = pywikibot.Category(site, u'Category:foooooo')
+ cat_not_empty = pywikibot.Category(site, u'Category:Wikipedia categories')
+ self.assertTrue(cat_empty.isEmptyCategory())
+ self.assertFalse(cat_not_empty.isEmptyCategory())
+
+
if __name__ == '__main__':
try:
unittest.main()
--
To view, visit https://gerrit.wikimedia.org/r/157293
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I6070c72882fbcd94a5526a158a9827738386bf51
Gerrit-PatchSet: 3
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: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: [FIX] Safely close the files
......................................................................
[FIX] Safely close the files
Change-Id: I0b3f7fcca3b79474fd3cc21257ccb6e82087590b
---
M pywikibot/version.py
1 file changed, 7 insertions(+), 5 deletions(-)
Approvals:
Nullzero: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/version.py b/pywikibot/version.py
index 8826a4d..0b7d873 100644
--- a/pywikibot/version.py
+++ b/pywikibot/version.py
@@ -143,7 +143,8 @@
# some windows git versions provide git.cmd instead of git.exe
cmd = 'git.cmd'
- tag = open(os.path.join(_program_dir, '.git/config'), 'r').read()
+ with open(os.path.join(_program_dir, '.git/config'), 'r') as f:
+ tag = f.read()
# Try 'origin' and then 'gerrit' as remote name; bail if can't find either.
remote_pos = tag.find('[remote "origin"]')
if remote_pos == -1:
@@ -213,10 +214,11 @@
mtime = None
fn = os.path.join(_program_dir, filename)
if os.path.exists(fn):
- for line in open(fn, 'r').readlines():
- if line.find('__version__') == 0:
- exec(line)
- break
+ with open(fn, 'r') as f:
+ for line in f.readlines():
+ if line.find('__version__') == 0:
+ exec(line)
+ break
stat = os.stat(fn)
mtime = datetime.datetime.fromtimestamp(stat.st_mtime).isoformat(' ')
if mtime and __version__:
--
To view, visit https://gerrit.wikimedia.org/r/157487
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I0b3f7fcca3b79474fd3cc21257ccb6e82087590b
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Nullzero <nullzero.free(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: category.py: consider also files, not only pages
......................................................................
category.py: consider also files, not only pages
In CategoryTidyRobot(), a category is considered empty only if no pages
are present, while number of files is not considered.
This patch fixes it.
Change-Id: I1a340e2337d44caeedd435a40160736ea943d7cb
---
M scripts/category.py
1 file changed, 10 insertions(+), 8 deletions(-)
Approvals:
XZise: Looks good to me, but someone else must approve
Ladsgroup: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/category.py b/scripts/category.py
index fa7a3ea..cf07768 100755
--- a/scripts/category.py
+++ b/scripts/category.py
@@ -887,15 +887,17 @@
def run(self):
cat = pywikibot.Category(self.site, self.catTitle)
- if cat.categoryinfo['pages'] == 0:
- pywikibot.output(u'There are no articles in category %s'
+ empty = True
+ preloadingGen = pagegenerators.PreloadingGenerator(cat.articles())
+ for article in preloadingGen:
+ empty = False
+ pywikibot.output('')
+ pywikibot.output(u'=' * 67)
+ self.move_to_category(article, cat, cat)
+
+ if empty:
+ pywikibot.output(u'There are no articles or files in category %s'
% self.catTitle)
- else:
- preloadingGen = pagegenerators.PreloadingGenerator(cat.articles())
- for article in preloadingGen:
- pywikibot.output('')
- pywikibot.output(u'=' * 67)
- self.move_to_category(article, cat, cat)
class CategoryTreeRobot:
--
To view, visit https://gerrit.wikimedia.org/r/157292
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I1a340e2337d44caeedd435a40160736ea943d7cb
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Mpaa <mpaa.wiki(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: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Workaround flake8 2.2.3 breaking with pep257
......................................................................
Workaround flake8 2.2.3 breaking with pep257
pep257 yields some error which apparently cause flake8 2.2.3 to stall
completely waiting for some input. That can be worked around by
disabling multiprocessing (turned on by default with 2.2.3). Simply pass
--jobs=1 to flake8 in the flake8-docstrings job.
Upstream issue:
https://bitbucket.org/tarek/flake8/issue/167/flake8-223-stall-with-multipro…
Change-Id: Iff84c926b42846b4c36db30507851859a827e103
---
M tox.ini
1 file changed, 8 insertions(+), 1 deletion(-)
Approvals:
Ladsgroup: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tox.ini b/tox.ini
index 9fae601..00fcf0d 100644
--- a/tox.ini
+++ b/tox.ini
@@ -14,8 +14,15 @@
deps = flake8
[testenv:flake8-docstrings]
-commands = flake8 --select=D {posargs}
+commands = flake8 --select=D {posargs} --jobs=1
deps = flake8-docstrings
+# Note: flake8 is run here with --jobs=1 to disable multiprocessing which stall
+# the run with flake8-docstrings / pep257.
+# That appeared with flake8 2.2.3 which turns multiprocessing on by default.
+#
+# See upstream issue:
+# https://bitbucket.org/tarek/flake8/issue/167/flake8-223-stall-with-multipro…
+
[testenv:nose]
setenv = PYWIKIBOT2_NO_USER_CONFIG=1
--
To view, visit https://gerrit.wikimedia.org/r/157291
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iff84c926b42846b4c36db30507851859a827e103
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Hashar <hashar(a)free.fr>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: site.py: raise NoPage instead of Error
......................................................................
site.py: raise NoPage instead of Error
In site.movepage() raise NoPage instead of Error if no page exists.
This can be a problem for scripts that expect the proper exception.
E.g. movepages.py expects NoPage to be raised.
Added test in site_tests.py.
Also reordered imports in site_tests.py.
Change-Id: Ie89ec7dc8bd4ee99af4c8e51a779fedb52e098da
---
M pywikibot/site.py
M tests/site_tests.py
2 files changed, 15 insertions(+), 5 deletions(-)
Approvals:
XZise: Looks good to me, but someone else must approve
Ladsgroup: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py
index a19afa5..b125b54 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -3530,8 +3530,8 @@
raise Error("Cannot move page %s to its own title."
% oldtitle)
if not page.exists():
- raise Error("Cannot move page %s because it does not exist on %s."
- % (oldtitle, self))
+ raise NoPage("Cannot move page %s because it does not exist on %s."
+ % (oldtitle, self))
token = self.token(page, "move")
self.lock_page(page)
req = api.Request(site=self, action="move", to=newtitle,
diff --git a/tests/site_tests.py b/tests/site_tests.py
index b4e0540..3477872 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -8,14 +8,16 @@
__version__ = '$Id$'
+import sys
from distutils.version import LooseVersion as LV
from collections import Iterable
-import pywikibot
-from tests.utils import PywikibotTestCase, unittest
from datetime import datetime
import re
-import sys
+import pywikibot
+from pywikibot.exceptions import Error, NoPage
+from tests.utils import PywikibotTestCase, unittest
+
if sys.version_info[0] > 2:
basestring = (str, )
@@ -1035,6 +1037,14 @@
self.assertFalse(entered_loop(mysite.siteinfo.get(not_exists).values()))
self.assertFalse(entered_loop(mysite.siteinfo.get(not_exists).keys()))
+ def test_movepage(self):
+ self.assertRaises(Error, mysite.movepage, mainpage, 'Main Page', 'test')
+
+ page_from = pywikibot.Page(mysite, 'Not exiting page')
+ if not page_from.exists():
+ self.assertRaises(NoPage, mysite.movepage,
+ page_from, 'Main Page', 'test')
+
class TestSiteLoadRevisions(PywikibotTestCase):
--
To view, visit https://gerrit.wikimedia.org/r/156707
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie89ec7dc8bd4ee99af4c8e51a779fedb52e098da
Gerrit-PatchSet: 3
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: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
Mpaa has submitted this change and it was merged.
Change subject: [FEAT] Chunked uploads
......................................................................
[FEAT] Chunked uploads
This allows chunked uploads by setting the parameter 'chunk_size'
to a value between 0 and the file size (both exclusive). It will
also only work if the version is 1.20 or newer.
The upload.py script supports this mode via the '-chunked'
parameter.
This also adds the capability to run the API request without
throttle so that it don't has to wait after each request.
See: https://www.mediawiki.org/wiki/API:Upload#Chunked_uploading
Change-Id: I80b2bba9e63832173d5b697db1f4ea419ca1122f
---
M pywikibot/data/api.py
M pywikibot/site.py
M scripts/upload.py
3 files changed, 156 insertions(+), 36 deletions(-)
Approvals:
Mpaa: Looks good to me, approved
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index 8132a27..11df17b 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -129,6 +129,8 @@
@param site: The Site to which the request will be submitted. If not
supplied, uses the user's configured default Site.
@param mime: If true, send in "multipart/form-data" format (default False)
+ @param mime_params: A dictionary of parameter which should only be
+ transferred via mime mode. If not None sets mime to True.
@param max_retries: (optional) Maximum number of times to retry after
errors, defaults to 25
@param retry_wait: (optional) Minimum time to wait after an error,
@@ -143,7 +145,15 @@
self.site = kwargs.pop("site")
except KeyError:
self.site = pywikibot.Site()
- self.mime = kwargs.pop("mime", False)
+ if 'mime_params' in kwargs:
+ self.mime_params = kwargs.pop('mime_params')
+ # mime may not be different from mime_params
+ if 'mime' in kwargs and kwargs.pop('mime') != self.mime:
+ raise ValueError('If mime_params is set, mime may not differ '
+ 'from it.')
+ else:
+ self.mime = kwargs.pop('mime', False)
+ self.throttle = kwargs.pop('throttle', False)
self.max_retries = kwargs.pop("max_retries", pywikibot.config.max_retries)
self.retry_wait = kwargs.pop("retry_wait", pywikibot.config.retry_wait)
self.params = {}
@@ -210,6 +220,23 @@
def iteritems(self):
return iter(self.params.items())
+ @property
+ def mime(self):
+ """Return whether mime parameters are defined."""
+ return self.mime_params is not None
+
+ @mime.setter
+ def mime(self, value):
+ """
+ Change whether mime parameter should be defined.
+
+ This will clear the mime parameters.
+ """
+ try:
+ self.mime_params = dict(value)
+ except TypeError:
+ self.mime_params = {} if value else None
+
def http_params(self):
"""Return the parameters formatted for inclusion in an HTTP request.
@@ -218,7 +245,9 @@
unicode (may be |-separated list)
str in site encoding (may be |-separated list)
"""
-
+ if self.mime_params and set(self.params.keys()) & set(self.mime_params.keys()):
+ raise ValueError('The mime_params and params may not share the '
+ 'same keys.')
for key in self.params:
if isinstance(self.params[key], bytes):
self.params[key] = self.params[key].decode(self.site.encoding())
@@ -296,6 +325,23 @@
message = None
return message == ERR_MSG
+ @staticmethod
+ def _generate_MIME_part(key, content, keytype, headers):
+ if not keytype:
+ try:
+ content.encode("ascii")
+ keytype = ("text", "plain")
+ except UnicodeError:
+ keytype = ("application", "octet-stream")
+ submsg = MIMENonMultipart(*keytype)
+ content_headers = {'name': key}
+ if headers:
+ content_headers.update(headers)
+ submsg.add_header("Content-disposition", "form-data",
+ **content_headers)
+ submsg.set_payload(content)
+ return submsg
+
def submit(self):
"""Submit a query and parse the response.
@@ -308,7 +354,10 @@
simulate = self._simulate(action)
if simulate:
return simulate
- self.site.throttle(write=self.write)
+ if self.throttle:
+ self.site.throttle(write=self.write)
+ else:
+ pywikibot.log("Action '{0}' is submitted not throttled.".format(action))
uri = self.site.scriptpath() + "/api.php"
ssl = False
if self.site.family.name in config.available_ssl_project:
@@ -328,22 +377,15 @@
filetype = mimetypes.guess_type(local_filename)[0] \
or 'application/octet-stream'
file_content = file(local_filename, "rb").read()
- submsg = MIMENonMultipart(*filetype.split("/"))
- submsg.add_header("Content-disposition",
- "form-data", name=key,
- filename=local_filename)
- submsg.set_payload(file_content)
+ submsg = Request._generate_MIME_part(
+ key, file_content, filetype.split('/'),
+ {'filename': local_filename})
else:
- try:
- self.params[key].encode("ascii")
- keytype = ("text", "plain")
- except UnicodeError:
- keytype = ("application", "octet-stream")
- submsg = MIMENonMultipart(*keytype)
- submsg.add_header("Content-disposition", "form-data",
- name=key)
- submsg.set_payload(self.params[key])
+ submsg = Request._generate_MIME_part(
+ key, self.params[key], None, None)
container.attach(submsg)
+ for key, value in self.mime_params.items():
+ container.attach(Request._generate_MIME_part(key, *value))
# strip the headers to get the HTTP message body
body = container.as_string()
marker = "\n\n" # separates headers from body
diff --git a/pywikibot/site.py b/pywikibot/site.py
index fb8202d..21e0989 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -3858,7 +3858,8 @@
@deprecate_arg('imagepage', 'filepage')
def upload(self, filepage, source_filename=None, source_url=None,
- comment=None, text=None, watch=False, ignore_warnings=False):
+ comment=None, text=None, watch=False, ignore_warnings=False,
+ chunk_size=0):
"""Upload a file to the wiki.
Either source_filename or source_url, but not both, must be provided.
@@ -3875,7 +3876,11 @@
@param watch: If true, add filepage to the bot user's watchlist
@param ignore_warnings: if true, ignore API warnings and force
upload (for example, to overwrite an existing file); default False
-
+ @param chunk_size: The chunk size in bytesfor chunked uploading (see
+ U{https://www.mediawiki.org/wiki/API:Upload#Chunked_uploading}). It
+ will only upload in chunks, if the version number is 1.20 or higher
+ and the chunk size is positive but lower than the file size.
+ @type chunk_size: int
"""
upload_warnings = {
# map API warning codes to user error messages
@@ -3909,18 +3914,51 @@
if not text:
text = comment
token = self.token(filepage, "edit")
+ result = None
if source_filename:
# upload local file
# make sure file actually exists
if not os.path.isfile(source_filename):
raise ValueError("File '%s' does not exist."
% source_filename)
- # TODO: if file size exceeds some threshold (to be determined),
- # upload by chunks (--> os.path.getsize(source_filename))
+ additional_parameters = {}
+ throttle = True
+ filesize = os.path.getsize(source_filename)
+ if (chunk_size > 0 and chunk_size < filesize and
+ LV(self.version()) >= LV('1.20')):
+ offset = 0
+ file_key = None
+ with open(source_filename, 'rb') as f:
+ while True:
+ f.seek(offset)
+ chunk = f.read(chunk_size)
+ req = api.Request(site=self, action='upload', token=token,
+ stash='1', offset=offset, filesize=filesize,
+ filename=filepage.title(withNamespace=False),
+ mime_params={}, throttle=throttle)
+ req.mime_params['chunk'] = (chunk, None, {'filename': req.params['filename']})
+ if file_key:
+ req['filekey'] = file_key
+ # TODO: Proper error and warning handling
+ data = req.submit()['upload']
+ if 'warnings' in data:
+ result = data
+ break
+ file_key = data['filekey']
+ throttle = False
+ new_offset = int(data['offset'])
+ if offset + len(chunk) != new_offset:
+ pywikibot.warning('Unexpected offset.')
+ offset = new_offset
+ if data['result'] != 'Continue': # finished
+ additional_parameters['filekey'] = file_key
+ break
+ else:
+ additional_parameters = {'file': source_filename, 'mime': True}
req = api.Request(site=self, action="upload", token=token,
filename=filepage.title(withNamespace=False),
- file=source_filename, comment=comment,
- text=text, mime=True)
+ comment=comment, text=text, throttle=throttle,
+ **additional_parameters)
else:
# upload by URL
if "upload_by_url" not in self.userinfo["rights"]:
@@ -3930,16 +3968,17 @@
req = api.Request(site=self, action="upload", token=token,
filename=filepage.title(withNamespace=False),
url=source_url, comment=comment, text=text)
- if watch:
- req["watch"] = ""
- if ignore_warnings:
- req["ignorewarnings"] = ""
- try:
- result = req.submit()
- except api.APIError:
- # TODO: catch and process foreseeable errors
- raise
- result = result["upload"]
+ if not result:
+ if watch:
+ req["watch"] = ""
+ if ignore_warnings:
+ req["ignorewarnings"] = ""
+ try:
+ result = req.submit()
+ except api.APIError:
+ # TODO: catch and process foreseeable errors
+ raise
+ result = result["upload"]
pywikibot.debug(result, _logger)
if "warnings" in result:
warning = list(result["warnings"].keys())[0]
diff --git a/scripts/upload.py b/scripts/upload.py
index 8a9a44d..39f9df5 100755
--- a/scripts/upload.py
+++ b/scripts/upload.py
@@ -11,6 +11,15 @@
is given
-abortonwarn: Abort upload on the specified warning type. If no warning type
is specified abort on all warnings.
+ -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:
+ No suffix: Bytes
+ 'k': Kilobytes (1000 B)
+ 'M': Megabytes (1000000 B)
+ 'Ki': Kibibytes (1024 B)
+ 'Mi': Mebibytes (1024x1024 B)
+ The suffixes are case insenstive.
If any other arguments are given, the first is the URL or filename to upload,
and the rest is a proposed description to go with the upload. If none of these
@@ -34,6 +43,8 @@
import urllib
import urlparse
import tempfile
+import re
+import math
import pywikibot
import pywikibot.data.api
from pywikibot import config
@@ -43,7 +54,7 @@
def __init__(self, url, urlEncoding=None, description=u'',
useFilename=None, keepFilename=False,
verifyDescription=True, ignoreWarning=False,
- targetSite=None, uploadByUrl=False, aborts=[]):
+ targetSite=None, uploadByUrl=False, aborts=[], chunk_size=0):
"""
@param ignoreWarning: Set this to True if you want to upload even if
another file would be overwritten or another mistake would be
@@ -58,6 +69,7 @@
self.verifyDescription = verifyDescription
self.ignoreWarning = ignoreWarning
self.aborts = aborts
+ self.chunk_size = chunk_size
if config.upload_to_commons:
self.targetSite = targetSite or pywikibot.Site('commons',
'commons')
@@ -224,7 +236,8 @@
else:
temp = self.url
site.upload(imagepage, source_filename=temp,
- ignore_warnings=self.ignoreWarning)
+ ignore_warnings=self.ignoreWarning,
+ chunk_size=self.chunk_size)
except pywikibot.data.api.UploadWarning as warn:
pywikibot.output(u"We got a warning message: {0}".format(warn.message))
@@ -266,6 +279,8 @@
useFilename = None
verifyDescription = True
aborts = set()
+ chunk_size = 0
+ chunk_size_regex = re.compile(r'^-chunked(?::(\d+(?:\.\d+)?)[ \t]*(k|ki|m|mi)?b?)?$', re.I)
# process all global bot args
# returns a list of non-global args, i.e. args for upload.py
@@ -282,6 +297,30 @@
aborts.add(arg[len('-abortonwarn:'):])
else:
aborts = True
+ elif arg.startswith('-chunked'):
+ match = chunk_size_regex.match(arg)
+ if match:
+ if match.group(1): # number was in there
+ base = float(match.group(1))
+ if match.group(2): # suffix too
+ suffix = match.group(2).lower()
+ if suffix == "k":
+ suffix = 1000
+ elif suffix == "m":
+ suffix = 1000000
+ elif suffix == "ki":
+ suffix = 1 << 10
+ elif suffix == "mi":
+ suffix = 1 << 20
+ else:
+ pass # huh?
+ else:
+ suffix = 1
+ chunk_size = math.trunc(base * suffix)
+ else:
+ chunk_size = 1 << 20 # default to 1 MiB
+ else:
+ pywikibot.error('Chunk size parameter is not valid.')
elif url == u'':
url = arg
else:
@@ -290,7 +329,7 @@
bot = UploadRobot(url, description=description, useFilename=useFilename,
keepFilename=keepFilename,
verifyDescription=verifyDescription,
- aborts=aborts)
+ aborts=aborts, chunk_size=chunk_size)
bot.run()
if __name__ == "__main__":
--
To view, visit https://gerrit.wikimedia.org/r/156030
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I80b2bba9e63832173d5b697db1f4ea419ca1122f
Gerrit-PatchSet: 4
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <CommodoreFabianus(a)gmx.de>
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: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>