diff options
Diffstat (limited to 'yum-fast-downloader.py')
-rw-r--r-- | yum-fast-downloader.py | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/yum-fast-downloader.py b/yum-fast-downloader.py index 5606c7f..4840fd0 100644 --- a/yum-fast-downloader.py +++ b/yum-fast-downloader.py @@ -36,15 +36,14 @@ plugin_type = (TYPE_CORE,) originalRetrieveMD = YumRepository._retrieveMD downloader_app = '' global_cache_dir='' +downloader_common_args = { + 'aria2c' : ["aria2c", "--continue", "--check-certificate=false"] +} # downloader functions def _getAria2CArgs(urls, remote_path, local_path, proxies = None): - args = ["aria2c"] - args.append("--continue") - args.append("--check-certificate=false") - args.append("--server-stat-if={0}/aria2c_server_stats".format(global_cache_dir)) - args.append("--server-stat-of={0}/aria2c_server_stats".format(global_cache_dir)) + args = downloader_common_args['aria2c'] args.append("--out={0}".format(os.path.basename(local_path))) args.append("--dir={0}".format(os.path.dirname(local_path))) for url in urls: @@ -62,7 +61,8 @@ def downloadFile(urls, remote_path, local_path, proxies = None): args = _getAria2CArgs(urls, remote_path, local_path) ret = os.spawnvp(os.P_WAIT, downloader_app, args) if ret: - raise yum.plugins.PluginYumExit("{0} exited with exit code: {1}".format(downloader_app, ret)) + raise yum.plugins.PluginYumExit( + "{0} exited with exit code: {1}".format(downloader_app, ret)) def queueDownload(inputFile, urls, remote_path, local_path, proxies = None): if urls[0].startswith("http://") or urls[0].startswith("ftp://"): @@ -79,16 +79,12 @@ def queueDownload(inputFile, urls, remote_path, local_path, proxies = None): inputFile.write(" {0}-proxy={1}\n".format(scheme, proxy)) def downloadQueuedFiles(inputFileName): - args = ["aria2c"] - args.append("--continue") - args.append("--check-certificate=false") - args.append("--server-stat-if={0}/aria2c_server_stats".format(global_cache_dir)) - args.append("--server-stat-of={0}/aria2c_server_stats".format(global_cache_dir)) - args.append("--max-concurrent-downloads=5") + args = downloader_common_args['aria2c'] args.append("--input-file={0}".format(inputFileName)) ret = os.spawnvp(os.P_WAIT, "aria2c", args) if ret: - raise yum.plugins.PluginYumExit("{0} exited with exit code: {1}".format(downloader_app, ret)) + raise yum.plugins.PluginYumExit( + "{0} exited with exit code: {1}".format(downloader_app, ret)) # Hooks! @@ -124,8 +120,20 @@ def myRetrieveMD(self, mdtype, retrieve_can_fail=False): def postconfig_hook(conduit): global downloader_app global global_cache_dir + global downloader_common_args downloader_app = conduit.confString('main', 'downloader', default='aria2c') - global_cache_dir=conduit.getConf().cachedir + global_cache_dir = conduit.getConf().cachedir + max_concurrent_downloads = conduit.confString('main', + 'max-concurrent-downloads', default='10') + + # append aria2c options + downloader_common_args['aria2c'].append( + "--server-stat-if={0}/aria2c_server_stats".format(global_cache_dir)) + downloader_common_args['aria2c'].append( + "--server-stat-of={0}/aria2c_server_stats".format(global_cache_dir)) + downloader_common_args['aria2c'].append( + "--max-concurrent-downloads={0}".format(max_concurrent_downloads)) + def postreposetup_hook(conduit): ret_insmethod = type(YumRepository._retrieveMD) @@ -153,7 +161,8 @@ def predownload_hook(conduit): # download_dir = os.path.join(pkg.repo.cachedir, 'alternative_downloader_cache') # conduit.info(2, "Getting: {0} into {1}".format(pkg.remote_url, local)) # downloadFile(pkg.repo.urls, pkg.remote_path, local, pkg.repo.proxy_dict) - queueDownload(ariaInputFile, pkg.repo.urls, pkg.remote_path, local, pkg.repo.proxy_dict) + queueDownload(ariaInputFile, pkg.repo.urls, pkg.remote_path, + local, pkg.repo.proxy_dict) ariaInputFile.close() downloadQueuedFiles(inputFileName) os.unlink(inputFileName) |