Created
September 11, 2015 19:07
-
-
Save pandada8/f70ced47fa9f8efc5bee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import tempfile | |
import os | |
import sys | |
def getUpdateList(rsync_source, target_source): | |
files = subprocess.check_output(['/usr/bin/rsync', '--no-motd', '-havn', '--exclude=Sources', rsync_source, target_source]).decode() | |
print(files) | |
ret = [] | |
for i in files.split("\n")[1:-3]: | |
i = i.strip() | |
if not i.startswith("delet") and not i.endswith("/") and "->" not in i and not i.startswith('project/trace') and i: | |
ret.append(i) | |
return ret | |
def rersync(rsync_source, target_source): | |
subprocess.call(['/usr/bin/rsync', '--no-motd', '-hav', '--exclude=Sources', rsync_source, target_source]) | |
def genAriaList(filelist, http_source, target_source): | |
with tempfile.NamedTemporaryFile(delete=False) as fp: | |
data = "{}\n" " out={}\n" " dir={}\n" " auto-file-renaming=false\n" " allow-overwrite=true\n" | |
for i in filelist: | |
fp.write(data.format(os.path.join(http_source, i), i, target_source).encode('UTF8')) | |
return fp.name | |
def do_the_download(filename): | |
subprocess.call(["aria2", '-R', '-i', filename, '-c']) | |
os.remove(filename) | |
if __name__ == "__main__": | |
rsync_source, http_source, target = sys.argv[1:] | |
filelist = getUpdateList(rsync_source, target) | |
filename = genAriaList(filelist, http_source, target) | |
do_the_download(filename) | |
rersync(rsync_source, target) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment