data.py: tweak getgrnam call for PyPy
authorZac Medico <zmedico@gentoo.org>
Fri, 16 Dec 2011 03:11:53 +0000 (19:11 -0800)
committerZac Medico <zmedico@gentoo.org>
Fri, 16 Dec 2011 03:11:53 +0000 (19:11 -0800)
This makes it unnecessary to explicitly call portage.data._init() in
runTests, and fixes some other cases that trigger the same issue.

pym/portage/data.py
pym/portage/tests/runTests

index cf94ab0cde7233d36fe0560f98d9bfb00e0f1b4d..ec750a611d942961cc2474efd21d8190fd8c7906 100644 (file)
@@ -87,7 +87,12 @@ def _get_global(k):
                #Discover the uid and gid of the portage user/group
                try:
                        portage_uid = pwd.getpwnam(_get_global('_portage_username')).pw_uid
-                       portage_gid = grp.getgrnam(_get_global('_portage_grpname')).gr_gid
+                       _portage_grpname = _get_global('_portage_grpname')
+                       if platform.python_implementation() == 'PyPy':
+                               # Somehow this prevents "TypeError: expected string" errors
+                               # from grp.getgrnam() with PyPy 1.7
+                               _portage_grpname = str(_portage_grpname)
+                       portage_gid = grp.getgrnam(_portage_grpname).gr_gid
                        if secpass < 1 and portage_gid in os.getgroups():
                                secpass = 1
                except KeyError:
index 0c476b3eb17f99c2e618e371b97cd1df72ffa126..4c10087084183233959772fbb618261362d51104 100755 (executable)
@@ -30,10 +30,6 @@ import portage
 # work the same regardless of global configuration file state/existence.
 portage._disable_legacy_globals()
 
-# Somehow this prevents "TypeError: expected string" errors
-# from grp.getgrnam() with PyPy 1.7
-portage.data._init(os.environ)
-
 import portage.tests as tests
 from portage.const import PORTAGE_BIN_PATH
 path = os.environ.get("PATH", "").split(":")