File: 0store

package info (click to toggle)
zeroinstall-injector 0.34-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,048 kB
  • ctags: 1,236
  • sloc: python: 10,189; xml: 167; makefile: 34; sh: 16
file content (73 lines) | stat: -rwxr-xr-x 2,194 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python
import os, sys
from optparse import OptionParser
import logging
from zeroinstall import SafeException

from zeroinstall.zerostore import cli, BadDigest

parser = OptionParser(usage="usage: %prog " + 
			  '\n       %prog '.join([c.__doc__ for c in cli.commands]))
parser.add_option("-v", "--verbose", help="more verbose output", action='count')
parser.add_option("-V", "--version", help="display version information", action='store_true')
parser.disable_interspersed_args()

(options, args) = parser.parse_args()

if options.verbose:
	logger = logging.getLogger()
	if options.verbose == 1:
		logger.setLevel(logging.INFO)
	else:
		logger.setLevel(logging.DEBUG)
        hdlr = logging.StreamHandler()
        fmt = logging.Formatter("%(levelname)s:%(message)s")
        hdlr.setFormatter(fmt)
        logger.addHandler(hdlr)

if options.version:
	import zeroinstall
	print "0store (zero-install) " + zeroinstall.version
	print "Copyright (C) 2007 Thomas Leonard"
	print "This program comes with ABSOLUTELY NO WARRANTY,"
	print "to the extent permitted by law."
	print "You may redistribute copies of this program"
	print "under the terms of the GNU Lesser General Public License."
	print "For more information about these matters, see the file named COPYING."
	sys.exit(0)

if len(args) < 1:
	parser.print_help()
	sys.exit(1)

try:
	cli.init_stores()

	pattern = args[0].lower()
	matches = [c for c in cli.commands if c.__name__[3:].startswith(pattern)]
	if len(matches) == 0:
		parser.print_help()
		sys.exit(1)
	if len(matches) > 1:
		raise SafeException("What do you mean by '%s'?\n%s" %
			(pattern, '\n'.join(['- ' + x.__name__[3:] for x in matches])))
	matches[0](args[1:])
except KeyboardInterrupt, ex:
	print >>sys.stderr, "Interrupted"
	sys.exit(1)
except OSError, ex:
	if options.verbose: raise
	print >>sys.stderr, str(ex)
	sys.exit(1)
except IOError, ex:
	if options.verbose: raise
	print >>sys.stderr, str(ex)
	sys.exit(1)
except cli.UsageError, ex:
	print >>sys.stderr, str(ex)
	print >>sys.stderr, "usage: " + sys.argv[0] + " " + matches[0].__doc__
	sys.exit(1)
except SafeException, ex:
	if options.verbose: raise
	print >>sys.stderr, str(ex)
	sys.exit(1)