summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2010-04-10 01:41:50 -0700
committerZac Medico <zmedico@gentoo.org>2010-04-10 01:41:50 -0700
commitb859a2d8beb7c4ad8730c19fca31993f66988d1f (patch)
tree6eaa7bd3d877b9d7acdf415c4976e627fc8b78ab
parentb0ed3c842d8dc882660fc4611c0fd9f79854721e (diff)
downloadportage-b859a2d8beb7c4ad8730c19fca31993f66988d1f.tar.gz
portage-b859a2d8beb7c4ad8730c19fca31993f66988d1f.tar.bz2
portage-b859a2d8beb7c4ad8730c19fca31993f66988d1f.zip
Make spawning of `id -G portage` happen lazily when userpriv_groups is first
accessed.
-rw-r--r--pym/portage/data.py39
1 files changed, 22 insertions, 17 deletions
diff --git a/pym/portage/data.py b/pym/portage/data.py
index 893663195..00fbec427 100644
--- a/pym/portage/data.py
+++ b/pym/portage/data.py
@@ -98,20 +98,25 @@ except KeyError:
else:
userpriv_groups = [portage_gid]
if secpass >= 2:
- # Get a list of group IDs for the portage user. Do not use
- # grp.getgrall() since it is known to trigger spurious
- # SIGPIPE problems with nss_ldap.
- try:
- from subprocess import getstatusoutput
- except ImportError:
- from commands import getstatusoutput
- mystatus, myoutput = getstatusoutput("id -G %s" % 'portage')
- if mystatus == os.EX_OK:
- for x in myoutput.split():
- try:
- userpriv_groups.append(int(x))
- except ValueError:
- pass
- del x
- userpriv_groups = list(set(userpriv_groups))
- del getstatusoutput, mystatus, myoutput
+ class _LazyUserprivGroups(portage.proxy.objectproxy.ObjectProxy):
+ def _get_target(self):
+ global userpriv_groups
+ if userpriv_groups is not self:
+ return userpriv_groups
+ userpriv_groups = _userpriv_groups
+ # Get a list of group IDs for the portage user. Do not use
+ # grp.getgrall() since it is known to trigger spurious
+ # SIGPIPE problems with nss_ldap.
+ mystatus, myoutput = \
+ portage.subprocess_getstatusoutput("id -G %s" % 'portage')
+ if mystatus == os.EX_OK:
+ for x in myoutput.split():
+ try:
+ userpriv_groups.append(int(x))
+ except ValueError:
+ pass
+ userpriv_groups[:] = sorted(set(userpriv_groups))
+ return userpriv_groups
+
+ _userpriv_groups = userpriv_groups
+ userpriv_groups = _LazyUserprivGroups()