Replace * in archive name with something more sensible
[0compile.git] / 0compile
blob775d7e9e2a12badbc9b21ed2abdf9662a3b63e03
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
12 zeroinstall_dir = os.environ.get('0COMPILE_ZEROINSTALL', None)
13 if zeroinstall_dir:
14 sys.path.insert(1, zeroinstall_dir)
16 import zeroinstall
18 if map(int, zeroinstall.version.split('.')) < [0, 24]:
19 print >>sys.stderr, "Your version of 0launch (%s) is too old. " \
20 "I need version 0.24 or later." % zeroinstall.version
21 sys.exit(1)
23 from zeroinstall import SafeException
25 class UsageError(SafeException): pass
27 commands = []
29 import autocompile, setup, clean, copysrc, build, publish, gui, bugs, include_deps
30 import support
32 version = '0.23'
34 try:
35 locale.setlocale(locale.LC_ALL, '')
36 except locale.Error:
37 warn('Error setting locale (eg. Invalid locale)')
39 parser = OptionParser(usage="usage: %prog " +
40 '\n %prog '.join([c.__doc__ for c in commands]))
42 parser.add_option("-c", "--console", help="never use GUI", action='store_true')
43 parser.add_option("-v", "--verbose", help="more verbose output", action='count')
44 parser.add_option("-V", "--version", help="display version information", action='store_true')
46 parser.disable_interspersed_args()
48 (options, args) = parser.parse_args()
50 if options.version:
51 print "0compile (zero-install) " + version
52 print "Copyright (C) 2006 Thomas Leonard"
53 print "This program comes with ABSOLUTELY NO WARRANTY,"
54 print "to the extent permitted by law."
55 print "You may redistribute copies of this program"
56 print "under the terms of the GNU General Public License."
57 print "For more information about these matters, see the file named COPYING."
58 sys.exit(0)
60 if options.verbose:
61 import logging
62 logger = logging.getLogger()
63 if options.verbose == 1:
64 logger.setLevel(logging.INFO)
65 else:
66 logger.setLevel(logging.DEBUG)
68 if options.console:
69 support.launch_prog.append('--console')
71 if len(args) < 1:
72 parser.print_help()
73 sys.exit(1)
75 try:
76 pattern = args[0].lower()
77 matches = [c for c in commands if c.__name__[3:].replace('_', '-').startswith(pattern)]
78 if len(matches) == 0:
79 parser.print_help()
80 sys.exit(1)
81 if len(matches) > 1:
82 raise SafeException("What do you mean by '%s'?\n%s" %
83 (pattern, '\n'.join(['- ' + x.__name__[3:] for x in matches])))
84 matches[0](args[1:])
85 except KeyboardInterrupt, ex:
86 print >>sys.stderr, "Interrupted"
87 sys.exit(1)
88 except OSError, ex:
89 if options.verbose: raise
90 print >>sys.stderr, str(ex)
91 sys.exit(1)
92 except IOError, ex:
93 if options.verbose: raise
94 print >>sys.stderr, str(ex)
95 sys.exit(1)
96 except UsageError, ex:
97 print >>sys.stderr, str(ex)
98 print >>sys.stderr, "usage: " + os.path.basename(sys.argv[0]) + " " + matches[0].__doc__
99 sys.exit(1)
100 except SafeException, ex:
101 if options.verbose: raise
102 print >>sys.stderr, str(ex)
103 sys.exit(1)