aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2011-12-21 12:55:56 -0800
committerZac Medico <zmedico@gentoo.org>2011-12-21 12:55:56 -0800
commit962f4d5387aa19b2a9a4cf41370000c849ff587d (patch)
treed90880c7d4f059b4b62560236bcfb75a4036f44b /pym/portage/data.py
parents/QA_STRICT_DT_SWITCHES/QA_STRICT_CFLAGS_IGNORED/ (diff)
downloadportage-962f4d5387aa19b2a9a4cf41370000c849ff587d.tar.gz
portage-962f4d5387aa19b2a9a4cf41370000c849ff587d.tar.bz2
portage-962f4d5387aa19b2a9a4cf41370000c849ff587d.zip
data.py: stat EROOT for PORTAGE_GRPNAME/USERNAME
The config class has equivalent code, but we also need to do it here if _disable_legacy_globals() has been called.
Diffstat (limited to 'pym/portage/data.py')
-rw-r--r--pym/portage/data.py48
1 files changed, 36 insertions, 12 deletions
diff --git a/pym/portage/data.py b/pym/portage/data.py
index ec750a611..c4d967a1b 100644
--- a/pym/portage/data.py
+++ b/pym/portage/data.py
@@ -141,20 +141,44 @@ def _get_global(k):
# Avoid instantiating portage.settings when the desired
# variable is set in os.environ.
- elif k == '_portage_grpname':
+ elif k in ('_portage_grpname', '_portage_username'):
v = None
- if 'PORTAGE_GRPNAME' in os.environ:
- v = os.environ['PORTAGE_GRPNAME']
- elif hasattr(portage, 'settings'):
- v = portage.settings.get('PORTAGE_GRPNAME')
- if v is None:
- v = 'portage'
- elif k == '_portage_username':
- v = None
- if 'PORTAGE_USERNAME' in os.environ:
- v = os.environ['PORTAGE_USERNAME']
+ if k == '_portage_grpname':
+ env_key = 'PORTAGE_GRPNAME'
+ else:
+ env_key = 'PORTAGE_USERNAME'
+
+ if env_key in os.environ:
+ v = os.environ[env_key]
elif hasattr(portage, 'settings'):
- v = portage.settings.get('PORTAGE_USERNAME')
+ v = portage.settings.get(env_key)
+ elif portage.const.EPREFIX:
+ # For prefix environments, default to the UID and GID of
+ # the top-level EROOT directory. The config class has
+ # equivalent code, but we also need to do it here if
+ # _disable_legacy_globals() has been called.
+ eroot = os.path.join(os.environ.get('ROOT', os.sep),
+ portage.const.EPREFIX.lstrip(os.sep))
+ try:
+ eroot_st = os.stat(eroot)
+ except OSError:
+ pass
+ else:
+ if k == '_portage_grpname':
+ try:
+ grp_struct = grp.getgrgid(eroot_st.st_gid)
+ except KeyError:
+ pass
+ else:
+ v = grp_struct.gr_name
+ else:
+ try:
+ pwd_struct = pwd.getpwuid(eroot_st.st_uid)
+ except KeyError:
+ pass
+ else:
+ v = pwd_struct.pw_name
+
if v is None:
v = 'portage'
else: