From d0eb16db58042da121cf0b784be6af6137f4f0a5 Mon Sep 17 00:00:00 2001 From: Daniel Julius Lasiman Date: Sat, 6 Jun 2015 22:12:17 +0700 Subject: [PATCH] Improve download speed of update plugin script --- update_plugins.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/update_plugins.py b/update_plugins.py index 62d7e16e..4409c42a 100644 --- a/update_plugins.py +++ b/update_plugins.py @@ -1,3 +1,11 @@ +try: + import concurrent.futures as futures +except ImportError: + try: + import futures + except ImportError: + futures = None + import zipfile import shutil import tempfile @@ -72,14 +80,21 @@ def download_extract_replace(plugin_name, zip_path, temp_dir, source_dir): print('Updated {0}'.format(plugin_name)) +def update(plugin): + name, github_url = plugin.split(' ') + zip_path = GITHUB_ZIP % github_url + download_extract_replace(name, zip_path, + temp_directory, SOURCE_DIR) + + if __name__ == '__main__': temp_directory = tempfile.mkdtemp() try: - for line in PLUGINS.splitlines(): - name, github_url = line.split(' ') - zip_path = GITHUB_ZIP % github_url - download_extract_replace(name, zip_path, - temp_directory, SOURCE_DIR) + if futures: + with futures.ThreadPoolExecutor(16) as executor: + executor.map(update, PLUGINS.splitlines()) + else: + [update(x) for x in PLUGINS.splitlines()] finally: shutil.rmtree(temp_directory)