Only display selected dependencies in autocompile output
[0compile.git] / copysrc.py
blobb00d8ee003dfb7b58d1b75b51e5b20f1eafb0679
1 # Copyright (C) 2006, Thomas Leonard
2 # See http://0install.net/0compile.html
4 import os, __main__
5 import shutil
7 from zeroinstall import SafeException
9 from support import BuildEnv, lookup, find_in_path
11 def do_copy_src(args):
12 """copy-src"""
13 if args:
14 raise __main__.UsageError()
16 buildenv = BuildEnv()
18 src_impl = buildenv.chosen_impl(buildenv.interface)
19 assert src_impl
20 path = lookup(src_impl)
21 assert path
23 new_src = os.path.realpath('src') # Just for better messages
24 if os.path.exists(new_src):
25 raise SafeException("Directory '%s' already exists!" % new_src)
26 shutil.copytree(path, 'src', symlinks = True)
27 # Make all files writable by the owner
28 for root, dirs, files in os.walk('src'):
29 os.chmod(root, os.stat(root).st_mode | 0200)
30 for f in files:
31 path = os.path.join(root, f)
32 if not os.path.islink(path):
33 os.chmod(path, os.stat(path).st_mode | 0200)
35 print "Copied as '%s'" % new_src
37 def do_diff(args):
38 """diff"""
39 if args:
40 raise __main__.UsageError()
41 buildenv = BuildEnv()
43 if not os.path.isdir('src'):
44 raise SafeException('No local src directory to diff against!')
45 new_src = os.path.realpath('src')
47 src_impl = buildenv.chosen_impl(buildenv.interface)
48 assert src_impl
50 prog = find_in_path('diff')
51 args = ['-ur', lookup(src_impl), new_src]
53 status = os.spawnv(os.P_WAIT, prog, [prog] + args)
54 if status == 0:
55 return False
56 elif status == 1:
57 return True
58 elif status > 1:
59 raise SafeException("Program '%s' failed with exit code %d" % (prog, status))
60 elif status < 0:
61 raise SafeException("Program '%s' failed with signal %d" % (prog, -status))
63 __main__.commands += [do_copy_src, do_diff]