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
|
#!/usr/bin/python
# vi: ts=4 noexpandtab
import sys
import os
import errno
from optparse import OptionParser
usage = "Usage: %prog latest-file [base]"
description = """
output a manifest file formated like
http://cdimages.ubuntu.com/.manifest-daily or
http://releases.ubuntu.com/.manifest
craws data stored at dirname(latest-file). paths found under that
directory are relavant to 'base'. base defaults to PUBLISH_BASE environment
"""
def fail(msg=None):
if msg: sys.stderr.write(msg)
sys.exit(1)
def main():
parser = OptionParser(usage=usage, description=description)
parser.add_option("--query-base", action="store", dest="qbase",
default=None, help="query base. defaults to dirname(latest-file)")
(options, args) = parser.parse_args()
if len(args) < 1 or len(args) > 2:
parser.error("must provide latest-file and optionally base")
lfile = args[0]
if len(args) < 2:
if "PUBLISH_BASE" in os.environ:
base = os.environ["PUBLISH_BASE"]
else:
parser.error("base not provided, must set or define PUBLISH_BASE")
else:
base = args[1]
if options.qbase == None:
qbase = os.path.dirname(lfile)
try:
lfp = open(lfile)
lines = lfp.read().splitlines()
lfp.close()
except IOError as e:
fail("failed to open %s:%s\n" % (lfile,e))
for line in lines:
(rel, buildname, label, serial) = line.split('\t',4)
rtype = "daily"
if label != "daily": rtype="released"
dl_file = "%s/%s/%s/%s-dl.current.txt" % (qbase,rel,buildname,rtype)
dlfp = open(dl_file)
dl_lines = dlfp.read().splitlines()
dlfp.close()
for dl_line in dl_lines:
(dl_r, dl_bn, dl_label, dl_ser, arch, path, sname) = \
dl_line.split('\t')[0:7]
try:
size = os.stat("%s/%s" % (base, path)).st_size
except OSError as e:
if e.errno == errno.ENOENT:
fail("%s/%s referenced in %s did not exist\n" %
(base,path, dl_file))
raise
print "cloudimg-%s\t%s\t/%s\t%s" % (buildname,rel,path,size)
sys.exit(0)
if __name__ == "__main__":
main()
|