summaryrefslogtreecommitdiff
path: root/lib/thandy
diff options
context:
space:
mode:
Diffstat (limited to 'lib/thandy')
-rw-r--r--lib/thandy/ClientCLI.py50
-rw-r--r--lib/thandy/repository.py7
2 files changed, 42 insertions, 15 deletions
diff --git a/lib/thandy/ClientCLI.py b/lib/thandy/ClientCLI.py
index ad39a2d..7d29de7 100644
--- a/lib/thandy/ClientCLI.py
+++ b/lib/thandy/ClientCLI.py
@@ -1,12 +1,14 @@
# Copyright 2008 The Tor Project, Inc. See LICENSE for licensing information.
+import getopt
+import logging
import os
import sys
-import getopt
import thandy.util
import thandy.repository
import thandy.download
+import thandy.master_keys
def update(args):
repoRoot = thandy.util.userFilename("cache")
@@ -21,24 +23,41 @@ def update(args):
repo = thandy.repository.LocalRepository(repoRoot)
- files = repo.getFilesToUpdate(trackingBundles=args)
+ while True:
+ hashes = {}
+ logging.info("Checking for files to update.")
+ files = repo.getFilesToUpdate(trackingBundles=args, hashDict=hashes)
+ logging.info("Files to download are: %s", ", ".join(sorted(files)))
+
+ if not download or not files:
+ return
+
+ mirrorlist = repo.getMirrorlistFile().get()
+ if not mirrorlist:
+ mirrorlist = thandy.master_keys.DEFAULT_MIRRORLIST
- if not download:
- return
+ downloader = thandy.download.DownloadManager()
- mirrorlist = repo.getMirrorlistFile().get()
+ for f in files:
+ dj = thandy.download.ThandyDownloadJob(f, repo.getFilename(f),
+ mirrorlist,
+ wantHash=hashes.get(f))
- downloader = thandy.download.Downloads()
- downloader.start()
+ def successCb(rp=f):
+ rf = repo.getRequestedFile(rp)
+ if rf != None:
+ rf.clear()
+ rf.load()
- for f in files:
- # XXXX Use hash.
- dj = thandy.download.ThandyDownloadJob(f, repo.getFilename(f),
- mirrorlist)
- downloader.addDownloadJob(dj)
- # XXXX replace file in repository if ok; reload; see what changed.
+ downloader.addDownloadJob(dj)
+
+ logging.info("Launching downloads")
+ downloader.start()
+
+ logging.info("Waiting for downloads to finish.")
+ downloader.wait()
+ logging.info("All downloads finished.")
- # Wait for in-progress jobs
# Check my repository
@@ -55,6 +74,9 @@ def usage():
sys.exit(1)
def main():
+ #XXXX make this an option.
+ logging.basicConfig(level=logging.DEBUG)
+
if len(sys.argv) < 2:
usage()
cmd = sys.argv[1]
diff --git a/lib/thandy/repository.py b/lib/thandy/repository.py
index af2fa4f..636ff86 100644
--- a/lib/thandy/repository.py
+++ b/lib/thandy/repository.py
@@ -174,6 +174,9 @@ class PkgFile:
def clear(self):
self._mtime = None
+ def load(self):
+ pass
+
def getRelativePath(self):
return self._relativePath
@@ -258,7 +261,7 @@ class LocalRepository:
return pkg
def getRequestedFile(self, relPath):
- """ """
+ """DOCDOC"""
for f in self._metafiles:
if f.getRelativePath() == relPath:
return f
@@ -274,6 +277,8 @@ class LocalRepository:
if rp == relPath:
return PkgFile(self, rp, thandy.formats.parseHash(h))
+ return None
+
def getFilesToUpdate(self, now=None, trackingBundles=(), hashDict=None):
"""Return a set of relative paths for all files that we need
to fetch. Assumes that we care about the bundles