Fixed test to put binary in DISTDIR
[0compile.git] / 0compile
blob475b794287a504ae15e860aefb8e4232d0f2b36e
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
31 import support
33 version = '0.21'
35 parser = OptionParser(usage="usage: %prog " +
36 '\n %prog '.join([c.__doc__ for c in commands]))
38 parser.add_option("-c", "--console", help="never use GUI", action='store_true')
39 parser.add_option("-v", "--verbose", help="more verbose output", action='count')
40 parser.add_option("-V", "--version", help="display version information", action='store_true')
42 parser.disable_interspersed_args()
44 (options, args) = parser.parse_args()
46 if options.version:
47 print "0compile (zero-install) " + version
48 print "Copyright (C) 2006 Thomas Leonard"
49 print "This program comes with ABSOLUTELY NO WARRANTY,"
50 print "to the extent permitted by law."
51 print "You may redistribute copies of this program"
52 print "under the terms of the GNU General Public License."
53 print "For more information about these matters, see the file named COPYING."
54 sys.exit(0)
56 if options.verbose:
57 import logging
58 logger = logging.getLogger()
59 if options.verbose == 1:
60 logger.setLevel(logging.INFO)
61 else:
62 logger.setLevel(logging.DEBUG)
64 if options.console:
65 support.launch_prog.append('--console')
67 if len(args) < 1:
68 parser.print_help()
69 sys.exit(1)
71 try:
72 pattern = args[0].lower()
73 matches = [c for c in commands if c.__name__[3:].replace('_', '-').startswith(pattern)]
74 if len(matches) == 0:
75 parser.print_help()
76 sys.exit(1)
77 if len(matches) > 1:
78 raise SafeException("What do you mean by '%s'?\n%s" %
79 (pattern, '\n'.join(['- ' + x.__name__[3:] for x in matches])))
80 matches[0](args[1:])
81 except KeyboardInterrupt, ex:
82 print >>sys.stderr, "Interrupted"
83 sys.exit(1)
84 except OSError, ex:
85 if options.verbose: raise
86 print >>sys.stderr, str(ex)
87 sys.exit(1)
88 except IOError, ex:
89 if options.verbose: raise
90 print >>sys.stderr, str(ex)
91 sys.exit(1)
92 except UsageError, ex:
93 print >>sys.stderr, str(ex)
94 print >>sys.stderr, "usage: " + os.path.basename(sys.argv[0]) + " " + matches[0].__doc__
95 sys.exit(1)
96 except SafeException, ex:
97 if options.verbose: raise
98 print >>sys.stderr, str(ex)
99 sys.exit(1)