From: Zac Medico Date: Sat, 10 Dec 2011 23:49:21 +0000 (-0800) Subject: data.py: avoid portage.settings when possible X-Git-Tag: v2.2.0_alpha80~6 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=54e4ab36340f1ef3ffa250132bc5458e3d77ab6d;p=portage.git data.py: avoid portage.settings when possible --- 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)