summaryrefslogtreecommitdiff
blob: bdeba351dc91e6107b0096337b0c84e9337b80f9 (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
# Copyright 2010 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

import portage
from portage import os
from portage.const import CACHE_PATH, PROFILE_PATH

def _get_legacy_global(name):
	constructed = portage._legacy_globals_constructed
	if name in constructed:
		return getattr(portage, name)

	if name == 'portdb':
		portage.portdb = portage.db[portage.root]["porttree"].dbapi
		constructed.add(name)
		return getattr(portage, name)

	elif name in ('mtimedb', 'mtimedbfile'):
		portage.mtimedbfile = os.path.join(portage.root,
			CACHE_PATH, "mtimedb")
		constructed.add('mtimedbfile')
		portage.mtimedb = portage.MtimeDB(portage.mtimedbfile)
		constructed.add('mtimedb')
		return getattr(portage, name)

	# Portage needs to ensure a sane umask for the files it creates.
	os.umask(0o22)

	kwargs = {}
	for k, envvar in (("config_root", "PORTAGE_CONFIGROOT"), ("target_root", "ROOT")):
		kwargs[k] = os.environ.get(envvar, "/")

	portage._initializing_globals = True
	portage.db = portage.create_trees(**kwargs)
	constructed.add('db')
	del portage._initializing_globals

	settings = portage.db["/"]["vartree"].settings

	for root in portage.db:
		if root != "/":
			settings = portage.db[root]["vartree"].settings
			break

	portage.output._init(config_root=settings['PORTAGE_CONFIGROOT'])

	portage.settings = settings
	constructed.add('settings')

	portage.root = root
	constructed.add('root')

	# COMPATIBILITY
	# These attributes should not be used within
	# Portage under any circumstances.

	portage.archlist = settings.archlist()
	constructed.add('archlist')

	portage.features = settings.features
	constructed.add('features')

	portage.groups = settings["ACCEPT_KEYWORDS"].split()
	constructed.add('groups')

	portage.pkglines = settings.packages
	constructed.add('pkglines')

	portage.selinux_enabled = settings.selinux_enabled()
	constructed.add('selinux_enabled')

	portage.thirdpartymirrors = settings.thirdpartymirrors()
	constructed.add('thirdpartymirrors')

	portage.usedefaults = settings.use_defs
	constructed.add('usedefaults')

	profiledir = os.path.join(settings["PORTAGE_CONFIGROOT"], PROFILE_PATH)
	if not os.path.isdir(profiledir):
		profiledir = None
	portage.profiledir = profiledir
	constructed.add('profiledir')

	return getattr(portage, name)