Add a "cache-dir" option to the script.
--- 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])