1 # Copyright (C) 2006, Thomas Leonard
2 # See http://0install.net/0compile.html
7 from zeroinstall
import SafeException
9 from support
import BuildEnv
, lookup
, find_in_path
11 def do_copy_src(args
):
14 raise __main__
.UsageError()
18 src_impl
= buildenv
.chosen_impl(buildenv
.interface
)
20 path
= lookup(src_impl
)
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)
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
40 raise __main__
.UsageError()
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
)
50 prog
= find_in_path('diff')
51 args
= ['-ur', lookup(src_impl
), new_src
]
53 status
= os
.spawnv(os
.P_WAIT
, prog
, [prog
] + args
)
59 raise SafeException("Program '%s' failed with exit code %d" % (prog
, status
))
61 raise SafeException("Program '%s' failed with signal %d" % (prog
, -status
))
63 __main__
.commands
+= [do_copy_src
, do_diff
]