2
from collections import defaultdict
6
from twisted.internet.defer import (
10
from twisted.internet.utils import getProcessValue
12
from linaro_android_mirror.factor_manifests import (
13
make_mirror_manifests,
18
prefix = '/mnt/mirror'
20
_directory_locks = defaultdict(DeferredLock)
23
def mirror_directory(hostname, manifest):
24
target_directory = os.path.join(prefix, hostname)
25
d = _directory_locks[target_directory]
27
assert os.path.exists(target_directory)
28
manifest_path = os.path.join(target_directory, '.repo/manifest.xml')
30
os.unlink(manifest_path)
32
if e.errno != errno.ENOENT:
34
with open(manifest_path, 'w') as manifest_file:
35
manifest_file.write(manifest)
36
print "'running'", '/usr/local/bin/repo', ['sync', '-j8'], 'in', target_directory
38
return getProcessValue(
39
'/usr/local/bin/repo', ['sync', '-j8'], path=target_directory)
43
def mirror(source_manifest):
44
slave_manifest = make_slave_manifest(source_manifest)
45
mirror_manifests = make_mirror_manifests(source_manifest)
47
for hostname, manifest in mirror_manifests:
48
ds.append(mirror_directory(hostname, manifest))
49
return gatherResults(ds).addCallback(lambda stuff: slave_manifest)