Improve download speed of update plugin script
This commit is contained in:
parent
0c914e09cc
commit
6773769038
1 changed files with 20 additions and 5 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
try:
|
||||||
|
import concurrent.futures as futures
|
||||||
|
except ImportError:
|
||||||
|
try:
|
||||||
|
import futures
|
||||||
|
except ImportError:
|
||||||
|
futures = None
|
||||||
|
|
||||||
import zipfile
|
import zipfile
|
||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
|
@ -76,14 +84,21 @@ def download_extract_replace(plugin_name, zip_path, temp_dir, source_dir):
|
||||||
print('Updated {0}'.format(plugin_name))
|
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__':
|
if __name__ == '__main__':
|
||||||
temp_directory = tempfile.mkdtemp()
|
temp_directory = tempfile.mkdtemp()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for line in PLUGINS.splitlines():
|
if futures:
|
||||||
name, github_url = line.split(' ')
|
with futures.ThreadPoolExecutor(16) as executor:
|
||||||
zip_path = GITHUB_ZIP % github_url
|
executor.map(update, PLUGINS.splitlines())
|
||||||
download_extract_replace(name, zip_path,
|
else:
|
||||||
temp_directory, SOURCE_DIR)
|
[update(x) for x in PLUGINS.splitlines()]
|
||||||
finally:
|
finally:
|
||||||
shutil.rmtree(temp_directory)
|
shutil.rmtree(temp_directory)
|
||||||
|
|
Loading…
Reference in a new issue