From 54e4ab36340f1ef3ffa250132bc5458e3d77ab6d Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sat, 10 Dec 2011 15:49:21 -0800 Subject: [PATCH] data.py: avoid portage.settings when possible --- pym/portage/data.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/pym/portage/data.py b/pym/portage/data.py index f17fd7326..a25b282ab 100644 --- a/pym/portage/data.py +++ b/pym/portage/data.py @@ -134,12 +134,24 @@ def _get_global(k): pass v = sorted(set(v)) + # Avoid instantiating portage.settings when the desired + # variable is set in os.environ. elif k == '_portage_grpname': - env = getattr(portage, 'settings', os.environ) - v = env.get('PORTAGE_GRPNAME', 'portage') + 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': - env = getattr(portage, 'settings', os.environ) - v = env.get('PORTAGE_USERNAME', 'portage') + v = None + if 'PORTAGE_USERNAME' in os.environ: + v = os.environ['PORTAGE_USERNAME'] + elif hasattr(portage, 'settings'): + v = portage.settings.get('PORTAGE_USERNAME') + if v is None: + v = 'portage' else: raise AssertionError('unknown name: %s' % k) -- 2.26.2