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
12 if map(int, zeroinstall
.version
.split('.')) < [0, 24]:
13 print >>sys
.stderr
, "Your version of 0launch (%s) is too old. " \
14 "I need version 0.24 or later." % zeroinstall
.version
17 from zeroinstall
.injector
import model
, arch
, run
18 from zeroinstall
.injector
.policy
import Policy
19 from zeroinstall
import SafeException
21 class UsageError(SafeException
): pass
25 import setup
, copysrc
, build
, publish
, gui
, bugs
29 parser
= OptionParser(usage
="usage: %prog " +
30 '\n %prog '.join([c
.__doc
__ for c
in commands
]))
32 parser
.add_option("-v", "--verbose", help="more verbose output", action
='count')
33 parser
.add_option("-V", "--version", help="display version information", action
='store_true')
35 parser
.disable_interspersed_args()
37 (options
, args
) = parser
.parse_args()
40 print "0compile (zero-install) " + version
41 print "Copyright (C) 2006 Thomas Leonard"
42 print "This program comes with ABSOLUTELY NO WARRANTY,"
43 print "to the extent permitted by law."
44 print "You may redistribute copies of this program"
45 print "under the terms of the GNU General Public License."
46 print "For more information about these matters, see the file named COPYING."
51 logger
= logging
.getLogger()
52 if options
.verbose
== 1:
53 logger
.setLevel(logging
.INFO
)
55 logger
.setLevel(logging
.DEBUG
)
62 pattern
= args
[0].lower()
63 matches
= [c
for c
in commands
if c
.__name
__[3:].replace('_', '-').startswith(pattern
)]
68 raise SafeException("What do you mean by '%s'?\n%s" %
69 (pattern
, '\n'.join(['- ' + x
.__name
__[3:] for x
in matches
])))
71 except KeyboardInterrupt, ex
:
72 print >>sys
.stderr
, "Interrupted"
75 if options
.verbose
: raise
76 print >>sys
.stderr
, str(ex
)
79 if options
.verbose
: raise
80 print >>sys
.stderr
, str(ex
)
82 except UsageError
, ex
:
83 print >>sys
.stderr
, str(ex
)
84 print >>sys
.stderr
, "usage: " + os
.path
.basename(sys
.argv
[0]) + " " + matches
[0].__doc
__
86 except SafeException
, ex
:
87 if options
.verbose
: raise
88 print >>sys
.stderr
, str(ex
)