1 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
12 from mailer import Message
13 from config import config
16 def __init__(self, p, login):
22 if p.has_option(login, "gpg_emails"):
23 self.gpg_emails = string.split(p.get(login, "gpg_emails"))
25 log.panic("acl: [%s] has no gpg_emails" % login)
27 if p.has_option(login, "mailto"):
28 self.mailto = p.get(login, "mailto")
30 if len(self.gpg_emails) > 0:
31 self.mailto = self.gpg_emails[0]
33 if p.has_option(login, "privs"):
34 for p in string.split(p.get(login, "privs")):
35 l = string.split(p, ":")
38 if len(l) not in (2,3) or l[0] == "" or l[1] == "":
39 log.panic("acl: invalid priv format: '%s' [%s]" % (p, login))
43 log.panic("acl: [%s] has no privs" % login)
45 def can_do(self, what, where, branch=None):
47 action = "%s:%s:%s" % (what, where, branch)
49 action = "%s:%s:N-A" % (what, where)
50 for priv in self.privs:
56 pwhat,pwhere,pbranch=priv.split(":")
57 for pbranch in pbranch.split(","):
58 priv="%s:%s:%s" % (pwhat,pwhere,pbranch)
59 if fnmatch.fnmatch(action, priv):
63 def check_priority(self, prio, where):
64 for priv in self.privs:
65 val,builder=priv.split(":")[0:2]
66 if fnmatch.fnmatch(where, builder):
82 m.set_headers(to = self.mail_to(), cc = config.builder_list)
93 mtime = os.stat(path.acl_conf)[stat.ST_MTIME]
94 if mtime != self.acl_conf_mtime:
95 log.notice("acl.conf has changed, reloading...")
101 self.acl_conf_mtime = os.stat(path.acl_conf)[stat.ST_MTIME]
102 self.current_user = None
103 status.push("reading acl.conf")
104 p = ConfigParser.ConfigParser()
105 p.readfp(open(path.acl_conf))
107 for login in p.sections():
108 if self.users.has_key(login):
109 log.panic("acl: duplicate login: %s" % login)
111 user = User(p, login)
112 for e in user.gpg_emails:
113 if self.users.has_key(e):
114 log.panic("acl: user email colision %s <-> %s" % \
115 (self.users[e].login, login))
118 self.users[login] = user
121 def user_by_email(self, ems):
123 if self.users.has_key(e):
128 if not self.users.has_key(l):
129 log.panic("no such user: %s" % l)
132 def set_current_user(self, u):
133 self.current_user = u
135 status.email = u.mail_to()
137 def current_user_login(self):
138 if self.current_user != None:
139 return self.current_user.login