aboutsummaryrefslogtreecommitdiff
blob: 9dced08a79e0db6bbb2a0d8ba998df065e5ec6b8 (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
#!/usr/bin/env python
# Copyright 1999-2008 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $
#
# Zac Medico <zmedico@gentoo.org>
#

import os
import sys
from itertools import izip

def vdb_to_fake_binrepo():

	metadata_keys = ["CATEGORY", "CHOST", "DEPEND",
		"EAPI", "IUSE", "KEYWORDS", "LICENSE", "PF",
		"PROVIDE", "RDEPEND", "PDEPEND", "SLOT", "USE"]

	import portage
	try:
		from portage import xpak
		from portage.util import ensure_dirs
	except ImportError:
		import xpak
		from portage_util import ensure_dirs

	root = portage.settings["ROOT"]
	vartree = portage.db[root]["vartree"]
	bintree = portage.db[root]["bintree"]

	for cpv in vartree.dbapi.cpv_all():
		bintree.prevent_collision(cpv)
		metadata = dict(izip(metadata_keys,
			vartree.dbapi.aux_get(cpv, metadata_keys)))
		xpdata = xpak.xpak_mem(metadata)
		binpkg_tmpfile = os.path.join(bintree.pkgdir,
			cpv + ".tbz2." + str(os.getpid()))
		ensure_dirs(os.path.dirname(binpkg_tmpfile))
		xpak.tbz2(binpkg_tmpfile).recompose_mem(xpdata)
		binpkg_path = bintree.getname(cpv)
		ensure_dirs(os.path.dirname(binpkg_path))
		os.rename(binpkg_tmpfile, binpkg_path)
		bintree.inject(cpv)

def main():
	description = "This program uses the currently installed packages to" + \
		" populate $PKGDIR with a fake binary package repository that is " + \
		"suitable for dependency calculations."
	usage = "usage: %s" % os.path.basename(sys.argv[0])
	from optparse import OptionParser
	parser = OptionParser(description=description, usage=usage)
	options, args = parser.parse_args(args=sys.argv[1:])
	vdb_to_fake_binrepo()

if __name__ == '__main__':
	try:
		main()
	except KeyboardInterrupt:
		print "Interrupted."
		sys.exit(1)