3 from optparse
import OptionParser
5 from zeroinstall
import SafeException
7 from zeroinstall
.zerostore
import cli
, BadDigest
9 parser
= OptionParser(usage
="usage: %prog " +
10 '\n %prog '.join([c
.__doc
__ for c
in cli
.commands
]))
11 parser
.add_option("-v", "--verbose", help="more verbose output", action
='count')
12 parser
.add_option("-V", "--version", help="display version information", action
='store_true')
13 parser
.disable_interspersed_args()
15 (options
, args
) = parser
.parse_args()
18 logger
= logging
.getLogger()
19 if options
.verbose
== 1:
20 logger
.setLevel(logging
.INFO
)
22 logger
.setLevel(logging
.DEBUG
)
23 hdlr
= logging
.StreamHandler()
24 fmt
= logging
.Formatter("%(levelname)s:%(message)s")
25 hdlr
.setFormatter(fmt
)
26 logger
.addHandler(hdlr
)
30 print "0store (zero-install) " + zeroinstall
.version
31 print "Copyright (C) 2005 Thomas Leonard"
32 print "This program comes with ABSOLUTELY NO WARRANTY,"
33 print "to the extent permitted by law."
34 print "You may redistribute copies of this program"
35 print "under the terms of the GNU General Public License."
36 print "For more information about these matters, see the file named COPYING."
46 pattern
= args
[0].lower()
47 matches
= [c
for c
in cli
.commands
if c
.__name
__[3:].startswith(pattern
)]
52 raise SafeException("What do you mean by '%s'?\n%s" %
53 (pattern
, '\n'.join(['- ' + x
.__name
__[3:] for x
in matches
])))
55 except KeyboardInterrupt, ex
:
56 print >>sys
.stderr
, "Interrupted"
59 if options
.verbose
: raise
60 print >>sys
.stderr
, str(ex
)
63 if options
.verbose
: raise
64 print >>sys
.stderr
, str(ex
)
66 except cli
.UsageError
, ex
:
67 print >>sys
.stderr
, str(ex
)
68 print >>sys
.stderr
, "usage: " + sys
.argv
[0] + " " + matches
[0].__doc
__
70 except SafeException
, ex
:
71 if options
.verbose
: raise
72 print >>sys
.stderr
, str(ex
)