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