2 # Copyright (C) 2006, Thomas Leonard
3 # See the README file for details, or visit http://0install.net.
5 __builtins__
._ = lambda x
: x
8 from optparse
import OptionParser
10 from logging
import warn
12 zeroinstall_dir
= os
.environ
.get('0COMPILE_ZEROINSTALL', None)
14 sys
.path
.insert(1, zeroinstall_dir
)
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
23 from zeroinstall
import SafeException
25 class UsageError(SafeException
): pass
29 import autocompile
, setup
, clean
, copysrc
, build
, publish
, gui
, bugs
, include_deps
35 locale
.setlocale(locale
.LC_ALL
, '')
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()
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."
62 logger
= logging
.getLogger()
63 if options
.verbose
== 1:
64 logger
.setLevel(logging
.INFO
)
66 logger
.setLevel(logging
.DEBUG
)
69 support
.launch_prog
.append('--console')
76 pattern
= args
[0].lower()
77 matches
= [c
for c
in commands
if c
.__name
__[3:].replace('_', '-').startswith(pattern
)]
82 raise SafeException("What do you mean by '%s'?\n%s" %
83 (pattern
, '\n'.join(['- ' + x
.__name
__[3:] for x
in matches
])))
85 except KeyboardInterrupt, ex
:
86 print >>sys
.stderr
, "Interrupted"
89 if options
.verbose
: raise
90 print >>sys
.stderr
, str(ex
)
93 if options
.verbose
: raise
94 print >>sys
.stderr
, str(ex
)
96 except UsageError
, ex
:
97 print >>sys
.stderr
, str(ex
)
98 print >>sys
.stderr
, "usage: " + os
.path
.basename(sys
.argv
[0]) + " " + matches
[0].__doc
__
100 except SafeException
, ex
:
101 if options
.verbose
: raise
102 print >>sys
.stderr
, str(ex
)