-
-
Notifications
You must be signed in to change notification settings - Fork 181
/
Copy pathmirror-zsync.py
executable file
·54 lines (42 loc) · 1.6 KB
/
mirror-zsync.py
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
#!/usr/bin/env python
# this script generates zsync files
# zsyncmake -e -v -b 1024 [ -u http://... for each mirror ] FILE.tar.gz -o meta/FILE.tar.gz.zsync
import os
import sys
print("zsync doesn't work ... this file is just for reference")
sys.exit(1)
# script uses relative paths, switch to its
os.chdir(os.path.dirname(os.path.abspath(sys.argv[0])))
basecmd = 'zsyncmake -e -v -b 1024 '
rootdir = './www/mirror/'
roots = map(os.path.expanduser, ['./www/mirror/livecd', './www/mirror/win', './www/mirror/linux', './www/mirror/osx', './www/mirror/solaris', './www/mirror/src'])
# get the URLs for the mirrors
mirrors = []
with open(os.path.expanduser('~/www2-dev/www/metalink.helper')) as f:
for l in f:
url = l.split('%')[1].strip()
mirrors.append(url)
# print mirrors
def mirrorcmd(p, fn):
p = p[len(rootdir):]
return ' '.join(['-u %s%s/%s' % (_, p, fn) for _ in mirrors])
for root in roots:
for dir, dirs, files in os.walk(root):
if 'meta' not in dirs:
continue
print('Directory %s' % dir)
for fn in files:
f = os.path.join(dir, fn)
if fn.endswith('zsync'):
continue
z = os.path.join(dir, 'meta', fn) + '.zsync'
if os.path.exists(z):
print('skipped file already exists: %s' % z)
continue
if os.path.getsize(f) < 1024 * 1024 * 10:
continue
print('Calling zsync on ', f)
m = mirrorcmd(dir, fn)
cmd = basecmd + m + ' ' + f + ' -o ' + z
# print('executing:', cmd)
os.system(cmd)