summaryrefslogtreecommitdiff
blob: ad6b72167051e71d4b663affeb7f2122510b602b (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/usr/bin/python -O
# Copyright 1999-2003 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2
# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/pym/portageq.py,v 1.2 2004/12/05 13:35:59 ferringb Exp $

# this is the core portageq functionality, stuck in a module so ebuild_daemon can use it.
# bin/portageq doesn't currently use this, but should for the sake of reduction of code
# duplication.

import portage,types,string


#-----------------------------------------------------------------------------
#
# To add functionality to this tool, add a function below.
#
# The format for functions is:
#
#   def function(argv):
#       """<list of options for this function>
#       <description of the function>
#       """
#       <code>
#
# "argv" is an array of the command line parameters provided after the command.
#
# Make sure you document the function in the right format.  The documentation
# is used to display help on the function.
#
# You do not need to add the function to any lists, this tool is introspective,
# and will automaticly add a command by the same name as the function!
#


def has_version(argv):
	"""<root> <category/package>
	Return code 0 if it's available, 1 otherwise.
	"""
	if (len(argv) < 2):
		print "ERROR: insufficient parameters!"
		raise Exception
	try:
		mylist=portage.db[argv[0]]["vartree"].dbapi.match(argv[1])
		if mylist:
			return 0, ""
		else:
			return 1, ""
	except KeyError:
		return 1, ""


def best_version(argv):
	"""<root> <category/package>
	Returns category/package-version (without .ebuild).
	"""
	if (len(argv) < 2):
		print "ERROR: insufficient parameters!"
		raise Exception
	try:
		mylist=portage.db[argv[0]]["vartree"].dbapi.match(argv[1])
		return 0, portage.best(mylist)
	except KeyError:
		return 1, ""


def mass_best_version(argv):
	"""<root> [<category/package>]+
	Returns category/package-version (without .ebuild).
	"""
	if (len(argv) < 2):
		print "ERROR: insufficient parameters!"
		raise Exception
	try:
		s=''
		for pack in argv[1:]:
			mylist=portage.db[argv[0]]["vartree"].dbapi.match(pack)
			s += "%s:%s\n" % (pack, portage.best(mylist))
		return 0, s
	except KeyError:
		return 1, ""


def best_visible(argv):
	"""<root> [<category/package>]+
	Returns category/package-version (without .ebuild).
	"""
	if (len(argv) < 2):
		raise Exception("insufficient parameters")
	try:
		mylist=portage.db[argv[0]]["porttree"].dbapi.match(argv[1])
		return 0, portage.best(mylist)
	except KeyError:
		return 1, ""


def mass_best_visible(argv):
	"""<root> [<category/package>]+
	Returns category/package-version (without .ebuild).
	"""
	if (len(argv) < 2):
		print "ERROR: insufficient parameters!"
		raise Exception
	try:
		s=''
		for pack in argv[1:]:
			mylist=portage.db[argv[0]]["porttree"].dbapi.match(pack)
			s += "%s:%s\n" % (pack, portage.best(mylist))
		return 0,s
	except KeyError:
		return 1, ''


def all_best_visible(argv):
	"""<root>
	Returns all best_visible packages (without .ebuild).
	"""
	if (len(argv) < 1):
		print "ERROR: insufficient parameters!"
		raise Exception("ERROR: insufficient parameters!")
	
	#print portage.db[argv[0]]["porttree"].dbapi.cp_all()
	s=''
	for pkg in portage.db[argv[0]]["porttree"].dbapi.cp_all():
		mybest=portage.best(portage.db[argv[0]]["porttree"].dbapi.match(pkg))
		if mybest:
			s += mybest +"\n"
	return 0,s

def match(argv):
	"""<root> <category/package>
	Returns \n seperated list of category/package-version
	"""
	if (len(argv) < 2):
		print "ERROR: insufficient parameters!"
		raise Exception
	try:
		return 0, string.join(portage.db[argv[0]]["vartree"].dbapi.match(argv[1]),"\n")
	except KeyError:
		return 1,''


def vdb_path(argv):
	"""
	Returns the path used for the var(installed) package database for the
	set environment/configuration options.
	"""
	return 0, portage.root+portage.VDB_PATH+"\n"

def gentoo_mirrors(argv):
	"""
	Returns the mirrors set to use in the portage configuration.
	"""
	return 0,portage.settings["GENTOO_MIRRORS"]+"\n"


def portdir(argv):
	"""
	Returns the PORTDIR path as defined in the portage configuration.
	"""
	return 0, portage.settings["PORTDIR"]+"\n"


def config_protect(argv):
	"""
	Returns the CONFIG_PROTECT paths as defined in the portage configuration.
	"""
	return 0, portage.settings["PORTDIR"]+"\n"


def config_protect_mask(argv):
	"""
	Returns the CONFIG_PROTECT_MASK paths as defined in the portage configuration.
	"""
	return 0, portage.settings["CONFIG_PROTECT_MASK"]+"\n"


def portdir_overlay(argv):
	"""
	Returns the PORTDIR_OVERLAY path as defined in the portage configuration.
	"""
	return 0, portage.settings["PORTDIR_OVERLAY"]+"\n"


def pkgdir(argv):
	"""
	Returns the PKGDIR path as defined in the portage configuration.
	"""
	return 0, portage.settings["PKGDIR"]+"\n"


def distdir(argv):
	"""
	Returns the DISTDIR path as defined in the portage configuration.
	"""
	return 0, portage.settings["DISTDIR"]+"\n"


def envvar(argv):
	"""<variable>
	Returns a specific environment variable as exists prior to ebuild.sh.
	Similar to: emerge --verbose --info | egrep '^<variable>='
	"""
	return 0, portage.settings[argv[0]]+"\n"