1 # Copyright (C) 2006, Thomas Leonard
2 # See http://0install.net/0compile.html
4 import sys
, os
, __main__
5 from logging
import info
11 raise __main__
.UsageError()
15 src_impl
= buildenv
.chosen_impl(buildenv
.interface
)
17 path
= lookup(src_impl
.id)
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')
24 # Make all files writable by the owner
25 for root
, dirs
, files
in os
.walk('src'):
27 path
= os
.path
.join(root
, f
)
28 os
.chmod(path
, os
.stat(path
).st_mode |
0200)
30 print "Copied as '%s'" % new_src
35 raise __main__
.UsageError()
38 if not os
.path
.isdir('src'):
39 raise SafeException('No local src directory to diff against!')
40 new_src
= os
.path
.realpath('src')
42 src_impl
= buildenv
.chosen_impl(buildenv
.interface
)
45 prog
= find_in_path('diff')
46 args
= ['-ur', lookup(src_impl
.id), new_src
]
48 status
= os
.spawnv(os
.P_WAIT
, prog
, [prog
] + args
)
54 raise SafeException("Program '%s' failed with exit code %d" % (prog
, status
))
56 raise SafeException("Program '%s' failed with signal %d" % (prog
, -status
))
58 __main__
.commands
+= [do_copy_src
, do_diff
]