Avoid KeyError if PORTAGE_USERNAME or PORTAGE_GRPNAME are unset.
authorZac Medico <zmedico@gentoo.org>
Sun, 15 Aug 2010 08:05:26 +0000 (01:05 -0700)
committerZac Medico <zmedico@gentoo.org>
Sun, 15 Aug 2010 08:05:26 +0000 (01:05 -0700)
pym/portage/tests/resolver/ResolverPlayground.py

index 64cd6f1dbe69bc211c4bda0bca56f1be01801aab..b713c652ccecded52f2131a0aa0c434c55070011 100644 (file)
@@ -198,17 +198,20 @@ class ResolverPlayground(object):
                f.close()
 
        def _load_config(self):
-               # Pass along PORTAGE_USERNAME and PORTAGE_GRPNAME since they
-               # need to be inherited by ebuild subprocesses.
                env = {
                        "ACCEPT_KEYWORDS": "x86",
                        "PORTDIR": self.portdir,
                        "ROOT": self.root,
                        'PORTAGE_TMPDIR'       : os.path.join(self.root, 'var/tmp'),
-                       'PORTAGE_USERNAME'     : os.environ["PORTAGE_USERNAME"],
-                       'PORTAGE_GRPNAME'      : os.environ["PORTAGE_GRPNAME"],
                }
 
+               # Pass along PORTAGE_USERNAME and PORTAGE_GRPNAME since they
+               # need to be inherited by ebuild subprocesses.
+               if 'PORTAGE_USERNAME' in os.environ:
+                       env['PORTAGE_USERNAME'] = os.environ['PORTAGE_USERNAME']
+               if 'PORTAGE_GRPNAME' in os.environ:
+                       env['PORTAGE_GRPNAME'] = os.environ['PORTAGE_GRPNAME']
+
                settings = config(config_root=self.root, target_root=self.root, env=env)
                settings.lock()