Gentoo Archives: gentoo-commits

From: Zac Medico <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/
Date: Wed, 21 Dec 2011 20:56:16
Message-Id: 962f4d5387aa19b2a9a4cf41370000c849ff587d.zmedico@gentoo
1 commit: 962f4d5387aa19b2a9a4cf41370000c849ff587d
2 Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
3 AuthorDate: Wed Dec 21 20:55:56 2011 +0000
4 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
5 CommitDate: Wed Dec 21 20:55:56 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=962f4d53
7
8 data.py: stat EROOT for PORTAGE_GRPNAME/USERNAME
9
10 The config class has equivalent code, but we also need to do it here if
11 _disable_legacy_globals() has been called.
12
13 ---
14 pym/portage/data.py | 48 ++++++++++++++++++++++++++++++++++++------------
15 1 files changed, 36 insertions(+), 12 deletions(-)
16
17 diff --git a/pym/portage/data.py b/pym/portage/data.py
18 index ec750a6..c4d967a 100644
19 --- a/pym/portage/data.py
20 +++ b/pym/portage/data.py
21 @@ -141,20 +141,44 @@ def _get_global(k):
22
23 # Avoid instantiating portage.settings when the desired
24 # variable is set in os.environ.
25 - elif k == '_portage_grpname':
26 + elif k in ('_portage_grpname', '_portage_username'):
27 v = None
28 - if 'PORTAGE_GRPNAME' in os.environ:
29 - v = os.environ['PORTAGE_GRPNAME']
30 - elif hasattr(portage, 'settings'):
31 - v = portage.settings.get('PORTAGE_GRPNAME')
32 - if v is None:
33 - v = 'portage'
34 - elif k == '_portage_username':
35 - v = None
36 - if 'PORTAGE_USERNAME' in os.environ:
37 - v = os.environ['PORTAGE_USERNAME']
38 + if k == '_portage_grpname':
39 + env_key = 'PORTAGE_GRPNAME'
40 + else:
41 + env_key = 'PORTAGE_USERNAME'
42 +
43 + if env_key in os.environ:
44 + v = os.environ[env_key]
45 elif hasattr(portage, 'settings'):
46 - v = portage.settings.get('PORTAGE_USERNAME')
47 + v = portage.settings.get(env_key)
48 + elif portage.const.EPREFIX:
49 + # For prefix environments, default to the UID and GID of
50 + # the top-level EROOT directory. The config class has
51 + # equivalent code, but we also need to do it here if
52 + # _disable_legacy_globals() has been called.
53 + eroot = os.path.join(os.environ.get('ROOT', os.sep),
54 + portage.const.EPREFIX.lstrip(os.sep))
55 + try:
56 + eroot_st = os.stat(eroot)
57 + except OSError:
58 + pass
59 + else:
60 + if k == '_portage_grpname':
61 + try:
62 + grp_struct = grp.getgrgid(eroot_st.st_gid)
63 + except KeyError:
64 + pass
65 + else:
66 + v = grp_struct.gr_name
67 + else:
68 + try:
69 + pwd_struct = pwd.getpwuid(eroot_st.st_uid)
70 + except KeyError:
71 + pass
72 + else:
73 + v = pwd_struct.pw_name
74 +
75 if v is None:
76 v = 'portage'
77 else: