3 # Installs Debian packages from queue/accepted into the pool
4 # Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006 James Troup <james@nocrew.org>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 ###############################################################################
22 # Cartman: "I'm trying to make the best of a bad situation, I don't
23 # need to hear crap from a bunch of hippy freaks living in
24 # denial. Screw you guys, I'm going home."
26 # Kyle: "But Cartman, we're trying to..."
28 # Cartman: "uhh.. screw you guys... home."
30 ###############################################################################
32 import errno, fcntl, os, sys, time, re
33 import apt_pkg, tarfile, commands
34 from daklib import database
35 from daklib import logging
36 from daklib import queue
37 from daklib import utils
38 from daklib.dak_exceptions import *
40 ###############################################################################
60 installing_to_stable = 0
62 ###############################################################################
64 # FIXME: this should go away to some Debian specific file
65 # FIXME: should die if file already exists
68 "Urgency Logger object"
69 def __init__ (self, Cnf):
70 "Initialize a new Urgency Logger object"
72 self.timestamp = time.strftime("%Y%m%d%H%M%S")
73 # Create the log directory if it doesn't exist
74 self.log_dir = Cnf["Dir::UrgencyLog"]
75 if not os.path.exists(self.log_dir) or not os.access(self.log_dir, os.W_OK):
76 utils.warn("UrgencyLog directory %s does not exist or is not writeable, using /srv/ftp.debian.org/tmp/ instead" % (self.log_dir))
77 self.log_dir = '/srv/ftp.debian.org/tmp/'
79 self.log_filename = "%s/.install-urgencies-%s.new" % (self.log_dir, self.timestamp)
80 self.log_file = utils.open_file(self.log_filename, 'w')
83 def log (self, source, version, urgency):
85 self.log_file.write(" ".join([source, version, urgency])+'\n')
90 "Close a Logger object"
94 new_filename = "%s/install-urgencies-%s" % (self.log_dir, self.timestamp)
95 utils.move(self.log_filename, new_filename)
97 os.unlink(self.log_filename)
100 ###############################################################################
102 def generate_contents_information(filename):
103 # Generate all the contents for the database
104 cmd = "ar t %s" % (filename)
105 (result, output) = commands.getstatusoutput(cmd)
107 reject("%s: 'ar t' invocation failed." % (filename))
108 reject(utils.prefix_multi_line_string(output, " [ar output:] "), "")
110 # Ugh ... this is ugly ... Code ripped from process_unchecked.py
111 chunks = output.split('\n')
112 cmd = "ar x %s %s" % (filename, chunks[2])
113 (result, output) = commands.getstatusoutput(cmd)
115 reject("%s: 'ar t' invocation failed." % (filename))
116 reject(utils.prefix_multi_line_string(output, " [ar output:] "), "")
118 # Got deb tarballs, now lets go through and determine what bits
119 # and pieces the deb had ...
120 if chunks[2] == "data.tar.gz":
121 data = tarfile.open("data.tar.gz", "r:gz")
122 elif data_tar == "data.tar.bz2":
123 data = tarfile.open("data.tar.bz2", "r:bz2")
126 reject("couldn't find data.tar.*")
130 if not tarinfo.isdir():
131 contents.append(tarinfo.name[2:])
136 ###############################################################################
138 def reject (str, prefix="Rejected: "):
139 global reject_message
141 reject_message += prefix + str + "\n"
143 # Recheck anything that relies on the database; since that's not
144 # frozen between accept and our run time.
149 for file in files.keys():
150 # The .orig.tar.gz can disappear out from under us is it's a
151 # duplicate of one in the archive.
152 if not files.has_key(file):
154 # Check that the source still exists
155 if files[file]["type"] == "deb":
156 source_version = files[file]["source version"]
157 source_package = files[file]["source package"]
158 if not changes["architecture"].has_key("source") \
159 and not Upload.source_exists(source_package, source_version, changes["distribution"].keys()):
160 reject("no source found for %s %s (%s)." % (source_package, source_version, file))
162 # Version and file overwrite checks
163 if not installing_to_stable:
164 if files[file]["type"] == "deb":
165 reject(Upload.check_binary_against_db(file), "")
166 elif files[file]["type"] == "dsc":
167 reject(Upload.check_source_against_db(file), "")
168 (reject_msg, is_in_incoming) = Upload.check_dsc_against_db(file)
169 reject(reject_msg, "")
171 # propogate in the case it is in the override tables:
172 if changes.has_key("propdistribution"):
173 for suite in changes["propdistribution"].keys():
174 if Upload.in_override_p(files[file]["package"], files[file]["component"], suite, files[file].get("dbtype",""), file):
177 nopropogate[suite] = 1
179 for suite in propogate.keys():
180 if suite in nopropogate:
182 changes["distribution"][suite] = 1
184 for file in files.keys():
185 # Check the package is still in the override tables
186 for suite in changes["distribution"].keys():
187 if not Upload.in_override_p(files[file]["package"], files[file]["component"], suite, files[file].get("dbtype",""), file):
188 reject("%s is NEW for %s." % (file, suite))
190 ###############################################################################
193 global Cnf, Options, Upload, projectB, changes, dsc, dsc_files, files, pkg, Subst
195 Cnf = utils.get_conf()
197 Arguments = [('a',"automatic","Dinstall::Options::Automatic"),
198 ('h',"help","Dinstall::Options::Help"),
199 ('n',"no-action","Dinstall::Options::No-Action"),
200 ('p',"no-lock", "Dinstall::Options::No-Lock"),
201 ('s',"no-mail", "Dinstall::Options::No-Mail")]
203 for i in ["automatic", "help", "no-action", "no-lock", "no-mail", "version"]:
204 if not Cnf.has_key("Dinstall::Options::%s" % (i)):
205 Cnf["Dinstall::Options::%s" % (i)] = ""
207 changes_files = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
208 Options = Cnf.SubTree("Dinstall::Options")
213 Upload = queue.Upload(Cnf)
214 projectB = Upload.projectB
216 changes = Upload.pkg.changes
218 dsc_files = Upload.pkg.dsc_files
219 files = Upload.pkg.files
225 ###############################################################################
227 def usage (exit_code=0):
228 print """Usage: dak process-accepted [OPTION]... [CHANGES]...
229 -a, --automatic automatic run
230 -h, --help show this help and exit.
231 -n, --no-action don't do anything
232 -p, --no-lock don't check lockfile !! for cron.daily only !!
233 -s, --no-mail don't send any mail
234 -V, --version display the version number and exit"""
237 ###############################################################################
240 (summary, short_summary) = Upload.build_summaries()
242 (prompt, answer) = ("", "XXX")
243 if Options["No-Action"] or Options["Automatic"]:
246 if reject_message.find("Rejected") != -1:
247 print "REJECT\n" + reject_message,
248 prompt = "[R]eject, Skip, Quit ?"
249 if Options["Automatic"]:
252 print "INSTALL to " + ", ".join(changes["distribution"].keys())
253 print reject_message + summary,
254 prompt = "[I]nstall, Skip, Quit ?"
255 if Options["Automatic"]:
258 while prompt.find(answer) == -1:
259 answer = utils.our_raw_input(prompt)
260 m = queue.re_default_answer.match(prompt)
263 answer = answer[:1].upper()
268 if not installing_to_stable:
271 stable_install(summary, short_summary)
275 ###############################################################################
277 # Our reject is not really a reject, but an unaccept, but since a) the
278 # code for that is non-trivial (reopen bugs, unannounce etc.), b) this
279 # should be exteremly rare, for now we'll go with whining at our admin
283 Subst["__REJECTOR_ADDRESS__"] = Cnf["Dinstall::MyEmailAddress"]
284 Subst["__REJECT_MESSAGE__"] = reject_message
285 Subst["__CC__"] = "Cc: " + Cnf["Dinstall::MyEmailAddress"]
286 reject_mail_message = utils.TemplateSubst(Subst,Cnf["Dir::Templates"]+"/process-accepted.unaccept")
288 # Write the rejection email out as the <foo>.reason file
289 reason_filename = os.path.basename(pkg.changes_file[:-8]) + ".reason"
290 reject_filename = Cnf["Dir::Queue::Reject"] + '/' + reason_filename
291 # If we fail here someone is probably trying to exploit the race
292 # so let's just raise an exception ...
293 if os.path.exists(reject_filename):
294 os.unlink(reject_filename)
295 fd = os.open(reject_filename, os.O_RDWR|os.O_CREAT|os.O_EXCL, 0644)
296 os.write(fd, reject_mail_message)
299 utils.send_mail(reject_mail_message)
300 Logger.log(["unaccepted", pkg.changes_file])
302 ###############################################################################
305 global install_count, install_bytes
309 Logger.log(["installing changes",pkg.changes_file])
311 # Begin a transaction; if we bomb out anywhere between here and the COMMIT WORK below, the DB will not be changed.
312 projectB.query("BEGIN WORK")
314 # Ensure that we have all the hashes we need below.
315 rejmsg = utils.ensure_hashes(changes, dsc, files, dsc_files)
317 # There were errors. Print them and SKIP the changes.
322 # Add the .dsc file to the DB
323 for file in files.keys():
324 if files[file]["type"] == "dsc":
325 package = dsc["source"]
326 version = dsc["version"] # NB: not files[file]["version"], that has no epoch
327 maintainer = dsc["maintainer"]
328 maintainer = maintainer.replace("'", "\\'")
329 maintainer_id = database.get_or_set_maintainer_id(maintainer)
330 changedby = changes["changed-by"]
331 changedby = changedby.replace("'", "\\'")
332 changedby_id = database.get_or_set_maintainer_id(changedby)
333 fingerprint_id = database.get_or_set_fingerprint_id(dsc["fingerprint"])
334 install_date = time.strftime("%Y-%m-%d")
335 filename = files[file]["pool name"] + file
336 dsc_component = files[file]["component"]
337 dsc_location_id = files[file]["location id"]
338 if dsc.has_key("dm-upload-allowed") and dsc["dm-upload-allowed"] == "yes":
339 dm_upload_allowed = "true"
341 dm_upload_allowed = "false"
342 if not files[file].has_key("files id") or not files[file]["files id"]:
343 files[file]["files id"] = database.set_files_id (filename, files[file]["size"], files[file]["md5sum"], files[file]["sha1sum"], files[file]["sha256sum"], dsc_location_id)
344 projectB.query("INSERT INTO source (source, version, maintainer, changedby, file, install_date, sig_fpr, dm_upload_allowed) VALUES ('%s', '%s', %d, %d, %d, '%s', %s, %s)"
345 % (package, version, maintainer_id, changedby_id, files[file]["files id"], install_date, fingerprint_id, dm_upload_allowed))
347 for suite in changes["distribution"].keys():
348 suite_id = database.get_suite_id(suite)
349 projectB.query("INSERT INTO src_associations (suite, source) VALUES (%d, currval('source_id_seq'))" % (suite_id))
351 # Add the source files to the DB (files and dsc_files)
352 projectB.query("INSERT INTO dsc_files (source, file) VALUES (currval('source_id_seq'), %d)" % (files[file]["files id"]))
353 for dsc_file in dsc_files.keys():
354 filename = files[file]["pool name"] + dsc_file
355 # If the .orig.tar.gz is already in the pool, it's
356 # files id is stored in dsc_files by check_dsc().
357 files_id = dsc_files[dsc_file].get("files id", None)
359 files_id = database.get_files_id(filename, dsc_files[dsc_file]["size"], dsc_files[dsc_file]["md5sum"], dsc_location_id)
360 # FIXME: needs to check for -1/-2 and or handle exception
362 files_id = database.set_files_id (filename, dsc_files[dsc_file]["size"], dsc_files[dsc_file]["md5sum"], files[dsc_file]["sha1sum"], files[dsc_file]["sha256sum"], dsc_location_id)
363 projectB.query("INSERT INTO dsc_files (source, file) VALUES (currval('source_id_seq'), %d)" % (files_id))
365 # Add the src_uploaders to the DB
366 uploader_ids = [maintainer_id]
367 if dsc.has_key("uploaders"):
368 for u in dsc["uploaders"].split(","):
369 u = u.replace("'", "\\'")
372 database.get_or_set_maintainer_id(u))
374 for u in uploader_ids:
375 if added_ids.has_key(u):
376 utils.warn("Already saw uploader %s for source %s" % (u, package))
379 projectB.query("INSERT INTO src_uploaders (source, maintainer) VALUES (currval('source_id_seq'), %d)" % (u))
382 # Add the .deb files to the DB
383 for file in files.keys():
384 if files[file]["type"] == "deb":
385 package = files[file]["package"]
386 version = files[file]["version"]
387 maintainer = files[file]["maintainer"]
388 maintainer = maintainer.replace("'", "\\'")
389 maintainer_id = database.get_or_set_maintainer_id(maintainer)
390 fingerprint_id = database.get_or_set_fingerprint_id(changes["fingerprint"])
391 architecture = files[file]["architecture"]
392 architecture_id = database.get_architecture_id (architecture)
393 type = files[file]["dbtype"]
394 source = files[file]["source package"]
395 source_version = files[file]["source version"]
396 filename = files[file]["pool name"] + file
397 contents = generate_contents_information(file)
398 if not files[file].has_key("location id") or not files[file]["location id"]:
399 files[file]["location id"] = database.get_location_id(Cnf["Dir::Pool"],files[file]["component"],utils.where_am_i())
400 if not files[file].has_key("files id") or not files[file]["files id"]:
401 files[file]["files id"] = database.set_files_id (filename, files[file]["size"], files[file]["md5sum"], files[file]["sha1sum"], files[file]["sha256sum"], files[file]["location id"])
402 source_id = database.get_source_id (source, source_version)
404 projectB.query("INSERT INTO binaries (package, version, maintainer, source, architecture, file, type, sig_fpr) VALUES ('%s', '%s', %d, %d, %d, %d, '%s', %d)"
405 % (package, version, maintainer_id, source_id, architecture_id, files[file]["files id"], type, fingerprint_id))
407 raise NoSourceFieldError, "Unable to find a source id for %s (%s), %s, file %s, type %s, signed by %s" % (package, version, architecture, file, type, sig_fpr)
408 for suite in changes["distribution"].keys():
409 suite_id = database.get_suite_id(suite)
410 projectB.query("INSERT INTO bin_associations (suite, bin) VALUES (%d, currval('binaries_id_seq'))" % (suite_id))
412 # insert contents into the database
413 q = projectB.query("SELECT currval('binaries_id_seq')")
414 bin_id = int(q.getresult()[0][0])
415 for file in contents:
416 database.insert_content_path(bin_id, file)
418 # If the .orig.tar.gz is in a legacy directory we need to poolify
419 # it, so that apt-get source (and anything else that goes by the
420 # "Directory:" field in the Sources.gz file) works.
421 orig_tar_id = Upload.pkg.orig_tar_id
422 orig_tar_location = Upload.pkg.orig_tar_location
423 legacy_source_untouchable = Upload.pkg.legacy_source_untouchable
424 if orig_tar_id and orig_tar_location == "legacy":
425 q = projectB.query("SELECT DISTINCT ON (f.id) l.path, f.filename, f.id as files_id, df.source, df.id as dsc_files_id, f.size, f.md5sum FROM files f, dsc_files df, location l WHERE df.source IN (SELECT source FROM dsc_files WHERE file = %s) AND f.id = df.file AND l.id = f.location AND (l.type = 'legacy' OR l.type = 'legacy-mixed')" % (orig_tar_id))
428 # Is this an old upload superseded by a newer -sa upload? (See check_dsc() for details)
429 if legacy_source_untouchable.has_key(qid["files_id"]):
431 # First move the files to the new location
432 legacy_filename = qid["path"] + qid["filename"]
433 pool_location = utils.poolify (changes["source"], files[file]["component"])
434 pool_filename = pool_location + os.path.basename(qid["filename"])
435 destination = Cnf["Dir::Pool"] + pool_location
436 utils.move(legacy_filename, destination)
437 # Then Update the DB's files table
438 q = projectB.query("UPDATE files SET filename = '%s', location = '%s' WHERE id = '%s'" % (pool_filename, dsc_location_id, qid["files_id"]))
440 # If this is a sourceful diff only upload that is moving non-legacy
441 # cross-component we need to copy the .orig.tar.gz into the new
442 # component too for the same reasons as above.
444 if changes["architecture"].has_key("source") and orig_tar_id and \
445 orig_tar_location != "legacy" and orig_tar_location != dsc_location_id:
446 q = projectB.query("SELECT l.path, f.filename, f.size, f.md5sum, f.sha1sum, f.sha256sum FROM files f, location l WHERE f.id = %s AND f.location = l.id" % (orig_tar_id))
447 ql = q.getresult()[0]
448 old_filename = ql[0] + ql[1]
452 file_sha256sum = ql[5]
453 new_filename = utils.poolify(changes["source"], dsc_component) + os.path.basename(old_filename)
454 new_files_id = database.get_files_id(new_filename, file_size, file_md5sum, dsc_location_id)
455 if new_files_id == None:
456 utils.copy(old_filename, Cnf["Dir::Pool"] + new_filename)
457 new_files_id = database.set_files_id(new_filename, file_size, file_md5sum, file_sha1sum, file_sha256sum, dsc_location_id)
458 projectB.query("UPDATE dsc_files SET file = %s WHERE source = %s AND file = %s" % (new_files_id, database.get_source_id(changes["source"], changes["version"]), orig_tar_id))
460 # Install the files into the pool
461 for file in files.keys():
462 destination = Cnf["Dir::Pool"] + files[file]["pool name"] + file
463 utils.move(file, destination)
464 Logger.log(["installed", file, files[file]["type"], files[file]["size"], files[file]["architecture"]])
465 install_bytes += float(files[file]["size"])
467 # Copy the .changes file across for suite which need it.
470 for suite in changes["distribution"].keys():
471 if Cnf.has_key("Suite::%s::CopyChanges" % (suite)):
472 copy_changes[Cnf["Suite::%s::CopyChanges" % (suite)]] = ""
473 # and the .dak file...
474 if Cnf.has_key("Suite::%s::CopyDotDak" % (suite)):
475 copy_dot_dak[Cnf["Suite::%s::CopyDotDak" % (suite)]] = ""
476 for dest in copy_changes.keys():
477 utils.copy(pkg.changes_file, Cnf["Dir::Root"] + dest)
478 for dest in copy_dot_dak.keys():
479 utils.copy(Upload.pkg.changes_file[:-8]+".dak", dest)
480 projectB.query("COMMIT WORK")
482 # Move the .changes into the 'done' directory
483 utils.move (pkg.changes_file,
484 os.path.join(Cnf["Dir::Queue::Done"], os.path.basename(pkg.changes_file)))
486 # Remove the .dak file
487 os.unlink(Upload.pkg.changes_file[:-8]+".dak")
489 if changes["architecture"].has_key("source") and Urgency_Logger:
490 Urgency_Logger.log(dsc["source"], dsc["version"], changes["urgency"])
492 # Undo the work done in queue.py(accept) to help auto-building
494 projectB.query("BEGIN WORK")
495 for suite in changes["distribution"].keys():
496 if suite not in Cnf.ValueList("Dinstall::QueueBuildSuites"):
498 now_date = time.strftime("%Y-%m-%d %H:%M")
499 suite_id = database.get_suite_id(suite)
500 dest_dir = Cnf["Dir::QueueBuild"]
501 if Cnf.FindB("Dinstall::SecurityQueueBuild"):
502 dest_dir = os.path.join(dest_dir, suite)
503 for file in files.keys():
504 dest = os.path.join(dest_dir, file)
505 # Remove it from the list of packages for later processing by apt-ftparchive
506 projectB.query("UPDATE queue_build SET in_queue = 'f', last_used = '%s' WHERE filename = '%s' AND suite = %s" % (now_date, dest, suite_id))
507 if not Cnf.FindB("Dinstall::SecurityQueueBuild"):
508 # Update the symlink to point to the new location in the pool
509 pool_location = utils.poolify (changes["source"], files[file]["component"])
510 src = os.path.join(Cnf["Dir::Pool"], pool_location, os.path.basename(file))
511 if os.path.islink(dest):
513 os.symlink(src, dest)
514 # Update last_used on any non-upload .orig.tar.gz symlink
516 # Determine the .orig.tar.gz file name
517 for dsc_file in dsc_files.keys():
518 if dsc_file.endswith(".orig.tar.gz"):
519 orig_tar_gz = os.path.join(dest_dir, dsc_file)
520 # Remove it from the list of packages for later processing by apt-ftparchive
521 projectB.query("UPDATE queue_build SET in_queue = 'f', last_used = '%s' WHERE filename = '%s' AND suite = %s" % (now_date, orig_tar_gz, suite_id))
522 projectB.query("COMMIT WORK")
527 ################################################################################
529 def stable_install (summary, short_summary):
532 print "Installing to stable."
534 # Begin a transaction; if we bomb out anywhere between here and
535 # the COMMIT WORK below, the DB won't be changed.
536 projectB.query("BEGIN WORK")
538 # Add the source to stable (and remove it from proposed-updates)
539 for file in files.keys():
540 if files[file]["type"] == "dsc":
541 package = dsc["source"]
542 version = dsc["version"]; # NB: not files[file]["version"], that has no epoch
543 q = projectB.query("SELECT id FROM source WHERE source = '%s' AND version = '%s'" % (package, version))
546 utils.fubar("[INTERNAL ERROR] couldn't find '%s' (%s) in source table." % (package, version))
548 suite_id = database.get_suite_id('proposed-updates')
549 projectB.query("DELETE FROM src_associations WHERE suite = '%s' AND source = '%s'" % (suite_id, source_id))
550 suite_id = database.get_suite_id('stable')
551 projectB.query("INSERT INTO src_associations (suite, source) VALUES ('%s', '%s')" % (suite_id, source_id))
553 # Add the binaries to stable (and remove it/them from proposed-updates)
554 for file in files.keys():
555 if files[file]["type"] == "deb":
556 package = files[file]["package"]
557 version = files[file]["version"]
558 architecture = files[file]["architecture"]
559 q = projectB.query("SELECT b.id FROM binaries b, architecture a WHERE b.package = '%s' AND b.version = '%s' AND (a.arch_string = '%s' OR a.arch_string = 'all') AND b.architecture = a.id" % (package, version, architecture))
562 utils.fubar("[INTERNAL ERROR] couldn't find '%s' (%s for %s architecture) in binaries table." % (package, version, architecture))
565 suite_id = database.get_suite_id('proposed-updates')
566 projectB.query("DELETE FROM bin_associations WHERE suite = '%s' AND bin = '%s'" % (suite_id, binary_id))
567 suite_id = database.get_suite_id('stable')
568 projectB.query("INSERT INTO bin_associations (suite, bin) VALUES ('%s', '%s')" % (suite_id, binary_id))
570 projectB.query("COMMIT WORK")
572 utils.move (pkg.changes_file, Cnf["Dir::Morgue"] + '/process-accepted/' + os.path.basename(pkg.changes_file))
574 ## Update the Stable ChangeLog file
575 new_changelog_filename = Cnf["Dir::Root"] + Cnf["Suite::Stable::ChangeLogBase"] + ".ChangeLog"
576 changelog_filename = Cnf["Dir::Root"] + Cnf["Suite::Stable::ChangeLogBase"] + "ChangeLog"
577 if os.path.exists(new_changelog_filename):
578 os.unlink (new_changelog_filename)
580 new_changelog = utils.open_file(new_changelog_filename, 'w')
581 for file in files.keys():
582 if files[file]["type"] == "deb":
583 new_changelog.write("stable/%s/binary-%s/%s\n" % (files[file]["component"], files[file]["architecture"], file))
584 elif utils.re_issource.match(file):
585 new_changelog.write("stable/%s/source/%s\n" % (files[file]["component"], file))
587 new_changelog.write("%s\n" % (file))
588 chop_changes = queue.re_fdnic.sub("\n", changes["changes"])
589 new_changelog.write(chop_changes + '\n\n')
590 if os.access(changelog_filename, os.R_OK) != 0:
591 changelog = utils.open_file(changelog_filename)
592 new_changelog.write(changelog.read())
593 new_changelog.close()
594 if os.access(changelog_filename, os.R_OK) != 0:
595 os.unlink(changelog_filename)
596 utils.move(new_changelog_filename, changelog_filename)
600 if not Options["No-Mail"] and changes["architecture"].has_key("source"):
601 Subst["__SUITE__"] = " into stable"
602 Subst["__SUMMARY__"] = summary
603 mail_message = utils.TemplateSubst(Subst,Cnf["Dir::Templates"]+"/process-accepted.install")
604 utils.send_mail(mail_message)
605 Upload.announce(short_summary, 1)
607 # Finally remove the .dak file
608 dot_dak_file = os.path.join(Cnf["Suite::Proposed-Updates::CopyDotDak"], os.path.basename(Upload.pkg.changes_file[:-8]+".dak"))
609 os.unlink(dot_dak_file)
611 ################################################################################
613 def process_it (changes_file):
614 global reject_message
618 # Absolutize the filename to avoid the requirement of being in the
619 # same directory as the .changes file.
620 pkg.changes_file = os.path.abspath(changes_file)
622 # And since handling of installs to stable munges with the CWD
623 # save and restore it.
624 pkg.directory = os.getcwd()
626 if installing_to_stable:
627 old = Upload.pkg.changes_file
628 Upload.pkg.changes_file = os.path.basename(old)
629 os.chdir(Cnf["Suite::Proposed-Updates::CopyDotDak"])
633 Upload.update_subst()
635 if installing_to_stable:
636 Upload.pkg.changes_file = old
642 os.chdir(pkg.directory)
644 ###############################################################################
647 global projectB, Logger, Urgency_Logger, installing_to_stable
649 changes_files = init()
651 # -n/--dry-run invalidates some other options which would involve things happening
652 if Options["No-Action"]:
653 Options["Automatic"] = ""
655 # Check that we aren't going to clash with the daily cron job
657 if not Options["No-Action"] and os.path.exists("%s/Archive_Maintenance_In_Progress" % (Cnf["Dir::Root"])) and not Options["No-Lock"]:
658 utils.fubar("Archive maintenance in progress. Try again later.")
660 # If running from within proposed-updates; assume an install to stable
661 if os.getcwd().find('proposed-updates') != -1:
662 installing_to_stable = 1
664 # Obtain lock if not in no-action mode and initialize the log
665 if not Options["No-Action"]:
666 lock_fd = os.open(Cnf["Dinstall::LockFile"], os.O_RDWR | os.O_CREAT)
668 fcntl.lockf(lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
670 if errno.errorcode[e.errno] == 'EACCES' or errno.errorcode[e.errno] == 'EAGAIN':
671 utils.fubar("Couldn't obtain lock; assuming another 'dak process-accepted' is already running.")
674 Logger = Upload.Logger = logging.Logger(Cnf, "process-accepted")
675 if not installing_to_stable and Cnf.get("Dir::UrgencyLog"):
676 Urgency_Logger = Urgency_Log(Cnf)
678 # Initialize the substitution template mapping global
679 bcc = "X-DAK: dak process-accepted\nX-Katie: $Revision: 1.18 $"
680 if Cnf.has_key("Dinstall::Bcc"):
681 Subst["__BCC__"] = bcc + "\nBcc: %s" % (Cnf["Dinstall::Bcc"])
683 Subst["__BCC__"] = bcc
685 # Sort the .changes files so that we process sourceful ones first
686 changes_files.sort(utils.changes_compare)
688 # Process the changes files
689 for changes_file in changes_files:
690 print "\n" + changes_file
691 process_it (changes_file)
695 if install_count > 1:
697 sys.stderr.write("Installed %d package %s, %s.\n" % (install_count, sets, utils.size_type(int(install_bytes))))
698 Logger.log(["total",install_count,install_bytes])
700 if not Options["No-Action"]:
703 Urgency_Logger.close()
705 ###############################################################################
707 if __name__ == '__main__':