The GUI's Publish button now works.
[0compile.git] / copysrc.py
blob3ab7d8b33fda2208f0a3bd3f55f05b06cfa96120
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')
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 os.chmod(path, os.stat(path).st_mode | 0200)
30 print "Copied as '%s'" % new_src
32 def do_diff(args):
33 """diff"""
34 if args:
35 raise __main__.UsageError()
36 buildenv = BuildEnv()
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)
43 assert src_impl
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)
49 if status == 0:
50 return False
51 elif status == 1:
52 return True
53 elif status > 1:
54 raise SafeException("Program '%s' failed with exit code %d" % (prog, status))
55 elif status < 0:
56 raise SafeException("Program '%s' failed with signal %d" % (prog, -status))
58 __main__.commands += [do_copy_src, do_diff]