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
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)
99 ###############################################################################
101 def reject (str, prefix="Rejected: "):
102 global reject_message
104 reject_message += prefix + str + "\n"
106 # Recheck anything that relies on the database; since that's not
107 # frozen between accept and our run time.
112 for file in files.keys():
113 # The .orig.tar.gz can disappear out from under us is it's a
114 # duplicate of one in the archive.
115 if not files.has_key(file):
117 # Check that the source still exists
118 if files[file]["type"] == "deb":
119 source_version = files[file]["source version"]
120 source_package = files[file]["source package"]
121 if not changes["architecture"].has_key("source") \
122 and not Upload.source_exists(source_package, source_version, changes["distribution"].keys()):
123 reject("no source found for %s %s (%s)." % (source_package, source_version, file))
125 # Version and file overwrite checks
126 if not installing_to_stable:
127 if files[file]["type"] == "deb":
128 reject(Upload.check_binary_against_db(file), "")
129 elif files[file]["type"] == "dsc":
130 reject(Upload.check_source_against_db(file), "")
131 (reject_msg, is_in_incoming) = Upload.check_dsc_against_db(file)
132 reject(reject_msg, "")
134 # propogate in the case it is in the override tables:
135 if changes.has_key("propdistribution"):
136 for suite in changes["propdistribution"].keys():
137 if Upload.in_override_p(files[file]["package"], files[file]["component"], suite, files[file].get("dbtype",""), file):
140 nopropogate[suite] = 1
142 for suite in propogate.keys():
143 if suite in nopropogate:
145 changes["distribution"][suite] = 1
147 for file in files.keys():
148 # Check the package is still in the override tables
149 for suite in changes["distribution"].keys():
150 if not Upload.in_override_p(files[file]["package"], files[file]["component"], suite, files[file].get("dbtype",""), file):
151 reject("%s is NEW for %s." % (file, suite))
153 ###############################################################################
156 global Cnf, Options, Upload, projectB, changes, dsc, dsc_files, files, pkg, Subst
158 Cnf = utils.get_conf()
160 Arguments = [('a',"automatic","Dinstall::Options::Automatic"),
161 ('h',"help","Dinstall::Options::Help"),
162 ('n',"no-action","Dinstall::Options::No-Action"),
163 ('p',"no-lock", "Dinstall::Options::No-Lock"),
164 ('s',"no-mail", "Dinstall::Options::No-Mail")]
166 for i in ["automatic", "help", "no-action", "no-lock", "no-mail", "version"]:
167 if not Cnf.has_key("Dinstall::Options::%s" % (i)):
168 Cnf["Dinstall::Options::%s" % (i)] = ""
170 changes_files = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
171 Options = Cnf.SubTree("Dinstall::Options")
176 Upload = queue.Upload(Cnf)
177 projectB = Upload.projectB
179 changes = Upload.pkg.changes
181 dsc_files = Upload.pkg.dsc_files
182 files = Upload.pkg.files
188 ###############################################################################
190 def usage (exit_code=0):
191 print """Usage: dak process-accepted [OPTION]... [CHANGES]...
192 -a, --automatic automatic run
193 -h, --help show this help and exit.
194 -n, --no-action don't do anything
195 -p, --no-lock don't check lockfile !! for cron.daily only !!
196 -s, --no-mail don't send any mail
197 -V, --version display the version number and exit"""
200 ###############################################################################
203 (summary, short_summary) = Upload.build_summaries()
205 (prompt, answer) = ("", "XXX")
206 if Options["No-Action"] or Options["Automatic"]:
209 if reject_message.find("Rejected") != -1:
210 print "REJECT\n" + reject_message,
211 prompt = "[R]eject, Skip, Quit ?"
212 if Options["Automatic"]:
215 print "INSTALL to " + ", ".join(changes["distribution"].keys())
216 print reject_message + summary,
217 prompt = "[I]nstall, Skip, Quit ?"
218 if Options["Automatic"]:
221 while prompt.find(answer) == -1:
222 answer = utils.our_raw_input(prompt)
223 m = queue.re_default_answer.match(prompt)
226 answer = answer[:1].upper()
231 if not installing_to_stable:
234 stable_install(summary, short_summary)
238 ###############################################################################
240 # Our reject is not really a reject, but an unaccept, but since a) the
241 # code for that is non-trivial (reopen bugs, unannounce etc.), b) this
242 # should be exteremly rare, for now we'll go with whining at our admin
246 Subst["__REJECTOR_ADDRESS__"] = Cnf["Dinstall::MyEmailAddress"]
247 Subst["__REJECT_MESSAGE__"] = reject_message
248 Subst["__CC__"] = "Cc: " + Cnf["Dinstall::MyEmailAddress"]
249 reject_mail_message = utils.TemplateSubst(Subst,Cnf["Dir::Templates"]+"/process-accepted.unaccept")
251 # Write the rejection email out as the <foo>.reason file
252 reason_filename = os.path.basename(pkg.changes_file[:-8]) + ".reason"
253 reject_filename = Cnf["Dir::Queue::Reject"] + '/' + reason_filename
254 # If we fail here someone is probably trying to exploit the race
255 # so let's just raise an exception ...
256 if os.path.exists(reject_filename):
257 os.unlink(reject_filename)
258 fd = os.open(reject_filename, os.O_RDWR|os.O_CREAT|os.O_EXCL, 0644)
259 os.write(fd, reject_mail_message)
262 utils.send_mail(reject_mail_message)
263 Logger.log(["unaccepted", pkg.changes_file])
265 ###############################################################################
268 global install_count, install_bytes
272 Logger.log(["installing changes",pkg.changes_file])
274 # Begin a transaction; if we bomb out anywhere between here and the COMMIT WORK below, the DB will not be changed.
275 projectB.query("BEGIN WORK")
277 # Ensure that we have all the hashes we need below.
278 rejmsg = utils.ensure_hashes(changes, dsc, files, dsc_files)
280 # There were errors. Print them and SKIP the changes.
285 # Add the .dsc file to the DB
286 for file in files.keys():
287 if files[file]["type"] == "dsc":
288 package = dsc["source"]
289 version = dsc["version"] # NB: not files[file]["version"], that has no epoch
290 maintainer = dsc["maintainer"]
291 maintainer = maintainer.replace("'", "\\'")
292 maintainer_id = database.get_or_set_maintainer_id(maintainer)
293 changedby = changes["changed-by"]
294 changedby = changedby.replace("'", "\\'")
295 changedby_id = database.get_or_set_maintainer_id(changedby)
296 fingerprint_id = database.get_or_set_fingerprint_id(dsc["fingerprint"])
297 install_date = time.strftime("%Y-%m-%d")
298 filename = files[file]["pool name"] + file
299 dsc_component = files[file]["component"]
300 dsc_location_id = files[file]["location id"]
301 if not files[file].has_key("files id") or not files[file]["files id"]:
302 files[file]["files id"] = database.set_files_id (filename, files[file]["size"], files[file]["md5sum"], files[file]["sha1sum"], files[file]["sha256sum"], dsc_location_id)
303 projectB.query("INSERT INTO source (source, version, maintainer, changedby, file, install_date, sig_fpr) VALUES ('%s', '%s', %d, %d, %d, '%s', %s)"
304 % (package, version, maintainer_id, changedby_id, files[file]["files id"], install_date, fingerprint_id))
306 for suite in changes["distribution"].keys():
307 suite_id = database.get_suite_id(suite)
308 projectB.query("INSERT INTO src_associations (suite, source) VALUES (%d, currval('source_id_seq'))" % (suite_id))
310 # Add the source files to the DB (files and dsc_files)
311 projectB.query("INSERT INTO dsc_files (source, file) VALUES (currval('source_id_seq'), %d)" % (files[file]["files id"]))
312 for dsc_file in dsc_files.keys():
313 filename = files[file]["pool name"] + dsc_file
314 # If the .orig.tar.gz is already in the pool, it's
315 # files id is stored in dsc_files by check_dsc().
316 files_id = dsc_files[dsc_file].get("files id", None)
318 files_id = database.get_files_id(filename, dsc_files[dsc_file]["size"], dsc_files[dsc_file]["md5sum"], dsc_location_id)
319 # FIXME: needs to check for -1/-2 and or handle exception
321 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)
322 projectB.query("INSERT INTO dsc_files (source, file) VALUES (currval('source_id_seq'), %d)" % (files_id))
324 # Add the src_uploaders to the DB
325 if dsc.get("dm-upload-allowed", "no") == "yes":
326 uploader_ids = [maintainer_id]
327 if dsc.has_key("uploaders"):
328 for u in dsc["uploaders"].split(","):
329 u = u.replace("'", "\\'")
332 database.get_or_set_maintainer_id(u))
334 for u in uploader_ids:
335 if added_ids.has_key(u):
336 utils.warn("Already saw uploader %s for source %s" % (u, package))
339 projectB.query("INSERT INTO src_uploaders (source, maintainer) VALUES (currval('source_id_seq'), %d)" % (u))
342 # Add the .deb files to the DB
343 for file in files.keys():
344 if files[file]["type"] == "deb":
345 package = files[file]["package"]
346 version = files[file]["version"]
347 maintainer = files[file]["maintainer"]
348 maintainer = maintainer.replace("'", "\\'")
349 maintainer_id = database.get_or_set_maintainer_id(maintainer)
350 fingerprint_id = database.get_or_set_fingerprint_id(changes["fingerprint"])
351 architecture = files[file]["architecture"]
352 architecture_id = database.get_architecture_id (architecture)
353 type = files[file]["dbtype"]
354 source = files[file]["source package"]
355 source_version = files[file]["source version"]
356 filename = files[file]["pool name"] + file
357 if not files[file].has_key("location id") or not files[file]["location id"]:
358 files[file]["location id"] = database.get_location_id(Cnf["Dir::Pool"],files[file]["component"],utils.where_am_i())
359 if not files[file].has_key("files id") or not files[file]["files id"]:
360 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"])
361 source_id = database.get_source_id (source, source_version)
363 projectB.query("INSERT INTO binaries (package, version, maintainer, source, architecture, file, type, sig_fpr) VALUES ('%s', '%s', %d, %d, %d, %d, '%s', %d)"
364 % (package, version, maintainer_id, source_id, architecture_id, files[file]["files id"], type, fingerprint_id))
366 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)
367 for suite in changes["distribution"].keys():
368 suite_id = database.get_suite_id(suite)
369 projectB.query("INSERT INTO bin_associations (suite, bin) VALUES (%d, currval('binaries_id_seq'))" % (suite_id))
371 # If the .orig.tar.gz is in a legacy directory we need to poolify
372 # it, so that apt-get source (and anything else that goes by the
373 # "Directory:" field in the Sources.gz file) works.
374 orig_tar_id = Upload.pkg.orig_tar_id
375 orig_tar_location = Upload.pkg.orig_tar_location
376 legacy_source_untouchable = Upload.pkg.legacy_source_untouchable
377 if orig_tar_id and orig_tar_location == "legacy":
378 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))
381 # Is this an old upload superseded by a newer -sa upload? (See check_dsc() for details)
382 if legacy_source_untouchable.has_key(qid["files_id"]):
384 # First move the files to the new location
385 legacy_filename = qid["path"] + qid["filename"]
386 pool_location = utils.poolify (changes["source"], files[file]["component"])
387 pool_filename = pool_location + os.path.basename(qid["filename"])
388 destination = Cnf["Dir::Pool"] + pool_location
389 utils.move(legacy_filename, destination)
390 # Then Update the DB's files table
391 q = projectB.query("UPDATE files SET filename = '%s', location = '%s' WHERE id = '%s'" % (pool_filename, dsc_location_id, qid["files_id"]))
393 # If this is a sourceful diff only upload that is moving non-legacy
394 # cross-component we need to copy the .orig.tar.gz into the new
395 # component too for the same reasons as above.
397 if changes["architecture"].has_key("source") and orig_tar_id and \
398 orig_tar_location != "legacy" and orig_tar_location != dsc_location_id:
399 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))
400 ql = q.getresult()[0]
401 old_filename = ql[0] + ql[1]
405 file_sha256sum = ql[5]
406 new_filename = utils.poolify(changes["source"], dsc_component) + os.path.basename(old_filename)
407 new_files_id = database.get_files_id(new_filename, file_size, file_md5sum, dsc_location_id)
408 if new_files_id == None:
409 utils.copy(old_filename, Cnf["Dir::Pool"] + new_filename)
410 new_files_id = database.set_files_id(new_filename, file_size, file_md5sum, file_sha1sum, file_sha256sum, dsc_location_id)
411 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))
413 # Install the files into the pool
414 for file in files.keys():
415 destination = Cnf["Dir::Pool"] + files[file]["pool name"] + file
416 utils.move(file, destination)
417 Logger.log(["installed", file, files[file]["type"], files[file]["size"], files[file]["architecture"]])
418 install_bytes += float(files[file]["size"])
420 # Copy the .changes file across for suite which need it.
423 for suite in changes["distribution"].keys():
424 if Cnf.has_key("Suite::%s::CopyChanges" % (suite)):
425 copy_changes[Cnf["Suite::%s::CopyChanges" % (suite)]] = ""
426 # and the .dak file...
427 if Cnf.has_key("Suite::%s::CopyDotDak" % (suite)):
428 copy_dot_dak[Cnf["Suite::%s::CopyDotDak" % (suite)]] = ""
429 for dest in copy_changes.keys():
430 utils.copy(pkg.changes_file, Cnf["Dir::Root"] + dest)
431 for dest in copy_dot_dak.keys():
432 utils.copy(Upload.pkg.changes_file[:-8]+".dak", dest)
434 projectB.query("COMMIT WORK")
436 # Move the .changes into the 'done' directory
437 utils.move (pkg.changes_file,
438 os.path.join(Cnf["Dir::Queue::Done"], os.path.basename(pkg.changes_file)))
440 # Remove the .dak file
441 os.unlink(Upload.pkg.changes_file[:-8]+".dak")
443 if changes["architecture"].has_key("source") and Urgency_Logger:
444 Urgency_Logger.log(dsc["source"], dsc["version"], changes["urgency"])
446 # Undo the work done in queue.py(accept) to help auto-building
448 projectB.query("BEGIN WORK")
449 for suite in changes["distribution"].keys():
450 if suite not in Cnf.ValueList("Dinstall::QueueBuildSuites"):
452 now_date = time.strftime("%Y-%m-%d %H:%M")
453 suite_id = database.get_suite_id(suite)
454 dest_dir = Cnf["Dir::QueueBuild"]
455 if Cnf.FindB("Dinstall::SecurityQueueBuild"):
456 dest_dir = os.path.join(dest_dir, suite)
457 for file in files.keys():
458 dest = os.path.join(dest_dir, file)
459 # Remove it from the list of packages for later processing by apt-ftparchive
460 projectB.query("UPDATE queue_build SET in_queue = 'f', last_used = '%s' WHERE filename = '%s' AND suite = %s" % (now_date, dest, suite_id))
461 if not Cnf.FindB("Dinstall::SecurityQueueBuild"):
462 # Update the symlink to point to the new location in the pool
463 pool_location = utils.poolify (changes["source"], files[file]["component"])
464 src = os.path.join(Cnf["Dir::Pool"], pool_location, os.path.basename(file))
465 if os.path.islink(dest):
467 os.symlink(src, dest)
468 # Update last_used on any non-upload .orig.tar.gz symlink
470 # Determine the .orig.tar.gz file name
471 for dsc_file in dsc_files.keys():
472 if dsc_file.endswith(".orig.tar.gz"):
473 orig_tar_gz = os.path.join(dest_dir, dsc_file)
474 # Remove it from the list of packages for later processing by apt-ftparchive
475 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))
476 projectB.query("COMMIT WORK")
481 ################################################################################
483 def stable_install (summary, short_summary):
486 print "Installing to stable."
488 # Begin a transaction; if we bomb out anywhere between here and
489 # the COMMIT WORK below, the DB won't be changed.
490 projectB.query("BEGIN WORK")
492 # Add the source to stable (and remove it from proposed-updates)
493 for file in files.keys():
494 if files[file]["type"] == "dsc":
495 package = dsc["source"]
496 version = dsc["version"]; # NB: not files[file]["version"], that has no epoch
497 q = projectB.query("SELECT id FROM source WHERE source = '%s' AND version = '%s'" % (package, version))
500 utils.fubar("[INTERNAL ERROR] couldn't find '%s' (%s) in source table." % (package, version))
502 suite_id = database.get_suite_id('proposed-updates')
503 projectB.query("DELETE FROM src_associations WHERE suite = '%s' AND source = '%s'" % (suite_id, source_id))
504 suite_id = database.get_suite_id('stable')
505 projectB.query("INSERT INTO src_associations (suite, source) VALUES ('%s', '%s')" % (suite_id, source_id))
507 # Add the binaries to stable (and remove it/them from proposed-updates)
508 for file in files.keys():
509 if files[file]["type"] == "deb":
510 package = files[file]["package"]
511 version = files[file]["version"]
512 architecture = files[file]["architecture"]
513 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))
516 utils.fubar("[INTERNAL ERROR] couldn't find '%s' (%s for %s architecture) in binaries table." % (package, version, architecture))
519 suite_id = database.get_suite_id('proposed-updates')
520 projectB.query("DELETE FROM bin_associations WHERE suite = '%s' AND bin = '%s'" % (suite_id, binary_id))
521 suite_id = database.get_suite_id('stable')
522 projectB.query("INSERT INTO bin_associations (suite, bin) VALUES ('%s', '%s')" % (suite_id, binary_id))
524 projectB.query("COMMIT WORK")
526 utils.move (pkg.changes_file, Cnf["Dir::Morgue"] + '/process-accepted/' + os.path.basename(pkg.changes_file))
528 ## Update the Stable ChangeLog file
529 new_changelog_filename = Cnf["Dir::Root"] + Cnf["Suite::Stable::ChangeLogBase"] + ".ChangeLog"
530 changelog_filename = Cnf["Dir::Root"] + Cnf["Suite::Stable::ChangeLogBase"] + "ChangeLog"
531 if os.path.exists(new_changelog_filename):
532 os.unlink (new_changelog_filename)
534 new_changelog = utils.open_file(new_changelog_filename, 'w')
535 for file in files.keys():
536 if files[file]["type"] == "deb":
537 new_changelog.write("stable/%s/binary-%s/%s\n" % (files[file]["component"], files[file]["architecture"], file))
538 elif utils.re_issource.match(file):
539 new_changelog.write("stable/%s/source/%s\n" % (files[file]["component"], file))
541 new_changelog.write("%s\n" % (file))
542 chop_changes = queue.re_fdnic.sub("\n", changes["changes"])
543 new_changelog.write(chop_changes + '\n\n')
544 if os.access(changelog_filename, os.R_OK) != 0:
545 changelog = utils.open_file(changelog_filename)
546 new_changelog.write(changelog.read())
547 new_changelog.close()
548 if os.access(changelog_filename, os.R_OK) != 0:
549 os.unlink(changelog_filename)
550 utils.move(new_changelog_filename, changelog_filename)
554 if not Options["No-Mail"] and changes["architecture"].has_key("source"):
555 Subst["__SUITE__"] = " into stable"
556 Subst["__SUMMARY__"] = summary
557 mail_message = utils.TemplateSubst(Subst,Cnf["Dir::Templates"]+"/process-accepted.install")
558 utils.send_mail(mail_message)
559 Upload.announce(short_summary, 1)
561 # Finally remove the .dak file
562 dot_dak_file = os.path.join(Cnf["Suite::Proposed-Updates::CopyDotDak"], os.path.basename(Upload.pkg.changes_file[:-8]+".dak"))
563 os.unlink(dot_dak_file)
565 ################################################################################
567 def process_it (changes_file):
568 global reject_message
572 # Absolutize the filename to avoid the requirement of being in the
573 # same directory as the .changes file.
574 pkg.changes_file = os.path.abspath(changes_file)
576 # And since handling of installs to stable munges with the CWD
577 # save and restore it.
578 pkg.directory = os.getcwd()
580 if installing_to_stable:
581 old = Upload.pkg.changes_file
582 Upload.pkg.changes_file = os.path.basename(old)
583 os.chdir(Cnf["Suite::Proposed-Updates::CopyDotDak"])
587 Upload.update_subst()
589 if installing_to_stable:
590 Upload.pkg.changes_file = old
596 os.chdir(pkg.directory)
598 ###############################################################################
601 global projectB, Logger, Urgency_Logger, installing_to_stable
603 changes_files = init()
605 # -n/--dry-run invalidates some other options which would involve things happening
606 if Options["No-Action"]:
607 Options["Automatic"] = ""
609 # Check that we aren't going to clash with the daily cron job
611 if not Options["No-Action"] and os.path.exists("%s/Archive_Maintenance_In_Progress" % (Cnf["Dir::Root"])) and not Options["No-Lock"]:
612 utils.fubar("Archive maintenance in progress. Try again later.")
614 # If running from within proposed-updates; assume an install to stable
615 if os.getcwd().find('proposed-updates') != -1:
616 installing_to_stable = 1
618 # Obtain lock if not in no-action mode and initialize the log
619 if not Options["No-Action"]:
620 lock_fd = os.open(Cnf["Dinstall::LockFile"], os.O_RDWR | os.O_CREAT)
622 fcntl.lockf(lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
624 if errno.errorcode[e.errno] == 'EACCES' or errno.errorcode[e.errno] == 'EAGAIN':
625 utils.fubar("Couldn't obtain lock; assuming another 'dak process-accepted' is already running.")
628 Logger = Upload.Logger = logging.Logger(Cnf, "process-accepted")
629 if not installing_to_stable and Cnf.get("Dir::UrgencyLog"):
630 Urgency_Logger = Urgency_Log(Cnf)
632 # Initialize the substitution template mapping global
633 bcc = "X-DAK: dak process-accepted\nX-Katie: $Revision: 1.18 $"
634 if Cnf.has_key("Dinstall::Bcc"):
635 Subst["__BCC__"] = bcc + "\nBcc: %s" % (Cnf["Dinstall::Bcc"])
637 Subst["__BCC__"] = bcc
639 # Sort the .changes files so that we process sourceful ones first
640 changes_files.sort(utils.changes_compare)
642 # Process the changes files
643 for changes_file in changes_files:
644 print "\n" + changes_file
645 process_it (changes_file)
649 if install_count > 1:
651 sys.stderr.write("Installed %d package %s, %s.\n" % (install_count, sets, utils.size_type(int(install_bytes))))
652 Logger.log(["total",install_count,install_bytes])
654 if not Options["No-Action"]:
657 Urgency_Logger.close()
659 ###############################################################################
661 if __name__ == '__main__':