Updated test for new GNU Hello
[0compile.git] / copysrc.py
blob738b360bc3ed0f24ba05b0fdb5fb9d92fd44451f
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)
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 os.chmod(root, os.stat(root).st_mode | 0200)
27 for f in files:
28 path = os.path.join(root, f)
29 if not os.path.islink(path):
30 os.chmod(path, os.stat(path).st_mode | 0200)
32 print "Copied as '%s'" % new_src
34 def do_diff(args):
35 """diff"""
36 if args:
37 raise __main__.UsageError()
38 buildenv = BuildEnv()
40 if not os.path.isdir('src'):
41 raise SafeException('No local src directory to diff against!')
42 new_src = os.path.realpath('src')
44 src_impl = buildenv.chosen_impl(buildenv.interface)
45 assert src_impl
47 prog = find_in_path('diff')
48 args = ['-ur', lookup(src_impl), new_src]
50 status = os.spawnv(os.P_WAIT, prog, [prog] + args)
51 if status == 0:
52 return False
53 elif status == 1:
54 return True
55 elif status > 1:
56 raise SafeException("Program '%s' failed with exit code %d" % (prog, status))
57 elif status < 0:
58 raise SafeException("Program '%s' failed with signal %d" % (prog, -status))
60 __main__.commands += [do_copy_src, do_diff]