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
)
16 from zeroinstall
import SafeException
18 class UsageError(SafeException
): pass
22 import autocompile
, setup
, clean
, copysrc
, build
, publish
, gui
, bugs
, include_deps
28 locale
.setlocale(locale
.LC_ALL
, '')
30 warn('Error setting locale (eg. Invalid locale)')
32 parser
= OptionParser(usage
="usage: %prog " +
33 '\n %prog '.join([c
.__doc
__ for c
in commands
]))
35 parser
.add_option("-c", "--console", help="never use GUI", action
='store_true')
36 parser
.add_option("-v", "--verbose", help="more verbose output", action
='count')
37 parser
.add_option("-V", "--version", help="display version information", action
='store_true')
39 parser
.disable_interspersed_args()
41 (options
, args
) = parser
.parse_args()
44 print "0compile (zero-install) " + version
45 print "Copyright (C) 2006 Thomas Leonard"
46 print "This program comes with ABSOLUTELY NO WARRANTY,"
47 print "to the extent permitted by law."
48 print "You may redistribute copies of this program"
49 print "under the terms of the GNU General Public License."
50 print "For more information about these matters, see the file named COPYING."
55 logger
= logging
.getLogger()
56 if options
.verbose
== 1:
57 logger
.setLevel(logging
.INFO
)
59 logger
.setLevel(logging
.DEBUG
)
62 support
.launch_prog
.append('--console')
69 pattern
= args
[0].lower()
70 matches
= [c
for c
in commands
if c
.__name
__[3:].replace('_', '-').startswith(pattern
)]
75 raise SafeException("What do you mean by '%s'?\n%s" %
76 (pattern
, '\n'.join(['- ' + x
.__name
__[3:] for x
in matches
])))
78 except KeyboardInterrupt, ex
:
79 print >>sys
.stderr
, "Interrupted"
82 if options
.verbose
: raise
83 print >>sys
.stderr
, str(ex
)
86 if options
.verbose
: raise
87 print >>sys
.stderr
, str(ex
)
89 except UsageError
, ex
:
90 print >>sys
.stderr
, str(ex
)
91 print >>sys
.stderr
, "usage: " + os
.path
.basename(sys
.argv
[0]) + " " + matches
[0].__doc
__
93 except SafeException
, ex
:
94 if options
.verbose
: raise
96 print >>sys
.stderr
, unicode(ex
)
98 print >>sys
.stderr
, repr(ex
)