from daklib.config import Config
from daklib.archive import ArchiveTransaction
from daklib.urgencylog import UrgencyLog
-from daklib.textutils import fix_maintainer
+
+import daklib.announce
# Globals
Options = None
def do_comments(dir, srcqueue, opref, npref, line, fn, transaction):
session = transaction.session
+ actions = []
for comm in [ x for x in os.listdir(dir) if x.startswith(opref) ]:
lines = open(os.path.join(dir, comm)).readlines()
if len(lines) == 0 or lines[0] != line + "\n": continue
else:
changes_prefix = changes_prefix + '.changes'
+ # We need to escape "_" as we use it with the LIKE operator (via the
+ # SQLA startwith) later.
+ changes_prefix = changes_prefix.replace("_", r"\_")
+
uploads = session.query(PolicyQueueUpload).filter_by(policy_queue=srcqueue) \
.join(PolicyQueueUpload.changes).filter(DBChange.changesname.startswith(changes_prefix)) \
.order_by(PolicyQueueUpload.source_id)
- for u in uploads:
- print "Processing changes file: %s" % u.changes.changesname
- fn(u, srcqueue, "".join(lines[1:]), transaction)
+ reason = "".join(lines[1:])
+ actions.extend((u, reason) for u in uploads)
if opref != npref:
newcomm = npref + comm[len(opref):]
- transaction.fs.move(os.path.join(dir, comm), os.path.join(dir, newcomm))
+ newcomm = utils.find_next_free(os.path.join(dir, newcomm))
+ transaction.fs.move(os.path.join(dir, comm), newcomm)
+
+ actions.sort()
+
+ for u, reason in actions:
+ print("Processing changes file: {0}".format(u.changes.changesname))
+ fn(u, srcqueue, reason, transaction)
################################################################################
if upload.source is not None:
transaction.copy_source(upload.source, suite, source_component_func(upload.source), allow_tainted=allow_tainted)
for db_binary in upload.binaries:
+ # build queues may miss the source package if this is a binary-only upload
+ if suite != upload.target_suite:
+ transaction.copy_source(db_binary.source, suite, source_component_func(db_binary.source), allow_tainted=allow_tainted)
transaction.copy_binary(db_binary, suite, binary_component_func(db_binary), allow_tainted=allow_tainted, extra_archives=[upload.target_suite.archive])
# Copy .changes if needed
dst = os.path.join(upload.target_suite.path, upload.changes.changesname)
fs.copy(src, dst, mode=upload.target_suite.archive.mode)
+ # Copy upload to Process-Policy::CopyDir
+ # Used on security.d.o to sync accepted packages to ftp-master, but this
+ # should eventually be replaced by something else.
+ copydir = cnf.get('Process-Policy::CopyDir') or None
+ if copydir is not None:
+ mode = upload.target_suite.archive.mode
+ if upload.source is not None:
+ for f in [ df.poolfile for df in upload.source.srcfiles ]:
+ dst = os.path.join(copydir, f.basename)
+ if not os.path.exists(dst):
+ fs.copy(f.fullpath, dst, mode=mode)
+
+ for db_binary in upload.binaries:
+ f = db_binary.poolfile
+ dst = os.path.join(copydir, f.basename)
+ if not os.path.exists(dst):
+ fs.copy(f.fullpath, dst, mode=mode)
+
+ src = os.path.join(upload.policy_queue.path, upload.changes.changesname)
+ dst = os.path.join(copydir, upload.changes.changesname)
+ if not os.path.exists(dst):
+ fs.copy(src, dst, mode=mode)
+
if upload.source is not None and not Options['No-Action']:
urgency = upload.changes.urgency
if urgency not in cnf.value_list('Urgency::Valid'):
if not Options['No-Action']:
Logger.log(["Policy Queue ACCEPT", srcqueue.queue_name, changesname])
- # Send announcement
- if upload.source is not None:
- subst = subst_for_upload(upload)
- announce = ", ".join(upload.target_suite.announce or [])
- tracking = cnf.get('Dinstall::TrackingServer')
- if tracking and upload.source is not None:
- announce = '{0}\nBcc: {1}@{2}'.format(announce, upload.changes.source, tracking)
- subst['__ANNOUNCE_LIST_ADDRESS__'] = announce
- message = utils.TemplateSubst(subst, os.path.join(cnf['Dir::Templates'], 'process-unchecked.announce'))
- utils.send_mail(message)
-
- # TODO: code duplication. Similar code is in process-upload.
- if cnf.find_b('Dinstall::CloseBugs') and upload.changes.closes is not None and upload.source is not None:
- for bugnum in upload.changes.closes:
- subst['__BUG_NUMBER__'] = bugnum
- message = utils.TemplateSubst(subst, os.path.join(cnf['Dir::Templates'], 'process-unchecked.bug-close'))
- utils.send_mail(message)
-
- del subst['__BUG_NUMBER__']
+ pu = get_processed_upload(upload)
+ daklib.announce.announce_accept(pu)
# TODO: code duplication. Similar code is in process-upload.
# Move .changes to done
@try_or_reject
def comment_reject(*args):
- real_comment_reject(*args)
+ real_comment_reject(*args, manual=True)
-def real_comment_reject(upload, srcqueue, comments, transaction, notify=True):
+def real_comment_reject(upload, srcqueue, comments, transaction, notify=True, manual=False):
cnf = Config()
fs = transaction.fs
### Send mail notification
if notify:
- subst = subst_for_upload(upload)
- subst['__MANUAL_REJECT_MESSAGE__'] = ''
- subst['__REJECT_MESSAGE__'] = comments
+ rejected_by = None
+ reason = comments
# Try to use From: from comment file if there is one.
# This is not very elegant...
match = re.match(r"\AFrom: ([^\n]+)\n\n", comments)
if match:
- subst['__REJECTOR_ADDRESS__'] = match.group(1)
- subst['__REJECT_MESSAGE__'] = '\n'.join(comments.splitlines()[2:])
+ rejected_by = match.group(1)
+ reason = '\n'.join(comments.splitlines()[2:])
- message = utils.TemplateSubst(subst, os.path.join(cnf['Dir::Templates'], 'queue.rejected'))
- utils.send_mail(message)
+ pu = get_processed_upload(upload)
+ daklib.announce.announce_reject(pu, reason, rejected_by)
print " REJECT"
if not Options["No-Action"]:
Logger.log(["Policy Queue REJECT", srcqueue.queue_name, upload.changes.changesname])
+ changes = upload.changes
remove_upload(upload, transaction)
+ session.delete(changes)
################################################################################
fs.unlink(os.path.join(queuedir, upload.changes.changesname))
session.delete(upload)
- session.delete(changes)
session.flush()
################################################################################
-def subst_for_upload(upload):
- # TODO: similar code in process-upload
- cnf = Config()
+def get_processed_upload(upload):
+ pu = daklib.announce.ProcessedUpload()
- maintainer_field = upload.changes.changedby or upload.changes.maintainer
- if upload.source is not None:
- addresses = utils.mail_addresses_for_upload(upload.changes.maintainer, maintainer_field, upload.changes.fingerprint)
- else:
- addresses = utils.mail_addresses_for_upload(upload.changes.maintainer, upload.changes.maintainer, upload.changes.fingerprint)
+ pu.maintainer = upload.changes.maintainer
+ pu.changed_by = upload.changes.changedby
+ pu.fingerprint = upload.changes.fingerprint
+
+ pu.suites = [ upload.target_suite ]
+ pu.from_policy_suites = [ upload.target_suite ]
changes_path = os.path.join(upload.policy_queue.path, upload.changes.changesname)
- changes_contents = open(changes_path, 'r').read()
-
- bcc = 'X-DAK: dak process-policy'
- if 'Dinstall::Bcc' in cnf:
- bcc = '{0}\nBcc: {1}'.format(bcc, cnf['Dinstall::Bcc'])
-
- subst = {
- '__DISTRO__': cnf['Dinstall::MyDistribution'],
- '__ADMIN_ADDRESS__': cnf['Dinstall::MyAdminAddress'],
-
- '__CHANGES_FILENAME__': upload.changes.changesname,
- '__SOURCE__': upload.changes.source,
- '__VERSION__': upload.changes.version,
- '__ARCHITECTURE__': upload.changes.architecture,
- '__MAINTAINER__': maintainer_field,
- '__MAINTAINER_FROM__': fix_maintainer(maintainer_field)[1],
- '__MAINTAINER_TO__': ", ".join(addresses),
- '__CC__': 'X-DAK-Rejection: manual or automatic',
- '__REJECTOR_ADDRESS__': cnf['Dinstall::MyEmailAddress'],
- '__BCC__': bcc,
- '__BUG_SERVER__': cnf.get('Dinstall::BugServer'),
- '__FILE_CONTENTS__': changes_contents,
- }
-
- override_maintainer = cnf.get('Dinstall::OverrideMaintainer')
- if override_maintainer:
- subst['__MAINTAINER_TO__'] = override_maintainer
-
- return subst
+ pu.changes = open(changes_path, 'r').read()
+ pu.changes_filename = upload.changes.changesname
+ pu.sourceful = upload.source is not None
+ pu.source = upload.changes.source
+ pu.version = upload.changes.version
+ pu.architecture = upload.changes.architecture
+ pu.bugs = upload.changes.closes
+
+ pu.program = "process-policy"
+
+ return pu
################################################################################
# The comments stuff relies on being in the right directory
os.chdir(pq.path)
+ do_comments(commentsdir, pq, "REJECT.", "REJECTED.", "NOTOK", comment_reject, transaction)
do_comments(commentsdir, pq, "ACCEPT.", "ACCEPTED.", "OK", comment_accept, transaction)
do_comments(commentsdir, pq, "ACCEPTED.", "ACCEPTED.", "OK", comment_accept, transaction)
- do_comments(commentsdir, pq, "REJECT.", "REJECTED.", "NOTOK", comment_reject, transaction)
remove_unreferenced_binaries(pq, transaction)
remove_unreferenced_sources(pq, transaction)