From: Ansgar Burchardt Date: Mon, 17 Sep 2012 16:29:36 +0000 (+0200) Subject: Merge branch 'pu/backports-merge' X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=3f0972f87f2dc1c63773eaf1c7d5e4caa81aa109;hp=50349d329a1a6453b7fbe158bcb22a2f71f60b98;p=dak.git Merge branch 'pu/backports-merge' --- diff --git a/config/debian/dak.conf b/config/debian/dak.conf index e326354a..82a76cb7 100644 --- a/config/debian/dak.conf +++ b/config/debian/dak.conf @@ -374,3 +374,8 @@ Generate-Releases experimental; }; } + +ByGroup { + ftpteam ""; + backports "/srv/ftp-master.debian.org/dak/config/debian/dak.conf-backports"; +}; diff --git a/config/debian/dak.conf-backports b/config/debian/dak.conf-backports new file mode 100644 index 00000000..361909da --- /dev/null +++ b/config/debian/dak.conf-backports @@ -0,0 +1,15 @@ +Dir { + Log "/srv/ftp-master.debian.org/log/backports/"; + Lock "/srv/ftp-master.debian.org/lock/backports/"; +}; + +Rm { + LogFile "/srv/backports-web.debian.org/underlay/removals.txt"; + LogFile822 "/srv/backports-web.debian.org/underlay/removals.822"; +}; + +Process-New +{ + DinstallLockFile "/srv/ftp-master.debian.org/lock/backports/processnew.lock"; + LockDir "/srv/ftp-master.debian.org/lock/backports/new/"; +}; diff --git a/dak/admin.py b/dak/admin.py index 798aa3b7..8ba79797 100755 --- a/dak/admin.py +++ b/dak/admin.py @@ -556,6 +556,8 @@ def show_config(command): print "PGPORT=%s" % cnf["DB::Port"] e.append('PGPORT') print "export " + " ".join(e) + elif mode == 'get': + print cnf.get(args[2]) else: session = DBConn().session() try: diff --git a/dak/dakdb/update88.py b/dak/dakdb/update88.py new file mode 100644 index 00000000..08d29065 --- /dev/null +++ b/dak/dakdb/update88.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python +# coding=utf8 + +""" +add per-suite mail whitelists + +@contact: Debian FTP Master +@copyright: 2012 Ansgar Burchardt +@license: GNU General Public License version 2 or later +""" + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +################################################################################ + +import psycopg2 +from daklib.dak_exceptions import DBUpdateError +from daklib.config import Config + +################################################################################ +def do_update(self): + print __doc__ + try: + cnf = Config() + + c = self.db.cursor() + + c.execute("ALTER TABLE suite ADD COLUMN mail_whitelist TEXT"); + + c.execute("UPDATE config SET value = '88' WHERE name = 'db_revision'") + self.db.commit() + + except psycopg2.ProgrammingError as msg: + self.db.rollback() + raise DBUpdateError('Unable to apply sick update 88, rollback issued. Error message: {0}'.format(msg)) diff --git a/dak/rm.py b/dak/rm.py index e4f4a6cb..ec36bf4e 100755 --- a/dak/rm.py +++ b/dak/rm.py @@ -210,6 +210,7 @@ def main (): # Additional suite checks suite_ids_list = [] + whitelists = [] suites = utils.split_args(Options["Suite"]) suites_list = utils.join_with_commas_and(suites) if not Options["No-Action"]: @@ -217,6 +218,7 @@ def main (): s = get_suite(suite, session=session) if s is not None: suite_ids_list.append(s.suite_id) + whitelists.append(s.mail_whitelist) if suite in ("oldstable", "stable"): print "**WARNING** About to remove from the (old)stable suite!" print "This should only be done just prior to a (point) release and not at" @@ -498,7 +500,7 @@ def main (): mail_message = utils.TemplateSubst(Subst_close_rm,cnf["Dir::Templates"]+"/rm.bug-close-with-related") else: mail_message = utils.TemplateSubst(Subst_close_rm,cnf["Dir::Templates"]+"/rm.bug-close") - utils.send_mail(mail_message) + utils.send_mail(mail_message, whitelists=whitelists) # close associated bug reports if Options["Do-Close"]: diff --git a/dak/update_db.py b/dak/update_db.py index 9dc613ae..a27c32e7 100755 --- a/dak/update_db.py +++ b/dak/update_db.py @@ -46,7 +46,7 @@ from daklib.daklog import Logger ################################################################################ Cnf = None -required_database_schema = 87 +required_database_schema = 88 ################################################################################ diff --git a/daklib/announce.py b/daklib/announce.py index 6c0fd374..fdc3e468 100644 --- a/daklib/announce.py +++ b/daklib/announce.py @@ -87,9 +87,13 @@ def _subst_for_upload(upload): return subst +def _whitelists(upload): + return [ s.mail_whitelist for s in upload.suites ] + def announce_reject(upload, reason, rejected_by=None): cnf = Config() subst = _subst_for_upload(upload) + whitelists = _whitelists(upload) automatic = rejected_by is None @@ -103,11 +107,12 @@ def announce_reject(upload, reason, rejected_by=None): subst['__BCC__'] = '{0}\nBcc: {1}'.format(subst['__BCC__'], cnf['Dinstall::MyEmailAddress']) message = TemplateSubst(subst, os.path.join(cnf['Dir::Templates'], 'queue.rejected')) - send_mail(message) + send_mail(message, whitelists=whitelists) def announce_accept(upload): cnf = Config() subst = _subst_for_upload(upload) + whitelists = _whitelists(upload) accepted_to_real_suite = any(suite.policy_queue is None or suite in upload.from_policy_suites for suite in upload.suites) @@ -121,7 +126,7 @@ def announce_accept(upload): subst['__SUITE__'] = ', '.join(suite_names) or '(none)' message = TemplateSubst(subst, os.path.join(cnf['Dir::Templates'], 'process-unchecked.accepted')) - send_mail(message) + send_mail(message, whitelists=whitelists) if accepted_to_real_suite and upload.sourceful: # senf mail to announce lists and tracking server @@ -141,7 +146,7 @@ def announce_accept(upload): my_subst['__ANNOUNCE_LIST_ADDRESS__'] = announce_list_address message = TemplateSubst(my_subst, os.path.join(cnf['Dir::Templates'], 'process-unchecked.announce')) - send_mail(message) + send_mail(message, whitelists=whitelists) close_bugs_default = cnf.find_b('Dinstall::CloseBugs') close_bugs = any(s.close_bugs if s.close_bugs is not None else close_bugs_default for s in upload.suites) @@ -151,11 +156,12 @@ def announce_accept(upload): my_subst['__BUG_NUMBER__'] = str(bug) message = TemplateSubst(my_subst, os.path.join(cnf['Dir::Templates'], 'process-unchecked.bug-close')) - send_mail(message) + send_mail(message, whitelists=whitelists) def announce_new(upload): cnf = Config() subst = _subst_for_upload(upload) + whitelists = _whitelists(upload) message = TemplateSubst(subst, os.path.join(cnf['Dir::Templates'], 'process-unchecked.new')) - send_mail(message) + send_mail(message, whitelists=whitelists) diff --git a/daklib/config.py b/daklib/config.py index 65874250..339604a1 100755 --- a/daklib/config.py +++ b/daklib/config.py @@ -28,6 +28,7 @@ Config access class ################################################################################ +import grp import os import apt_pkg import socket @@ -76,6 +77,19 @@ class Config(object): if conffile: apt_pkg.read_config_file_isc(self.Cnf, conffile) + # Read group-specific options + if 'ByGroup' in self.Cnf: + bygroup = self.Cnf.subtree('ByGroup') + groups = set([os.getgid()]) + groups.update(os.getgroups()) + + for group in bygroup.list(): + gid = grp.getgrnam(group).gr_gid + if gid in groups: + if bygroup.get(group): + apt_pkg.read_config_file_isc(self.Cnf, bygroup[group]) + break + # Rebind some functions # TODO: Clean this up self.get = self.Cnf.get diff --git a/daklib/queue.py b/daklib/queue.py index 547972ed..9dd2702c 100644 --- a/daklib/queue.py +++ b/daklib/queue.py @@ -104,6 +104,7 @@ def check_valid(overrides, session): def prod_maintainer(notes, upload): cnf = Config() changes = upload.changes + whitelists = [ upload.target_suite.mail_whitelist ] # Here we prepare an editor and get them ready to prod... (fd, temp_filename) = utils.temp_filename() @@ -154,7 +155,7 @@ def prod_maintainer(notes, upload): Subst,cnf["Dir::Templates"]+"/process-new.prod") # Send the prod mail - utils.send_mail(prod_mail_message) + utils.send_mail(prod_mail_message, whitelists=whitelists) print "Sent prodding message" diff --git a/daklib/utils.py b/daklib/utils.py index 63d8f471..1034628e 100755 --- a/daklib/utils.py +++ b/daklib/utils.py @@ -43,6 +43,7 @@ import email as modemail import subprocess import ldap +import daklib.config as config from dbconn import DBConn, get_architecture, get_component, get_suite, \ get_override_type, Keyring, session_wrapper, \ get_active_keyring_paths, get_primary_keyring_path, \ @@ -603,8 +604,16 @@ def build_package_list(dsc, session = None): ################################################################################ -def send_mail (message, filename=""): - """sendmail wrapper, takes _either_ a message string or a file as arguments""" +def send_mail (message, filename="", whitelists=None): + """sendmail wrapper, takes _either_ a message string or a file as arguments + + @type whitelists: list of (str or None) + @param whitelists: path to whitelists. C{None} or an empty list whitelists + everything, otherwise an address is whitelisted if it is + included in any of the lists. + In addition a global whitelist can be specified in + Dinstall::MailWhiteList. + """ maildir = Cnf.get('Dir::Mail') if maildir: @@ -624,23 +633,24 @@ def send_mail (message, filename=""): os.write (fd, message) os.close (fd) - if Cnf.has_key("Dinstall::MailWhiteList") and \ - Cnf["Dinstall::MailWhiteList"] != "": + if whitelists is None or None in whitelists: + whitelists = [] + if Cnf.get('Dinstall::MailWhiteList', ''): + whitelists.append(Cnf['Dinstall::MailWhiteList']) + if len(whitelists) != 0: message_in = open_file(filename) message_raw = modemail.message_from_file(message_in) message_in.close(); whitelist = []; - whitelist_in = open_file(Cnf["Dinstall::MailWhiteList"]) - try: + for path in whitelists: + with open_file(path, 'r') as whitelist_in: for line in whitelist_in: if not re_whitespace_comment.match(line): if re_re_mark.match(line): whitelist.append(re.compile(re_re_mark.sub("", line.strip(), 1))) else: whitelist.append(re.compile(re.escape(line.strip()))) - finally: - whitelist_in.close() # Fields to check. fields = ["To", "Bcc", "Cc"] @@ -657,7 +667,7 @@ def send_mail (message, filename=""): mail_whitelisted = 1 break if not mail_whitelisted: - print "Skipping %s since it's not in %s" % (item, Cnf["Dinstall::MailWhiteList"]) + print "Skipping {0} since it's not whitelisted".format(item) continue match.append(item) @@ -1542,14 +1552,7 @@ def get_changes_files(from_dir): ################################################################################ -apt_pkg.init() - -Cnf = apt_pkg.Configuration() -if not os.getenv("DAK_TEST"): - apt_pkg.read_config_file_isc(Cnf,default_config) - -if which_conf_file() != default_config: - apt_pkg.read_config_file_isc(Cnf,which_conf_file()) +Cnf = config.Config().Cnf ################################################################################