3 from __future__
import print_function
6 from logging
import warn
8 locale
.setlocale(locale
.LC_ALL
, '')
10 warn('Error setting locale (eg. Invalid locale)')
16 from optparse
import OptionParser
18 from zeroinstall
import SafeException
20 from zeroinstall
.zerostore
import cli
, BadDigest
22 parser
= OptionParser(usage
="usage: %prog " +
23 '\n %prog '.join([c
.__doc
__ for c
in cli
.commands
]))
24 parser
.add_option("-v", "--verbose", help="more verbose output", action
='count')
25 parser
.add_option("-V", "--version", help="display version information", action
='store_true')
26 parser
.disable_interspersed_args()
28 (options
, args
) = parser
.parse_args()
31 logger
= logging
.getLogger()
32 if options
.verbose
== 1:
33 logger
.setLevel(logging
.INFO
)
35 logger
.setLevel(logging
.DEBUG
)
36 hdlr
= logging
.StreamHandler()
37 fmt
= logging
.Formatter("%(levelname)s:%(message)s")
38 hdlr
.setFormatter(fmt
)
39 logger
.addHandler(hdlr
)
43 print("0store (zero-install) " + zeroinstall
.version
)
44 print("Copyright (C) 2009 Thomas Leonard")
45 print("This program comes with ABSOLUTELY NO WARRANTY,")
46 print("to the extent permitted by law.")
47 print("You may redistribute copies of this program")
48 print("under the terms of the GNU Lesser General Public License.")
49 print("For more information about these matters, see the file named COPYING.")
59 pattern
= args
[0].lower()
60 matches
= [c
for c
in cli
.commands
if c
.__name
__[3:].startswith(pattern
)]
65 raise SafeException("What do you mean by '%s'?\n%s" %
66 (pattern
, '\n'.join(['- ' + x
.__name
__[3:] for x
in matches
])))
68 except KeyboardInterrupt as ex
:
69 print("Interrupted", file=sys
.stderr
)
72 if options
.verbose
: raise
73 print(str(ex
), file=sys
.stderr
)
76 if options
.verbose
: raise
77 print(str(ex
), file=sys
.stderr
)
79 except cli
.UsageError
as ex
:
80 print(str(ex
), file=sys
.stderr
)
81 print("usage: " + sys
.argv
[0] + " " + matches
[0].__doc
__, file=sys
.stderr
)
83 except SafeException
as ex
:
84 if options
.verbose
: raise
85 print(str(ex
), file=sys
.stderr
)