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