From 2f507ec69a5d499e12f42e041294114acc06ec5c Mon Sep 17 00:00:00 2001 From: Xibo Ning Date: Mar 24 2016 18:52:27 +0000 Subject: make the upload block size configurable --- diff --git a/cli/koji b/cli/koji index 437ac44..9991366 100755 --- a/cli/koji +++ b/cli/koji @@ -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 diff --git a/koji/__init__.py b/koji/__init__.py index 4b2f7ee..734c36b 100644 --- a/koji/__init__.py +++ b/koji/__init__.py @@ -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