Moved --manifest to new 0store command.
[zeroinstall.git] / 0store
blob11cfacc1b12b860b2ed171c122d80e4b9edcfcfc
1 #!/usr/bin/env python
2 import os, sys
3 from optparse import OptionParser
4 import logging
6 from zeroinstall.zerostore import cli
8 parser = OptionParser(usage="usage: %prog " +
9 '\n %prog '.join([c.__doc__ for c in cli.commands]))
10 parser.add_option("-v", "--verbose", help="more verbose output", action='count')
11 parser.add_option("-V", "--version", help="display version information", action='store_true')
12 parser.disable_interspersed_args()
14 (options, args) = parser.parse_args()
16 if options.verbose:
17 logger = logging.getLogger()
18 if options.verbose == 1:
19 logger.setLevel(logging.INFO)
20 else:
21 logger.setLevel(logging.DEBUG)
22 hdlr = logging.StreamHandler()
23 fmt = logging.Formatter("%(levelname)s:%(message)s")
24 hdlr.setFormatter(fmt)
25 logger.addHandler(hdlr)
27 if options.version:
28 import zeroinstall
29 print "0store (zero-install) " + zeroinstall.version
30 print "Copyright (C) 2005 Thomas Leonard"
31 print "This program comes with ABSOLUTELY NO WARRANTY,"
32 print "to the extent permitted by law."
33 print "You may redistribute copies of this program"
34 print "under the terms of the GNU General Public License."
35 print "For more information about these matters, see the file named COPYING."
36 sys.exit(0)
38 if len(args) < 1:
39 parser.print_help()
40 sys.exit(1)
42 pattern = args[0].lower()
43 matches = [c for c in cli.commands if c.__name__.startswith(pattern)]
44 if len(matches) == 0:
45 parser.print_help()
46 sys.exit(1)
47 if len(matches) > 1:
48 print >>sys.stderr, "What do you mean by '%s'?" % pattern
49 for x in matches:
50 print "- " + x
51 sys.exit(1)
53 try:
54 matches[0](args[1:])
55 except KeyboardInterrupt, ex:
56 print >>sys.stderr, "Interrupted"
57 sys.exit(1)
58 except OSError, ex:
59 print >>sys.stderr, str(ex)
60 sys.exit(1)
61 except IOError, ex:
62 print >>sys.stderr, str(ex)
63 sys.exit(1)