Release 1.4
[0compile.git] / include_deps.py
blobbed011343a9a0fa80c23812a2563a0233845a129
1 # Copyright (C) 2007, Thomas Leonard
2 # See http://0install.net/0compile.html
4 import os, __main__
5 import shutil
7 from zeroinstall import SafeException
8 from zeroinstall.zerostore import manifest
10 from support import BuildEnv, ensure_dir, lookup
12 def do_include_deps(args):
13 """include-deps"""
14 buildenv = BuildEnv()
16 depdir = os.path.realpath('dependencies')
17 ensure_dir(depdir)
19 dirs_to_copy = []
21 sels = buildenv.get_selections()
22 for needed_iface in sels.selections:
23 impl = buildenv.chosen_impl(needed_iface)
24 assert impl
25 if impl.local_path is not None:
26 raise SafeException("Can't export '%s' as it's a local implementation (not supported yet; sorry)" % impl)
27 if not impl.id.startswith('package:'):
28 dirs_to_copy.append(lookup(impl))
30 copied = 0
31 for cached in dirs_to_copy:
32 required_digest = os.path.basename(cached)
33 target_impl_dir = os.path.join(depdir, required_digest)
34 if not os.path.isdir(target_impl_dir):
35 if required_digest.startswith('sha1='):
36 shutil.copytree(cached, target_impl_dir)
37 else:
38 manifest_data = file(os.path.join(cached, '.manifest')).read()
39 manifest.copy_tree_with_verify(cached, depdir, manifest_data, required_digest)
40 copied += 1
42 print "Copied %d dependencies to %s (%d already there)" % (copied, depdir, len(dirs_to_copy) - copied)
44 __main__.commands.append(do_include_deps)