1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# Copyright 2008 The Tor Project, Inc. See LICENSE for licensing information.
import getopt
import logging
import os
import sys
import thandy.util
import thandy.repository
import thandy.download
import thandy.master_keys
def update(args):
repoRoot = thandy.util.userFilename("cache")
options, args = getopt.getopt(args, "", [ "repo=", "no-download" ])
download = True
for o, v in options:
if o == '--repo':
repoRoot = v
elif o == "--no-download":
download = False
repo = thandy.repository.LocalRepository(repoRoot)
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
downloader = thandy.download.DownloadManager()
for f in files:
dj = thandy.download.ThandyDownloadJob(f, repo.getFilename(f),
mirrorlist,
wantHash=hashes.get(f))
def successCb(rp=f):
rf = repo.getRequestedFile(rp)
if rf != None:
rf.clear()
rf.load()
downloader.addDownloadJob(dj)
logging.info("Launching downloads")
downloader.start()
logging.info("Waiting for downloads to finish.")
downloader.wait()
logging.info("All downloads finished.")
# Check my repository
# Tell me what I need to download
# Download stuff
# Tell me what to install.
def usage():
print "Known commands:"
print " update [--repo=repository] [--no-download]"
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]
args = sys.argv[2:]
if cmd in [ "update", "geturls" ]:
globals()[cmd](args)
else:
usage()
if __name__ == '__main__':
main()
|