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', symlinks
= True)
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 if not os
.path
.islink(path
):
29 os
.chmod(path
, os
.stat(path
).st_mode |
0200)
31 print "Copied as '%s'" % new_src
36 raise __main__
.UsageError()
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
)
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
)
55 raise SafeException("Program '%s' failed with exit code %d" % (prog
, status
))
57 raise SafeException("Program '%s' failed with signal %d" % (prog
, -status
))
59 __main__
.commands
+= [do_copy_src
, do_diff
]