Updated id test to use local_path
[0compile.git] / 0compile
blobec234a1594ba1d67f82e3ee2a632d10bf6d96d76
1 #!/usr/bin/env python
2 # Copyright (C) 2006, Thomas Leonard
3 # See the README file for details, or visit http://0install.net.
5 __builtins__._ = lambda x: x
7 import locale
8 from optparse import OptionParser
9 import os, sys
10 from logging import warn
11 import gobject; gobject.threads_init()
13 zeroinstall_dir = os.environ.get('0COMPILE_ZEROINSTALL', None)
14 if zeroinstall_dir:
15 sys.path.insert(1, zeroinstall_dir)
17 from zeroinstall import SafeException
19 class UsageError(SafeException): pass
21 commands = []
23 import autocompile, setup, clean, copysrc, build, publish, gui, bugs, include_deps
24 import support
26 version = '0.26'
28 try:
29 locale.setlocale(locale.LC_ALL, '')
30 except locale.Error:
31 warn('Error setting locale (eg. Invalid locale)')
33 parser = OptionParser(usage="usage: %prog " +
34 '\n %prog '.join([c.__doc__ for c in commands]))
36 parser.add_option("-c", "--console", help="never use GUI", action='store_true')
37 parser.add_option("-v", "--verbose", help="more verbose output", action='count')
38 parser.add_option("-V", "--version", help="display version information", action='store_true')
40 parser.disable_interspersed_args()
42 (options, args) = parser.parse_args()
44 if options.version:
45 print "0compile (zero-install) " + version
46 print "Copyright (C) 2006 Thomas Leonard"
47 print "This program comes with ABSOLUTELY NO WARRANTY,"
48 print "to the extent permitted by law."
49 print "You may redistribute copies of this program"
50 print "under the terms of the GNU General Public License."
51 print "For more information about these matters, see the file named COPYING."
52 sys.exit(0)
54 if options.verbose:
55 import logging
56 logger = logging.getLogger()
57 if options.verbose == 1:
58 logger.setLevel(logging.INFO)
59 else:
60 logger.setLevel(logging.DEBUG)
62 if options.console:
63 support.launch_prog.append('--console')
65 if len(args) < 1:
66 parser.print_help()
67 sys.exit(1)
69 try:
70 pattern = args[0].lower()
71 matches = [c for c in commands if c.__name__[3:].replace('_', '-').startswith(pattern)]
72 if len(matches) == 0:
73 parser.print_help()
74 sys.exit(1)
75 if len(matches) > 1:
76 raise SafeException("What do you mean by '%s'?\n%s" %
77 (pattern, '\n'.join(['- ' + x.__name__[3:] for x in matches])))
78 matches[0](args[1:])
79 except KeyboardInterrupt, ex:
80 print >>sys.stderr, "Interrupted"
81 sys.exit(1)
82 except OSError, ex:
83 if options.verbose: raise
84 print >>sys.stderr, str(ex)
85 sys.exit(1)
86 except IOError, ex:
87 if options.verbose: raise
88 print >>sys.stderr, str(ex)
89 sys.exit(1)
90 except UsageError, ex:
91 print >>sys.stderr, str(ex)
92 print >>sys.stderr, "usage: " + os.path.basename(sys.argv[0]) + " " + matches[0].__doc__
93 sys.exit(1)
94 except SafeException, ex:
95 if options.verbose: raise
96 try:
97 print >>sys.stderr, unicode(ex)
98 except:
99 print >>sys.stderr, repr(ex)
100 sys.exit(1)