Updated test for new GNU Hello
[0compile.git] / 0compile
blob613666b805f5c994dd609f659843633da39ec6d7
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 from optparse import OptionParser
8 import os, sys, tempfile, shutil, traceback
9 from logging import info, debug
11 zeroinstall_dir = os.environ.get('0COMPILE_ZEROINSTALL', None)
12 if zeroinstall_dir:
13 sys.path.insert(1, zeroinstall_dir)
15 import zeroinstall
17 if map(int, zeroinstall.version.split('.')) < [0, 24]:
18 print >>sys.stderr, "Your version of 0launch (%s) is too old. " \
19 "I need version 0.24 or later." % zeroinstall.version
20 sys.exit(1)
22 from zeroinstall.injector import model, arch, run
23 from zeroinstall.injector.policy import Policy
24 from zeroinstall import SafeException
26 class UsageError(SafeException): pass
28 commands = []
30 import autocompile, setup, clean, copysrc, build, publish, gui, bugs, include_deps
32 version = '0.19.1'
34 parser = OptionParser(usage="usage: %prog " +
35 '\n %prog '.join([c.__doc__ for c in commands]))
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 len(args) < 1:
63 parser.print_help()
64 sys.exit(1)
66 try:
67 pattern = args[0].lower()
68 matches = [c for c in commands if c.__name__[3:].replace('_', '-').startswith(pattern)]
69 if len(matches) == 0:
70 parser.print_help()
71 sys.exit(1)
72 if len(matches) > 1:
73 raise SafeException("What do you mean by '%s'?\n%s" %
74 (pattern, '\n'.join(['- ' + x.__name__[3:] for x in matches])))
75 matches[0](args[1:])
76 except KeyboardInterrupt, ex:
77 print >>sys.stderr, "Interrupted"
78 sys.exit(1)
79 except OSError, ex:
80 if options.verbose: raise
81 print >>sys.stderr, str(ex)
82 sys.exit(1)
83 except IOError, ex:
84 if options.verbose: raise
85 print >>sys.stderr, str(ex)
86 sys.exit(1)
87 except UsageError, ex:
88 print >>sys.stderr, str(ex)
89 print >>sys.stderr, "usage: " + os.path.basename(sys.argv[0]) + " " + matches[0].__doc__
90 sys.exit(1)
91 except SafeException, ex:
92 if options.verbose: raise
93 print >>sys.stderr, str(ex)
94 sys.exit(1)