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
11 import gobject
; gobject
.threads_init()
13 zeroinstall_dir
= os
.environ
.get('0COMPILE_ZEROINSTALL', None)
15 sys
.path
.insert(1, zeroinstall_dir
)
17 from zeroinstall
import SafeException
19 class UsageError(SafeException
): pass
23 import autocompile
, setup
, clean
, copysrc
, build
, publish
, gui
, bugs
, include_deps
29 locale
.setlocale(locale
.LC_ALL
, '')
31 warn('Error setting locale (eg. Invalid locale)')
33 parser
= OptionParser(usage
="usage: %prog " +
34 '\n %prog '.join([c
.__doc
__ for c
in commands
]))
36 parser
.add_option("-c", "--console", help="never use GUI", action
='store_true')
37 parser
.add_option("-v", "--verbose", help="more verbose output", action
='count')
38 parser
.add_option("-V", "--version", help="display version information", action
='store_true')
40 parser
.disable_interspersed_args()
42 (options
, args
) = parser
.parse_args()
45 print "0compile (zero-install) " + version
46 print "Copyright (C) 2006 Thomas Leonard"
47 print "This program comes with ABSOLUTELY NO WARRANTY,"
48 print "to the extent permitted by law."
49 print "You may redistribute copies of this program"
50 print "under the terms of the GNU General Public License."
51 print "For more information about these matters, see the file named COPYING."
56 logger
= logging
.getLogger()
57 if options
.verbose
== 1:
58 logger
.setLevel(logging
.INFO
)
60 logger
.setLevel(logging
.DEBUG
)
63 support
.launch_prog
.append('--console')
70 pattern
= args
[0].lower()
71 matches
= [c
for c
in commands
if c
.__name
__[3:].replace('_', '-').startswith(pattern
)]
76 raise SafeException("What do you mean by '%s'?\n%s" %
77 (pattern
, '\n'.join(['- ' + x
.__name
__[3:] for x
in matches
])))
79 except KeyboardInterrupt, ex
:
80 print >>sys
.stderr
, "Interrupted"
83 if options
.verbose
: raise
84 print >>sys
.stderr
, str(ex
)
87 if options
.verbose
: raise
88 print >>sys
.stderr
, str(ex
)
90 except UsageError
, ex
:
91 print >>sys
.stderr
, str(ex
)
92 print >>sys
.stderr
, "usage: " + os
.path
.basename(sys
.argv
[0]) + " " + matches
[0].__doc
__
94 except SafeException
, ex
:
95 if options
.verbose
: raise
97 print >>sys
.stderr
, unicode(ex
)
99 print >>sys
.stderr
, repr(ex
)