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
|
#!/usr/bin/env python
import glob
import io
import os
import os.path
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
import gemato.hash
def write_manifest_entry(manifest_file, t, path, relpath, hashes):
checksums = gemato.hash.hash_path(path,
[x.lower() for x in hashes] + ['__size__'])
hashvals = []
for h in hashes:
hashvals += [h, checksums[h.lower()]]
manifest_file.write('{} {} {} {}\n'.format(t, relpath,
checksums['__size__'], ' '.join(hashvals)))
def write_manifest_entries_for_dir(manifest_file, topdir, hashes):
for dirpath, dirs, files in os.walk(topdir):
if dirpath != topdir:
for f in files:
if f.startswith('Manifest'):
fp = os.path.join(dirpath, f)
write_manifest_entry(manifest_file, 'MANIFEST',
fp, os.path.relpath(fp, topdir), hashes)
# do not descend
dirs.clear()
skip = True
break
else:
skip = False
if skip:
continue
for f in files:
if f.startswith('Manifest'):
continue
fp = os.path.join(dirpath, f)
write_manifest_entry(manifest_file, 'DATA',
fp, os.path.relpath(fp, topdir), hashes)
def gen_metamanifests(top_dir, hashes):
with io.open(os.path.join(top_dir, 'profiles/categories'), 'r') as f:
categories = [x.strip() for x in f]
alldirs = []
# we assume every package has thick Manifests already, so we just
# need to Manifest the Manifests
for c in categories:
alldirs.append(c)
alldirs.append(os.path.join('metadata/md5-cache', c))
# Manifest a few big dirs separately
alldirs.extend(['eclass', 'licenses', 'metadata/md5-cache', 'metadata/glsa',
'metadata/news', 'metadata', 'profiles'])
for bm in alldirs:
bmdir = os.path.join(top_dir, bm)
if not list(glob.glob(os.path.join(bmdir, 'Manifest*'))):
with io.open(os.path.join(bmdir, 'Manifest'), 'w') as f:
write_manifest_entries_for_dir(f, bmdir, hashes)
with io.open(os.path.join(top_dir, 'Manifest'), 'w') as f:
write_manifest_entries_for_dir(f, top_dir, hashes)
if __name__ == '__main__':
if len(sys.argv) != 3:
print('Usage: {} <rsync-path> <hashes>'.format(sys.argv[0]))
sys.exit(1)
gen_metamanifests(sys.argv[1], sys.argv[2].split())
|