1 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
4 if sys.version_info[0] == 2:
7 import configparser as ConfigParser
16 from mailer import Message
17 from config import config
20 def __init__(self, p, login):
25 self.change_requester = False
27 if p.has_option(login, "gpg_emails"):
28 self.gpg_emails = p.get(login, "gpg_emails").split()
30 log.panic("acl: [%s] has no gpg_emails" % login)
32 if p.has_option(login, "mailto"):
33 self.mailto = p.get(login, "mailto")
35 if len(self.gpg_emails) > 0:
36 self.mailto = self.gpg_emails[0]
38 if p.has_option(login, "change_requester"):
39 self.change_requester = True
41 if p.has_option(login, "privs"):
42 for p in p.get(login, "privs").split():
46 if len(l) not in (2,3) or l[0] == "" or l[1] == "":
47 log.panic("acl: invalid priv format: '%s' [%s]" % (p, login))
51 log.panic("acl: [%s] has no privs" % login)
53 def can_do(self, what, where, branch=None):
55 action = "%s:%s:%s" % (what, where, branch)
57 action = "%s:%s:N-A" % (what, where)
58 for priv in self.privs:
64 pwhat,pwhere,pbranch=priv.split(":")
65 for pbranch in pbranch.split(","):
66 priv="%s:%s:%s" % (pwhat,pwhere,pbranch)
67 if fnmatch.fnmatch(action, priv):
71 def check_priority(self, prio, where):
72 for priv in self.privs:
73 val,builder=priv.split(":")[0:2]
74 if fnmatch.fnmatch(where, builder):
90 m.set_headers(to = self.mail_to(), cc = config.builder_list)
100 def try_reload(self):
101 mtime = os.stat(path.acl_conf)[stat.ST_MTIME]
102 if mtime != self.acl_conf_mtime:
103 log.notice("acl.conf has changed, reloading...")
109 self.acl_conf_mtime = os.stat(path.acl_conf)[stat.ST_MTIME]
110 self.current_user = None
111 status.push("reading acl.conf")
112 p = ConfigParser.ConfigParser()
113 p.readfp(open(path.acl_conf))
115 for login in p.sections():
116 if login in self.users:
117 log.panic("acl: duplicate login: %s" % login)
119 user = User(p, login)
120 for e in user.gpg_emails:
122 log.panic("acl: user email colision %s <-> %s" % \
123 (self.users[e].login, login))
126 self.users[login] = user
129 def user_by_email(self, ems):
135 def user_by_login(self, l):
139 if not l in self.users:
140 log.panic("no such user: %s" % l)
143 def set_current_user(self, u):
144 self.current_user = u
146 status.email = u.mail_to()
148 def current_user_login(self):
149 if self.current_user != None:
150 return self.current_user.login