Commits

php committed 707f973

Initial commit

  • Participants

Comments (0)

Files changed (2)

php/__init__.py

Empty file added.
+import urllib
+import fnmatch
+from mercurial import util
+
+class Karma (object):
+    def __init__(self, filename):
+        self._accesslines = self.load(filename)
+
+    def load(self, filename):
+        fctx = open(filename, 'r')
+        lines = fctx.readlines()
+        fctx.close()
+        return lines
+
+    def allowed(self, user, path):
+        bit = 0
+        allowed = False
+        for l in self._accesslines:
+            mode = False
+            (avail, sep, rest) = l.partition('|')
+            if avail == "unavail":
+                mode = False
+            elif avail == "avail":
+                mode = True
+            else:
+                continue
+
+            (userlist, sep, modules) = rest.partition("|")
+            if user in userlist.strip().split(',') or len(userlist.strip()) == 0:
+                if len(modules.strip()) == 0:
+                    allowed = mode
+                else:
+                    for module in modules.strip().split(','):
+                        if fnmatch.fnmatch(path, module + '*'):
+                            allowed = mode
+        return allowed
+
+def checkkarma(ui, repo, source, node, **kwargs):
+    user = False
+    if source == 'serve' and 'url' in kwargs:
+        url = kwargs['url'].split(':')
+        if url[0] == 'remote' and url[1].startswith('http'):
+            user = urllib.unquote(url[3])
+    if not user:
+        util.Abort("not authorized")
+
+    karma = Karma("/home/dsp/dev/php/SVNROOT/global_avail")
+    ctx = repo[node]
+    allowed = True
+    for fctx in ctx.files():
+        allowed = allowed and karma.allowed(user, fctx)
+
+    if allowed:
+        return False # This will cause the changegroup toe pass
+    ui.warn("insufficient karma\n")
+    return True # This will cause an rollback