make the upload block size configurable

This commit is contained in:
Xibo Ning 2016-03-24 14:46:49 -04:00 committed by Mike McLean
parent 9ecc283d4e
commit 2f507ec69a
2 changed files with 15 additions and 5 deletions

View file

@ -157,6 +157,7 @@ def get_options():
parser.add_option("--weburl", help=_("url of the Koji web interface"))
parser.add_option("--topurl", help=_("url for Koji file access"))
parser.add_option("--pkgurl", help=optparse.SUPPRESS_HELP)
parser.add_option("--upload-blocksize", help=_("upload the koji hub how many bytes per request"))
parser.add_option("--help-commands", action="store_true", default=False, help=_("list commands"))
(options, args) = parser.parse_args()
@ -210,6 +211,7 @@ def get_options():
'keepalive' : True,
'timeout' : None,
'use_fast_upload': False,
'upload_blocksize': 1048576,
'poll_interval': 5,
'krbservice': 'host',
'cert': '~/.koji/client.crt',
@ -254,7 +256,8 @@ def get_options():
if name in ('anon_retry', 'offline_retry', 'keepalive', 'use_fast_upload'):
defaults[name] = config.getboolean(options.profile, name)
elif name in ('max_retries', 'retry_interval',
'offline_retry_interval', 'poll_interval', 'timeout'):
'offline_retry_interval', 'poll_interval', 'timeout',
'upload_blocksize'):
try:
defaults[name] = int(value)
except ValueError:
@ -6934,8 +6937,9 @@ if __name__ == "__main__":
session_opts = {}
for k in ('user', 'password', 'krbservice', 'debug_xmlrpc', 'debug', 'max_retries',
'retry_interval', 'offline_retry', 'offline_retry_interval',
'anon_retry', 'keepalive', 'timeout', 'use_fast_upload'):
'retry_interval', 'offline_retry', 'offline_retry_interval',
'anon_retry', 'keepalive', 'timeout', 'use_fast_upload',
'upload_blocksize'):
value = getattr(options,k)
if value is not None:
session_opts[k] = value

View file

@ -2015,7 +2015,10 @@ class ClientSession(object):
# raise AttributeError, "no attribute %r" % name
return VirtualMethod(self._callMethod,name)
def fastUpload(self, localfile, path, name=None, callback=None, blocksize=1048576, overwrite=False):
def fastUpload(self, localfile, path, name=None, callback=None, blocksize=None, overwrite=False):
if blocksize is None:
blocksize = self.opts.get('upload_blocksize')
if not self.logged_in:
raise ActionNotAllowed, 'You must be logged in to upload files'
if name is None:
@ -2089,8 +2092,11 @@ class ClientSession(object):
request = chunk
return handler, headers, request
def uploadWrapper(self, localfile, path, name=None, callback=None, blocksize=1048576, overwrite=True):
def uploadWrapper(self, localfile, path, name=None, callback=None, blocksize=None, overwrite=True):
"""upload a file in chunks using the uploadFile call"""
if blocksize is None:
blocksize = self.opts.get('upload_blocksize')
if self.opts.get('use_fast_upload'):
self.fastUpload(localfile, path, name, callback, blocksize, overwrite)
return