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)
13 sys
.path
.insert(1, zeroinstall_dir
)
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
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
30 import autocompile
, setup
, clean
, copysrc
, build
, publish
, gui
, bugs
, include_deps
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()
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."
58 logger
= logging
.getLogger()
59 if options
.verbose
== 1:
60 logger
.setLevel(logging
.INFO
)
62 logger
.setLevel(logging
.DEBUG
)
65 support
.launch_prog
.append('--console')
72 pattern
= args
[0].lower()
73 matches
= [c
for c
in commands
if c
.__name
__[3:].replace('_', '-').startswith(pattern
)]
78 raise SafeException("What do you mean by '%s'?\n%s" %
79 (pattern
, '\n'.join(['- ' + x
.__name
__[3:] for x
in matches
])))
81 except KeyboardInterrupt, ex
:
82 print >>sys
.stderr
, "Interrupted"
85 if options
.verbose
: raise
86 print >>sys
.stderr
, str(ex
)
89 if options
.verbose
: raise
90 print >>sys
.stderr
, str(ex
)
92 except UsageError
, ex
:
93 print >>sys
.stderr
, str(ex
)
94 print >>sys
.stderr
, "usage: " + os
.path
.basename(sys
.argv
[0]) + " " + matches
[0].__doc
__
96 except SafeException
, ex
:
97 if options
.verbose
: raise
98 print >>sys
.stderr
, str(ex
)