In the 0compile-env.xml file, list the interfaces sorted by URI. Having
[0compile.git] / copysrc.py
blob72253bfae5643a0e3658c784ad09c83f04bddadd
1 # Copyright (C) 2006, Thomas Leonard
2 # See http://0install.net/0compile.html
4 import sys, os, __main__
5 from logging import info
6 from support import *
8 def do_copy_src(args):
9 """copy-src"""
10 if args:
11 raise __main__.UsageError()
13 buildenv = BuildEnv()
15 src_impl = buildenv.chosen_impl(buildenv.interface)
16 assert src_impl
17 path = lookup(src_impl.id)
18 assert path
20 new_src = os.path.realpath('src') # Just for better messages
21 if os.path.exists(new_src):
22 raise SafeException("Directory '%s' already exists!" % new_src)
23 shutil.copytree(path, 'src', symlinks = True)
24 # Make all files writable by the owner
25 for root, dirs, files in os.walk('src'):
26 for f in files:
27 path = os.path.join(root, f)
28 if not os.path.islink(path):
29 os.chmod(path, os.stat(path).st_mode | 0200)
31 print "Copied as '%s'" % new_src
33 def do_diff(args):
34 """diff"""
35 if args:
36 raise __main__.UsageError()
37 buildenv = BuildEnv()
39 if not os.path.isdir('src'):
40 raise SafeException('No local src directory to diff against!')
41 new_src = os.path.realpath('src')
43 src_impl = buildenv.chosen_impl(buildenv.interface)
44 assert src_impl
46 prog = find_in_path('diff')
47 args = ['-ur', lookup(src_impl.id), new_src]
49 status = os.spawnv(os.P_WAIT, prog, [prog] + args)
50 if status == 0:
51 return False
52 elif status == 1:
53 return True
54 elif status > 1:
55 raise SafeException("Program '%s' failed with exit code %d" % (prog, status))
56 elif status < 0:
57 raise SafeException("Program '%s' failed with signal %d" % (prog, -status))
59 __main__.commands += [do_copy_src, do_diff]