aboutsummaryrefslogtreecommitdiff
blob: d74931803490aa85476327c6bf1bd1be2c44e22b (plain)
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
74
#!/usr/bin/python -O
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/bin/portageq,v 1.15 2004/12/07 15:06:41 jstubbs Exp $

import sys
sys.path = ["/usr/lib/portage/pym"]+sys.path

import portage,types, portageq


#-----------------------------------------------------------------------------
#
# DO NOT CHANGE CODE BEYOND THIS POINT - IT'S NOT NEEDED!
#

def usage():
	rev="$Revision: 1.15 $"
	ver=rev.split(' ')[1]
	print ">>> Portage information query tool -- version "+ver
	print ">>> Usage: portageq <command> [<option> ...]"
	print ""
	print "Available commands:"

	#
	# Show our commands -- we do this by scanning the functions in this
	# file, and formatting each functions documentation.
	#
	for name in dir(portageq):
		# Drop python stuff, modules, and our own support functions.
		if (name in ("usage", "__doc__", "__name__", "main", "os", "portage", "sys", "__builtins__", "types", "string")):
			continue

		# Drop non-functions
		obj = getattr(portageq,name)
		if  (type(obj) != types.FunctionType):
			continue

		doc = obj.__doc__
		if (doc == None):
			print "   "+name
			print "      MISSING DOCUMENTATION!"
			print ""
			continue

		lines = doc.split('\n')
		print "   "+name+" "+lines[0].strip()
		for line in lines[1:]:
			print "      "+line.strip()


def main():
	if (len(sys.argv) < 2):
		usage()
		sys.exit()
	
	cmd = sys.argv[1]
	try:
		function = getattr(portageq,cmd)
		e,s = function(sys.argv[2:])
		print s
		sys.exit(e)
	except KeyError:
		usage()
		sys.exit()
	except SystemExit:
		raise
	except Exception,e:
		sys.exit(1)

main()


#-----------------------------------------------------------------------------