4 from logging
import warn
6 locale
.setlocale(locale
.LC_ALL
, '')
8 warn('Error setting locale (eg. Invalid locale)')
11 from optparse
import OptionParser
13 from zeroinstall
import SafeException
15 from zeroinstall
.zerostore
import cli
, BadDigest
17 parser
= OptionParser(usage
="usage: %prog " +
18 '\n %prog '.join([c
.__doc
__ for c
in cli
.commands
]))
19 parser
.add_option("-v", "--verbose", help="more verbose output", action
='count')
20 parser
.add_option("-V", "--version", help="display version information", action
='store_true')
21 parser
.disable_interspersed_args()
23 (options
, args
) = parser
.parse_args()
26 logger
= logging
.getLogger()
27 if options
.verbose
== 1:
28 logger
.setLevel(logging
.INFO
)
30 logger
.setLevel(logging
.DEBUG
)
31 hdlr
= logging
.StreamHandler()
32 fmt
= logging
.Formatter("%(levelname)s:%(message)s")
33 hdlr
.setFormatter(fmt
)
34 logger
.addHandler(hdlr
)
38 print "0store (zero-install) " + zeroinstall
.version
39 print "Copyright (C) 2009 Thomas Leonard"
40 print "This program comes with ABSOLUTELY NO WARRANTY,"
41 print "to the extent permitted by law."
42 print "You may redistribute copies of this program"
43 print "under the terms of the GNU Lesser General Public License."
44 print "For more information about these matters, see the file named COPYING."
54 pattern
= args
[0].lower()
55 matches
= [c
for c
in cli
.commands
if c
.__name
__[3:].startswith(pattern
)]
60 raise SafeException("What do you mean by '%s'?\n%s" %
61 (pattern
, '\n'.join(['- ' + x
.__name
__[3:] for x
in matches
])))
63 except KeyboardInterrupt, ex
:
64 print >>sys
.stderr
, "Interrupted"
67 if options
.verbose
: raise
68 print >>sys
.stderr
, str(ex
)
71 if options
.verbose
: raise
72 print >>sys
.stderr
, str(ex
)
74 except cli
.UsageError
, ex
:
75 print >>sys
.stderr
, str(ex
)
76 print >>sys
.stderr
, "usage: " + sys
.argv
[0] + " " + matches
[0].__doc
__
78 except SafeException
, ex
:
79 if options
.verbose
: raise
80 print >>sys
.stderr
, str(ex
)