src/mercurialserver/ruleset.py
changeset 371 e9ce904b62a9
parent 311 3cbde66305e4
child 372 80f78674c56e
--- a/src/mercurialserver/ruleset.py	Wed Jul 23 14:31:59 2014 +0000
+++ b/src/mercurialserver/ruleset.py	Mon Nov 03 11:12:35 2014 +0100
@@ -31,6 +31,7 @@
     matchers = [(k, globmatcher(v)) for k, v in pairs]
     def c(kw):
         return min(rmatch(k, m, kw) for k, m in matchers)
+    c.patterns = [(k, m.pattern) for k, m in matchers]
     return c
 
 class Ruleset(object):
@@ -66,19 +67,28 @@
     def readfile(self, fn):
         f = open(fn)
         try:
-            for l in f:
-                l = l.strip()
-                if len(l) == 0 or l.startswith("#"):
-                    continue
-                l = l.split()
-                # Unrecognized actions are off the high end
-                if l[0] in self.levels:
-                    ix = self.levels.index(l[0])
-                else:
-                    ix = len(self.levels)
-                self.rules.append((ix,
-                    rule([c.split("=", 1) for c in l[1:]])))
+            self.buildrules(f)
         finally:
             f.close()
 
+    def buildrules(self, f):
+        """Build rules from f
+
+        f shoud be iterable per line, each line is like:
+
+        level [user=pattern] [repo=pattern] [file=pattern] [branch=pattern]
+        """
+        for l in f:
+            l = l.strip()
+            if not l or l.startswith("#"):
+                continue
+            l = l.split()
+            # Unrecognized actions are off the high end
+            if l[0] in self.levels:
+                ix = self.levels.index(l[0])
+            else:
+                ix = len(self.levels)
+            self.rules.append((ix,
+                rule([c.split("=", 1) for c in l[1:]])))
+
 rules = Ruleset()