summaryrefslogtreecommitdiff
blob: 6b991a4682cb54fa2c296ed42a57e18454595834 (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
#!/usr/bin/env python2

""" Helper module to print a list of needed keywords provided a list of cpv.

Can be tweaked to either compute keyword request from a list of defined arches or from older revisions available stable keywords.
"""

import os
import sys

import portage

from pprint import pprint

ARCH_GNOME=['alpha', 'amd64', 'arm', 'hppa', 'ia64', 'ppc', 'ppc64', 'sh', 'sparc', 'x86']
ARCH_DEV=["mips", "amd64-fbsd", "sparc-fbsd", "x86-fbsd"]
ARCH_EXP=["ppc-aix", "x86-freebsd", "x64-freebsd", "hppa-hpux", "ia64-hpux", "x86-interix", "mips-irix", "amd64-linux", "arm-linux", "ia64-linux", "x86-linux", "ppc-macos", "x86-macos", "x64-macos", "m68k-mint", "x86-netbsd", "ppc-openbsd", "x86-openbsd", "x64-openbsd", "sparc-solaris", "sparc64-solaris", "x64-solaris", "x86-solaris", "x86-winnt"]

def package_sort(item1, item2):
	""" Sort revisions """

	return portage.dep.pkgcmp(portage.dep.pkgsplit(item1), portage.dep.pkgsplit(item2))

def main():
	""" Main function """

	api = portage.portdbapi()
	api._aux_cache_keys.clear()
	api._aux_cache_keys.update(["EAPI", "KEYWORDS", "SLOT"])

	root = '/'
	trees = {
		root : {'porttree' : portage.portagetree(root)}
	}
	portdb = trees[root]['porttree'].dbapi
	#portdb._aux_cache_keys.clear()
	#portdb._aux_cache_keys.update(["EAPI", "KEYWORDS", "SLOT"])

	#pprint(api.porttrees)

	for atom in sys.argv:

		arches = {}
		keywords = {}
		best_revision = {}
		need_keyword = {}
		revisions = api.cp_list(atom, mytree=api.porttrees[0])
		rev_keywords = {}
		max_arch_list = []

		# Select best revision
		revisions.sort(package_sort)

		# Build maximum possible arches list
		for revision in revisions:
			# print revision

			aux_kw, slot = api.aux_get(revision, ['KEYWORDS', 'SLOT'])
			aux_kw = [kw for kw in aux_kw.replace('~', '').split() if kw and not kw.startswith('-') and kw not in ARCH_DEV and kw not in ARCH_EXP]

			# Build best set of keywords per SLOT
			for kw in aux_kw:
				if slot in keywords:
					if kw not in keywords[slot]:
						keywords[slot].append(kw)
				else:
					keywords[slot] = [kw]

			if not keywords or not slot in keywords:
				revisions.remove(revision)
			else:
				if revision.endswith("9999"):
					revisions.remove(revision)
					continue
				best_revision[slot] = revision
				keywords[slot] = ARCH_GNOME
				need_keyword[slot] = [kw for kw in keywords[slot] if kw not in aux_kw]

		# Show missing arches
		for slot in keywords:
			if need_keyword[slot]:
#				keycheck_incrementals = tuple(x for x in portage.const.INCREMENTALS if x != 'ACCEPT_KEYWORDS')
				# for package.use.mask support inside dep_check
#				dep_settings = portage.config(
#					config_incrementals = keycheck_incrementals,
#					local_config = False)
#				dep_settings.setcpv(revision)
#				dep_settings["ACCEPT_KEYWORDS"] = " ".join(keywords[slot] + need_keyword[slot])
#
#				for dep_type in ('DEPEND', 'RDEPEND', 'PDEPEND'):
#					aux_dep = api.aux_get(revision, [dep_type])[0]
#					print portage.dep_check(aux_dep, portdb, dep_settings, use='all', trees=trees, mode='minimum-visible')
#

				kw_print = ""
				for kw in ARCH_GNOME:
					kw_print += " "
					if kw in need_keyword[slot]:
						kw_print += kw
					else:
						kw_print += " " * len(kw)

				print "%-60s:" % best_revision[slot], kw_print
			

if __name__ == "__main__":
	main()