Created
July 6, 2015 17:08
-
-
Save pandada8/632a7a5bab1de871de4f to your computer and use it in GitHub Desktop.
Rsync with aria2c
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