# HG changeset patch # User Fabien Ninoles # Date 1406509674 14400 # Node ID 7567c5e4db458afb6d4554fbdb05741cc0cdd9f4 # Parent 9d5880ecdb8202d31f2d1077b64f227d6d795b44 Add a "cache-dir" option to the script. diff -r 9d5880ecdb82 -r 7567c5e4db45 update-hib.py --- a/update-hib.py Sun Jul 06 08:54:22 2014 -0400 +++ b/update-hib.py Sun Jul 27 21:07:54 2014 -0400 @@ -230,7 +230,7 @@ for o in self.other: o.write(s) -def main(fn): +def main(fn, cachedir): selector = FileSelector() downloads = [] import sys @@ -262,12 +262,16 @@ import urllib.request urlfile = open('http-download.sh','w') opener = urllib.request.build_opener() + cache = set(os.listdir(cachedir)) for dl in (dl for dl in downloads): if dl.torrent: try: fn = os.path.basename(urllib.parse.urlsplit(dl.torrent).path) if os.path.exists(fn): logging.info("Skipping existing torrent %s", fn) + elif fn in cache: + logging.info("Copying %s as %s from cache", dl.torrent, fn) + os.link(os.path.join(cachedir, fn), fn) else: logging.info("Saving %s as %s", dl.torrent, fn) with opener.open(dl.torrent) as u: @@ -286,4 +290,4 @@ if __name__ == '__main__': import sys logging.getLogger().setLevel(logging.INFO) - main(sys.argv[1]) + main(sys.argv[1], sys.argv[2])