aboutsummaryrefslogtreecommitdiff
path: root/gitosis
diff options
context:
space:
mode:
authorTommi Virtanen <tv@eagain.net>2007-06-04 14:22:48 +0300
committerTommi Virtanen <tv@eagain.net>2007-06-04 14:22:48 +0300
commit65dc130228fe3084a7a29aca8652a04d10379bdf (patch)
treebfc51977cf85d675e923de7bdfbc76eb26dea5b5 /gitosis
parentwriteAuthorizedKeys now reads old file by name, not by open file. (diff)
downloadgitosis-dakkar-65dc130228fe3084a7a29aca8652a04d10379bdf.tar.gz
gitosis-dakkar-65dc130228fe3084a7a29aca8652a04d10379bdf.tar.bz2
gitosis-dakkar-65dc130228fe3084a7a29aca8652a04d10379bdf.zip
Everyone always belongs to group "all".
Diffstat (limited to 'gitosis')
-rw-r--r--gitosis/group.py39
-rw-r--r--gitosis/test/test_group.py13
2 files changed, 37 insertions, 15 deletions
diff --git a/gitosis/group.py b/gitosis/group.py
index 0ecbb61..975bbc5 100644
--- a/gitosis/group.py
+++ b/gitosis/group.py
@@ -1,25 +1,15 @@
import logging
from ConfigParser import NoSectionError, NoOptionError
-def getMembership(config, user, _seen=None):
- """
- Generate groups ``user`` is member of, according to ``config``
-
- :type config: RawConfigParser
- :type user: str
- :param _seen: internal use only
- """
+def _getMembership(config, user, seen):
log = logging.getLogger('gitosis.group.getMembership')
- if _seen is None:
- _seen = set()
-
for section in config.sections():
GROUP_PREFIX = 'group '
if not section.startswith(GROUP_PREFIX):
continue
group = section[len(GROUP_PREFIX):]
- if group in _seen:
+ if group in seen:
continue
try:
@@ -34,9 +24,28 @@ def getMembership(config, user, _seen=None):
user=user,
group=group,
))
- _seen.add(group)
+ seen.add(group)
yield group
- for member_of in getMembership(config, '@%s' % group,
- _seen=_seen):
+ for member_of in _getMembership(
+ config, '@%s' % group, seen,
+ ):
yield member_of
+
+
+def getMembership(config, user):
+ """
+ Generate groups ``user`` is member of, according to ``config``
+
+ :type config: RawConfigParser
+ :type user: str
+ :param _seen: internal use only
+ """
+
+ seen = set()
+ for member_of in _getMembership(config, user, seen):
+ yield member_of
+
+ # everyone is always a member of group "all"
+ yield 'all'
+
diff --git a/gitosis/test/test_group.py b/gitosis/test/test_group.py
index c282661..9ea035a 100644
--- a/gitosis/test/test_group.py
+++ b/gitosis/test/test_group.py
@@ -7,12 +7,14 @@ from gitosis import group
def test_no_emptyConfig():
cfg = RawConfigParser()
gen = group.getMembership(config=cfg, user='jdoe')
+ eq(gen.next(), 'all')
assert_raises(StopIteration, gen.next)
def test_no_emptyGroup():
cfg = RawConfigParser()
cfg.add_section('group hackers')
gen = group.getMembership(config=cfg, user='jdoe')
+ eq(gen.next(), 'all')
assert_raises(StopIteration, gen.next)
def test_no_notListed():
@@ -20,6 +22,7 @@ def test_no_notListed():
cfg.add_section('group hackers')
cfg.set('group hackers', 'members', 'wsmith')
gen = group.getMembership(config=cfg, user='jdoe')
+ eq(gen.next(), 'all')
assert_raises(StopIteration, gen.next)
def test_yes_simple():
@@ -28,6 +31,7 @@ def test_yes_simple():
cfg.set('group hackers', 'members', 'jdoe')
gen = group.getMembership(config=cfg, user='jdoe')
eq(gen.next(), 'hackers')
+ eq(gen.next(), 'all')
assert_raises(StopIteration, gen.next)
def test_yes_leading():
@@ -36,6 +40,7 @@ def test_yes_leading():
cfg.set('group hackers', 'members', 'jdoe wsmith')
gen = group.getMembership(config=cfg, user='jdoe')
eq(gen.next(), 'hackers')
+ eq(gen.next(), 'all')
assert_raises(StopIteration, gen.next)
def test_yes_trailing():
@@ -44,6 +49,7 @@ def test_yes_trailing():
cfg.set('group hackers', 'members', 'wsmith jdoe')
gen = group.getMembership(config=cfg, user='jdoe')
eq(gen.next(), 'hackers')
+ eq(gen.next(), 'all')
assert_raises(StopIteration, gen.next)
def test_yes_middle():
@@ -52,6 +58,7 @@ def test_yes_middle():
cfg.set('group hackers', 'members', 'wsmith jdoe danny')
gen = group.getMembership(config=cfg, user='jdoe')
eq(gen.next(), 'hackers')
+ eq(gen.next(), 'all')
assert_raises(StopIteration, gen.next)
def test_yes_recurse_one():
@@ -63,6 +70,7 @@ def test_yes_recurse_one():
gen = group.getMembership(config=cfg, user='jdoe')
eq(gen.next(), 'smackers')
eq(gen.next(), 'hackers')
+ eq(gen.next(), 'all')
assert_raises(StopIteration, gen.next)
def test_yes_recurse_one_ordering():
@@ -74,6 +82,7 @@ def test_yes_recurse_one_ordering():
gen = group.getMembership(config=cfg, user='jdoe')
eq(gen.next(), 'smackers')
eq(gen.next(), 'hackers')
+ eq(gen.next(), 'all')
assert_raises(StopIteration, gen.next)
def test_yes_recurse_three():
@@ -91,6 +100,7 @@ def test_yes_recurse_three():
eq(gen.next(), 'snackers')
eq(gen.next(), 'smackers')
eq(gen.next(), 'hackers')
+ eq(gen.next(), 'all')
assert_raises(StopIteration, gen.next)
def test_yes_recurse_junk():
@@ -102,6 +112,7 @@ def test_yes_recurse_junk():
gen = group.getMembership(config=cfg, user='jdoe')
eq(gen.next(), 'smackers')
eq(gen.next(), 'hackers')
+ eq(gen.next(), 'all')
assert_raises(StopIteration, gen.next)
def test_yes_recurse_loop():
@@ -113,6 +124,7 @@ def test_yes_recurse_loop():
gen = group.getMembership(config=cfg, user='jdoe')
eq(gen.next(), 'smackers')
eq(gen.next(), 'hackers')
+ eq(gen.next(), 'all')
assert_raises(StopIteration, gen.next)
def test_no_recurse_loop():
@@ -122,4 +134,5 @@ def test_no_recurse_loop():
cfg.add_section('group smackers')
cfg.set('group smackers', 'members', '@hackers')
gen = group.getMembership(config=cfg, user='jdoe')
+ eq(gen.next(), 'all')
assert_raises(StopIteration, gen.next)