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 setup
, copysrc
, build
, publish
, gui
, bugs
, include_deps
34 parser
= OptionParser(usage
="usage: %prog " +
35 '\n %prog '.join([c
.__doc
__ for c
in commands
]))
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
)
67 pattern
= args
[0].lower()
68 matches
= [c
for c
in commands
if c
.__name
__[3:].replace('_', '-').startswith(pattern
)]
73 raise SafeException("What do you mean by '%s'?\n%s" %
74 (pattern
, '\n'.join(['- ' + x
.__name
__[3:] for x
in matches
])))
76 except KeyboardInterrupt, ex
:
77 print >>sys
.stderr
, "Interrupted"
80 if options
.verbose
: raise
81 print >>sys
.stderr
, str(ex
)
84 if options
.verbose
: raise
85 print >>sys
.stderr
, str(ex
)
87 except UsageError
, ex
:
88 print >>sys
.stderr
, str(ex
)
89 print >>sys
.stderr
, "usage: " + os
.path
.basename(sys
.argv
[0]) + " " + matches
[0].__doc
__
91 except SafeException
, ex
:
92 if options
.verbose
: raise
93 print >>sys
.stderr
, str(ex
)