src/ruleset.py
changeset 39 f5055ce263c7
parent 33 18e93dbdaf12
child 45 59dee3c04279
--- a/src/ruleset.py	Thu Feb 19 16:36:41 2009 +0000
+++ b/src/ruleset.py	Thu Feb 19 17:51:06 2009 +0000
@@ -7,6 +7,8 @@
 
 import sys
 import re
+import os
+import os.path
 
 allowedchars = "A-Za-z0-9_-"
 
@@ -74,9 +76,7 @@
         a = self.matchrule(**kw)
         return a in self.levels and self.levels.index(a) <= self.levels.index(level)
     
-    @classmethod
-    def readfile(cls, fn):
-        res = cls()
+    def readfile(self, fn):
         try:
             f = open(fn)
             try:
@@ -85,11 +85,16 @@
                     if len(l) == 0 or l.startswith("#"):
                         continue
                     l = l.split()
-                    res.add(l[0], rule([c.split("=", 1) for c in l[1:]]))
+                    self.add(l[0], rule([c.split("=", 1) for c in l[1:]]))
             finally:
                 f.close()
         except Exception, e:
             print >> sys.stderr, "Failure reading rules file:", e
-            return cls()
-        return res
 
+def rules_from_env():
+    res = Ruleset()
+    for f in os.environ['HG_ACCESS_RULES_PATH'].split(os.pathsep):
+        if os.path.isfile(f):
+            res.readfile(f)
+    return res
+