Don't treat 'src' as a local copy if it coincides with the original
[0compile.git] / gui.py
bloba16b120206466a1c2ea831eb3085021274f0a36d
1 # Copyright (C) 2006, Thomas Leonard
2 # See http://0install.net/0compile.html
4 # This is normally called by 0launch's GUI.
6 import sys, os, __main__
7 from zeroinstall.injector.iface_cache import iface_cache
8 from logging import info
10 from support import *
12 def do_gui(args):
13 "gui [--no-prompt] [SOURCE-URI]"
14 prompt = True
15 if args and args[0] == '--no-prompt':
16 del args[0]
17 prompt = False
19 import gui_support
20 import gtk
22 if len(args) == 0:
23 env = BuildEnv()
24 interface = env.interface
25 build_dir = None
26 prompt = False
27 elif len(args) == 1:
28 interface = args[0]
29 default_dir = os.path.basename(interface)
30 if default_dir.endswith('.xml'):
31 default_dir = default_dir[:-4]
32 assert '/' not in default_dir
34 interface = model.canonical_iface_uri(args[0])
36 build_dir = gui_support.choose_dir(_('Create build directory'), default_dir)
37 if not build_dir: return
38 else:
39 raise __main__.UsageError()
41 try:
42 import setup
43 setup.setup(interface, build_dir, prompt)
44 if build_dir:
45 os.chdir(build_dir)
47 box = gui_support.CompileBox(interface)
48 box.connect('destroy', lambda b: gtk.main_quit())
49 box.show()
51 gtk.main()
52 except KeyboardInterrupt:
53 pass
54 except SafeException, ex:
55 gui_support.alert(None, '%s' % ex)
56 sys.exit(1)
57 except Exception, ex:
58 import traceback
59 traceback.print_exc()
60 gui_support.alert(None, '%s: %s' % (ex.__class__, ex))
61 sys.exit(1)
63 __main__.commands.append(do_gui)