New release.
[0compile.git] / 0compile
blob74f14813e568f042fc8069a29d4752621776490d
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
10 import zeroinstall
12 if map(int, zeroinstall.version.split('.')) < [0, 24]:
13 print >>sys.stderr, "Your version of 0launch (%s) is too old. " \
14 "I need version 0.24 or later." % zeroinstall.version
15 sys.exit(1)
17 from zeroinstall.injector import model, arch, run
18 from zeroinstall.injector.policy import Policy
19 from zeroinstall import SafeException
21 class UsageError(SafeException): pass
23 commands = []
25 import setup, copysrc, build, publish, gui, bugs
27 version = '0.9'
29 parser = OptionParser(usage="usage: %prog " +
30 '\n %prog '.join([c.__doc__ for c in commands]))
32 parser.add_option("-v", "--verbose", help="more verbose output", action='count')
33 parser.add_option("-V", "--version", help="display version information", action='store_true')
35 parser.disable_interspersed_args()
37 (options, args) = parser.parse_args()
39 if options.version:
40 print "0compile (zero-install) " + version
41 print "Copyright (C) 2006 Thomas Leonard"
42 print "This program comes with ABSOLUTELY NO WARRANTY,"
43 print "to the extent permitted by law."
44 print "You may redistribute copies of this program"
45 print "under the terms of the GNU General Public License."
46 print "For more information about these matters, see the file named COPYING."
47 sys.exit(0)
49 if options.verbose:
50 import logging
51 logger = logging.getLogger()
52 if options.verbose == 1:
53 logger.setLevel(logging.INFO)
54 else:
55 logger.setLevel(logging.DEBUG)
57 if len(args) < 1:
58 parser.print_help()
59 sys.exit(1)
61 try:
62 pattern = args[0].lower()
63 matches = [c for c in commands if c.__name__[3:].replace('_', '-').startswith(pattern)]
64 if len(matches) == 0:
65 parser.print_help()
66 sys.exit(1)
67 if len(matches) > 1:
68 raise SafeException("What do you mean by '%s'?\n%s" %
69 (pattern, '\n'.join(['- ' + x.__name__[3:] for x in matches])))
70 matches[0](args[1:])
71 except KeyboardInterrupt, ex:
72 print >>sys.stderr, "Interrupted"
73 sys.exit(1)
74 except OSError, ex:
75 if options.verbose: raise
76 print >>sys.stderr, str(ex)
77 sys.exit(1)
78 except IOError, ex:
79 if options.verbose: raise
80 print >>sys.stderr, str(ex)
81 sys.exit(1)
82 except UsageError, ex:
83 print >>sys.stderr, str(ex)
84 print >>sys.stderr, "usage: " + os.path.basename(sys.argv[0]) + " " + matches[0].__doc__
85 sys.exit(1)
86 except SafeException, ex:
87 if options.verbose: raise
88 print >>sys.stderr, str(ex)
89 sys.exit(1)