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 *
39 from daklib.regexes import re_default_answer, re_issource, re_fdnic
41 ###############################################################################
61 installing_to_stable = 0
63 ###############################################################################
65 # FIXME: this should go away to some Debian specific file
66 # FIXME: should die if file already exists
69 "Urgency Logger object"
70 def __init__ (self, Cnf):
71 "Initialize a new Urgency Logger object"
73 self.timestamp = time.strftime("%Y%m%d%H%M%S")
74 # Create the log directory if it doesn't exist
75 self.log_dir = Cnf["Dir::UrgencyLog"]
76 if not os.path.exists(self.log_dir) or not os.access(self.log_dir, os.W_OK):
77 utils.warn("UrgencyLog directory %s does not exist or is not writeable, using /srv/ftp.debian.org/tmp/ instead" % (self.log_dir))
78 self.log_dir = '/srv/ftp.debian.org/tmp/'
80 self.log_filename = "%s/.install-urgencies-%s.new" % (self.log_dir, self.timestamp)
81 self.log_file = utils.open_file(self.log_filename, 'w')
84 def log (self, source, version, urgency):
86 self.log_file.write(" ".join([source, version, urgency])+'\n')
91 "Close a Logger object"
95 new_filename = "%s/install-urgencies-%s" % (self.log_dir, self.timestamp)
96 utils.move(self.log_filename, new_filename)
98 os.unlink(self.log_filename)
100 ###############################################################################
102 def reject (str, prefix="Rejected: "):
103 global reject_message
105 reject_message += prefix + str + "\n"
107 # Recheck anything that relies on the database; since that's not
108 # frozen between accept and our run time.
113 for checkfile in files.keys():
114 # The .orig.tar.gz can disappear out from under us is it's a
115 # duplicate of one in the archive.
116 if not files.has_key(checkfile):
118 # Check that the source still exists
119 if files[checkfile]["type"] == "deb":
120 source_version = files[checkfile]["source version"]
121 source_package = files[checkfile]["source package"]
122 if not changes["architecture"].has_key("source") \
123 and not Upload.source_exists(source_package, source_version, changes["distribution"].keys()):
124 reject("no source found for %s %s (%s)." % (source_package, source_version, checkfile))
126 # Version and file overwrite checks
127 if not installing_to_stable:
128 if files[checkfile]["type"] == "deb":
129 reject(Upload.check_binary_against_db(checkfile), "")
130 elif files[checkfile]["type"] == "dsc":
131 reject(Upload.check_source_against_db(checkfile), "")
132 (reject_msg, is_in_incoming) = Upload.check_dsc_against_db(checkfile)
133 reject(reject_msg, "")
135 # propogate in the case it is in the override tables:
136 if changes.has_key("propdistribution"):
137 for suite in changes["propdistribution"].keys():
138 if Upload.in_override_p(files[checkfile]["package"], files[checkfile]["component"], suite, files[checkfile].get("dbtype",""), checkfile):
141 nopropogate[suite] = 1
143 for suite in propogate.keys():
144 if suite in nopropogate:
146 changes["distribution"][suite] = 1
148 for checkfile in files.keys():
149 # Check the package is still in the override tables
150 for suite in changes["distribution"].keys():
151 if not Upload.in_override_p(files[checkfile]["package"], files[checkfile]["component"], suite, files[checkfile].get("dbtype",""), checkfile):
152 reject("%s is NEW for %s." % (checkfile, suite))
154 ###############################################################################
157 global Cnf, Options, Upload, projectB, changes, dsc, dsc_files, files, pkg, Subst
159 Cnf = utils.get_conf()
161 Arguments = [('a',"automatic","Dinstall::Options::Automatic"),
162 ('h',"help","Dinstall::Options::Help"),
163 ('n',"no-action","Dinstall::Options::No-Action"),
164 ('p',"no-lock", "Dinstall::Options::No-Lock"),
165 ('s',"no-mail", "Dinstall::Options::No-Mail")]
167 for i in ["automatic", "help", "no-action", "no-lock", "no-mail", "version"]:
168 if not Cnf.has_key("Dinstall::Options::%s" % (i)):
169 Cnf["Dinstall::Options::%s" % (i)] = ""
171 changes_files = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
172 Options = Cnf.SubTree("Dinstall::Options")
177 Upload = queue.Upload(Cnf)
178 projectB = Upload.projectB
180 changes = Upload.pkg.changes
182 dsc_files = Upload.pkg.dsc_files
183 files = Upload.pkg.files
189 ###############################################################################
191 def usage (exit_code=0):
192 print """Usage: dak process-accepted [OPTION]... [CHANGES]...
193 -a, --automatic automatic run
194 -h, --help show this help and exit.
195 -n, --no-action don't do anything
196 -p, --no-lock don't check lockfile !! for cron.daily only !!
197 -s, --no-mail don't send any mail
198 -V, --version display the version number and exit"""
201 ###############################################################################
204 (summary, short_summary) = Upload.build_summaries()
206 (prompt, answer) = ("", "XXX")
207 if Options["No-Action"] or Options["Automatic"]:
210 if reject_message.find("Rejected") != -1:
211 print "REJECT\n" + reject_message,
212 prompt = "[R]eject, Skip, Quit ?"
213 if Options["Automatic"]:
216 print "INSTALL to " + ", ".join(changes["distribution"].keys())
217 print reject_message + summary,
218 prompt = "[I]nstall, Skip, Quit ?"
219 if Options["Automatic"]:
222 while prompt.find(answer) == -1:
223 answer = utils.our_raw_input(prompt)
224 m = re_default_answer.match(prompt)
227 answer = answer[:1].upper()
232 if not installing_to_stable:
235 stable_install(summary, short_summary)
239 ###############################################################################
241 # Our reject is not really a reject, but an unaccept, but since a) the
242 # code for that is non-trivial (reopen bugs, unannounce etc.), b) this
243 # should be exteremly rare, for now we'll go with whining at our admin
247 Subst["__REJECTOR_ADDRESS__"] = Cnf["Dinstall::MyEmailAddress"]
248 Subst["__REJECT_MESSAGE__"] = reject_message
249 Subst["__CC__"] = "Cc: " + Cnf["Dinstall::MyEmailAddress"]
250 reject_mail_message = utils.TemplateSubst(Subst,Cnf["Dir::Templates"]+"/process-accepted.unaccept")
252 # Write the rejection email out as the <foo>.reason file
253 reason_filename = os.path.basename(pkg.changes_file[:-8]) + ".reason"
254 reject_filename = Cnf["Dir::Queue::Reject"] + '/' + reason_filename
255 # If we fail here someone is probably trying to exploit the race
256 # so let's just raise an exception ...
257 if os.path.exists(reject_filename):
258 os.unlink(reject_filename)
259 fd = os.open(reject_filename, os.O_RDWR|os.O_CREAT|os.O_EXCL, 0644)
260 os.write(fd, reject_mail_message)
263 utils.send_mail(reject_mail_message)
264 Logger.log(["unaccepted", pkg.changes_file])
266 ###############################################################################
269 global install_count, install_bytes
273 Logger.log(["installing changes",pkg.changes_file])
275 # Begin a transaction; if we bomb out anywhere between here and the COMMIT WORK below, the DB will not be changed.
276 projectB.query("BEGIN WORK")
278 # Ensure that we have all the hashes we need below.
279 rejmsg = utils.ensure_hashes(changes, dsc, files, dsc_files)
281 # There were errors. Print them and SKIP the changes.
286 # Add the .dsc file to the DB
287 for newfile in files.keys():
288 if files[newfile]["type"] == "dsc":
289 package = dsc["source"]
290 version = dsc["version"] # NB: not files[file]["version"], that has no epoch
291 maintainer = dsc["maintainer"]
292 maintainer = maintainer.replace("'", "\\'")
293 maintainer_id = database.get_or_set_maintainer_id(maintainer)
294 changedby = changes["changed-by"]
295 changedby = changedby.replace("'", "\\'")
296 changedby_id = database.get_or_set_maintainer_id(changedby)
297 fingerprint_id = database.get_or_set_fingerprint_id(dsc["fingerprint"])
298 install_date = time.strftime("%Y-%m-%d")
299 filename = files[newfile]["pool name"] + newfile
300 dsc_component = files[newfile]["component"]
301 dsc_location_id = files[newfile]["location id"]
302 if dsc.has_key("dm-upload-allowed") and dsc["dm-upload-allowed"] == "yes":
303 dm_upload_allowed = "true"
305 dm_upload_allowed = "false"
306 if not files[newfile].has_key("files id") or not files[newfile]["files id"]:
307 files[newfile]["files id"] = database.set_files_id (filename, files[newfile]["size"], files[newfile]["md5sum"], files[newfile]["sha1sum"], files[newfile]["sha256sum"], dsc_location_id)
308 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)"
309 % (package, version, maintainer_id, changedby_id, files[newfile]["files id"], install_date, fingerprint_id, dm_upload_allowed))
311 for suite in changes["distribution"].keys():
312 suite_id = database.get_suite_id(suite)
313 projectB.query("INSERT INTO src_associations (suite, source) VALUES (%d, currval('source_id_seq'))" % (suite_id))
315 # Add the source files to the DB (files and dsc_files)
316 projectB.query("INSERT INTO dsc_files (source, file) VALUES (currval('source_id_seq'), %d)" % (files[newfile]["files id"]))
317 for dsc_file in dsc_files.keys():
318 filename = files[newfile]["pool name"] + dsc_file
319 # If the .orig.tar.gz is already in the pool, it's
320 # files id is stored in dsc_files by check_dsc().
321 files_id = dsc_files[dsc_file].get("files id", None)
323 files_id = database.get_files_id(filename, dsc_files[dsc_file]["size"], dsc_files[dsc_file]["md5sum"], dsc_location_id)
324 # FIXME: needs to check for -1/-2 and or handle exception
326 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)
327 projectB.query("INSERT INTO dsc_files (source, file) VALUES (currval('source_id_seq'), %d)" % (files_id))
329 # Add the src_uploaders to the DB
330 uploader_ids = [maintainer_id]
331 if dsc.has_key("uploaders"):
332 for u in dsc["uploaders"].split(","):
333 u = u.replace("'", "\\'")
336 database.get_or_set_maintainer_id(u))
338 for u in uploader_ids:
339 if added_ids.has_key(u):
340 utils.warn("Already saw uploader %s for source %s" % (u, package))
343 projectB.query("INSERT INTO src_uploaders (source, maintainer) VALUES (currval('source_id_seq'), %d)" % (u))
346 # Add the .deb files to the DB
347 for newfile in files.keys():
348 if files[newfile]["type"] == "deb":
349 package = files[newfile]["package"]
350 version = files[newfile]["version"]
351 maintainer = files[newfile]["maintainer"]
352 maintainer = maintainer.replace("'", "\\'")
353 maintainer_id = database.get_or_set_maintainer_id(maintainer)
354 fingerprint_id = database.get_or_set_fingerprint_id(changes["fingerprint"])
355 architecture = files[newfile]["architecture"]
356 architecture_id = database.get_architecture_id (architecture)
357 filetype = files[newfile]["dbtype"]
358 source = files[newfile]["source package"]
359 source_version = files[newfile]["source version"]
360 filename = files[newfile]["pool name"] + newfile
361 if not files[newfile].has_key("location id") or not files[newfile]["location id"]:
362 files[newfile]["location id"] = database.get_location_id(Cnf["Dir::Pool"],files[newfile]["component"],utils.where_am_i())
363 if not files[newfile].has_key("files id") or not files[newfile]["files id"]:
364 files[newfile]["files id"] = database.set_files_id (filename, files[newfile]["size"], files[newfile]["md5sum"], files[newfile]["sha1sum"], files[newfile]["sha256sum"], files[newfile]["location id"])
365 source_id = database.get_source_id (source, source_version)
367 projectB.query("INSERT INTO binaries (package, version, maintainer, source, architecture, file, type, sig_fpr) VALUES ('%s', '%s', %d, %d, %d, %d, '%s', %d)"
368 % (package, version, maintainer_id, source_id, architecture_id, files[newfile]["files id"], filetype, fingerprint_id))
370 raise NoSourceFieldError, "Unable to find a source id for %s (%s), %s, file %s, type %s, signed by %s" % (package, version, architecture, newfile, filetype, changes["fingerprint"])
371 for suite in changes["distribution"].keys():
372 suite_id = database.get_suite_id(suite)
373 projectB.query("INSERT INTO bin_associations (suite, bin) VALUES (%d, currval('binaries_id_seq'))" % (suite_id))
375 # If the .orig.tar.gz is in a legacy directory we need to poolify
376 # it, so that apt-get source (and anything else that goes by the
377 # "Directory:" field in the Sources.gz file) works.
378 orig_tar_id = Upload.pkg.orig_tar_id
379 orig_tar_location = Upload.pkg.orig_tar_location
380 legacy_source_untouchable = Upload.pkg.legacy_source_untouchable
381 if orig_tar_id and orig_tar_location == "legacy":
382 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))
385 # Is this an old upload superseded by a newer -sa upload? (See check_dsc() for details)
386 if legacy_source_untouchable.has_key(qid["files_id"]):
388 # First move the files to the new location
389 legacy_filename = qid["path"] + qid["filename"]
390 pool_location = utils.poolify (changes["source"], files[newfile]["component"])
391 pool_filename = pool_location + os.path.basename(qid["filename"])
392 destination = Cnf["Dir::Pool"] + pool_location
393 utils.move(legacy_filename, destination)
394 # Then Update the DB's files table
395 q = projectB.query("UPDATE files SET filename = '%s', location = '%s' WHERE id = '%s'" % (pool_filename, dsc_location_id, qid["files_id"]))
397 # If this is a sourceful diff only upload that is moving non-legacy
398 # cross-component we need to copy the .orig.tar.gz into the new
399 # component too for the same reasons as above.
401 if changes["architecture"].has_key("source") and orig_tar_id and \
402 orig_tar_location != "legacy" and orig_tar_location != dsc_location_id:
403 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))
404 ql = q.getresult()[0]
405 old_filename = ql[0] + ql[1]
409 file_sha256sum = ql[5]
410 new_filename = utils.poolify(changes["source"], dsc_component) + os.path.basename(old_filename)
411 new_files_id = database.get_files_id(new_filename, file_size, file_md5sum, dsc_location_id)
412 if new_files_id == None:
413 utils.copy(old_filename, Cnf["Dir::Pool"] + new_filename)
414 new_files_id = database.set_files_id(new_filename, file_size, file_md5sum, file_sha1sum, file_sha256sum, dsc_location_id)
415 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))
417 # Install the files into the pool
418 for newfile in files.keys():
419 destination = Cnf["Dir::Pool"] + files[newfile]["pool name"] + newfile
420 utils.move(newfile, destination)
421 Logger.log(["installed", newfile, files[newfile]["type"], files[newfile]["size"], files[newfile]["architecture"]])
422 install_bytes += float(files[newfile]["size"])
424 # Copy the .changes file across for suite which need it.
427 for suite in changes["distribution"].keys():
428 if Cnf.has_key("Suite::%s::CopyChanges" % (suite)):
429 copy_changes[Cnf["Suite::%s::CopyChanges" % (suite)]] = ""
430 # and the .dak file...
431 if Cnf.has_key("Suite::%s::CopyDotDak" % (suite)):
432 copy_dot_dak[Cnf["Suite::%s::CopyDotDak" % (suite)]] = ""
433 for dest in copy_changes.keys():
434 utils.copy(pkg.changes_file, Cnf["Dir::Root"] + dest)
435 for dest in copy_dot_dak.keys():
436 utils.copy(Upload.pkg.changes_file[:-8]+".dak", dest)
438 projectB.query("COMMIT WORK")
440 # Move the .changes into the 'done' directory
441 utils.move (pkg.changes_file,
442 os.path.join(Cnf["Dir::Queue::Done"], os.path.basename(pkg.changes_file)))
444 # Remove the .dak file
445 os.unlink(Upload.pkg.changes_file[:-8]+".dak")
447 if changes["architecture"].has_key("source") and Urgency_Logger:
448 Urgency_Logger.log(dsc["source"], dsc["version"], changes["urgency"])
450 # Undo the work done in queue.py(accept) to help auto-building
452 projectB.query("BEGIN WORK")
453 for suite in changes["distribution"].keys():
454 if suite not in Cnf.ValueList("Dinstall::QueueBuildSuites"):
456 now_date = time.strftime("%Y-%m-%d %H:%M")
457 suite_id = database.get_suite_id(suite)
458 dest_dir = Cnf["Dir::QueueBuild"]
459 if Cnf.FindB("Dinstall::SecurityQueueBuild"):
460 dest_dir = os.path.join(dest_dir, suite)
461 for newfile in files.keys():
462 dest = os.path.join(dest_dir, newfile)
463 # Remove it from the list of packages for later processing by apt-ftparchive
464 projectB.query("UPDATE queue_build SET in_queue = 'f', last_used = '%s' WHERE filename = '%s' AND suite = %s" % (now_date, dest, suite_id))
465 if not Cnf.FindB("Dinstall::SecurityQueueBuild"):
466 # Update the symlink to point to the new location in the pool
467 pool_location = utils.poolify (changes["source"], files[newfile]["component"])
468 src = os.path.join(Cnf["Dir::Pool"], pool_location, os.path.basename(newfile))
469 if os.path.islink(dest):
471 os.symlink(src, dest)
472 # Update last_used on any non-upload .orig.tar.gz symlink
474 # Determine the .orig.tar.gz file name
475 for dsc_file in dsc_files.keys():
476 if dsc_file.endswith(".orig.tar.gz"):
477 orig_tar_gz = os.path.join(dest_dir, dsc_file)
478 # Remove it from the list of packages for later processing by apt-ftparchive
479 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))
480 projectB.query("COMMIT WORK")
485 ################################################################################
487 def stable_install (summary, short_summary):
490 print "Installing to stable."
492 # Begin a transaction; if we bomb out anywhere between here and
493 # the COMMIT WORK below, the DB won't be changed.
494 projectB.query("BEGIN WORK")
496 # Add the source to stable (and remove it from proposed-updates)
497 for newfile in files.keys():
498 if files[newfile]["type"] == "dsc":
499 package = dsc["source"]
500 version = dsc["version"]; # NB: not files[file]["version"], that has no epoch
501 q = projectB.query("SELECT id FROM source WHERE source = '%s' AND version = '%s'" % (package, version))
504 utils.fubar("[INTERNAL ERROR] couldn't find '%s' (%s) in source table." % (package, version))
506 suite_id = database.get_suite_id('proposed-updates')
507 projectB.query("DELETE FROM src_associations WHERE suite = '%s' AND source = '%s'" % (suite_id, source_id))
508 suite_id = database.get_suite_id('stable')
509 projectB.query("INSERT INTO src_associations (suite, source) VALUES ('%s', '%s')" % (suite_id, source_id))
511 # Add the binaries to stable (and remove it/them from proposed-updates)
512 for newfile in files.keys():
513 if files[newfile]["type"] == "deb":
514 package = files[newfile]["package"]
515 version = files[newfile]["version"]
516 architecture = files[newfile]["architecture"]
517 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))
520 utils.fubar("[INTERNAL ERROR] couldn't find '%s' (%s for %s architecture) in binaries table." % (package, version, architecture))
523 suite_id = database.get_suite_id('proposed-updates')
524 projectB.query("DELETE FROM bin_associations WHERE suite = '%s' AND bin = '%s'" % (suite_id, binary_id))
525 suite_id = database.get_suite_id('stable')
526 projectB.query("INSERT INTO bin_associations (suite, bin) VALUES ('%s', '%s')" % (suite_id, binary_id))
528 projectB.query("COMMIT WORK")
530 utils.move (pkg.changes_file, Cnf["Dir::Morgue"] + '/process-accepted/' + os.path.basename(pkg.changes_file))
532 ## Update the Stable ChangeLog file
533 new_changelog_filename = Cnf["Dir::Root"] + Cnf["Suite::Stable::ChangeLogBase"] + ".ChangeLog"
534 changelog_filename = Cnf["Dir::Root"] + Cnf["Suite::Stable::ChangeLogBase"] + "ChangeLog"
535 if os.path.exists(new_changelog_filename):
536 os.unlink (new_changelog_filename)
538 new_changelog = utils.open_file(new_changelog_filename, 'w')
539 for newfile in files.keys():
540 if files[newfile]["type"] == "deb":
541 new_changelog.write("stable/%s/binary-%s/%s\n" % (files[newfile]["component"], files[newfile]["architecture"], newfile))
542 elif re_issource.match(newfile):
543 new_changelog.write("stable/%s/source/%s\n" % (files[newfile]["component"], newfile))
545 new_changelog.write("%s\n" % (newfile))
546 chop_changes = re_fdnic.sub("\n", changes["changes"])
547 new_changelog.write(chop_changes + '\n\n')
548 if os.access(changelog_filename, os.R_OK) != 0:
549 changelog = utils.open_file(changelog_filename)
550 new_changelog.write(changelog.read())
551 new_changelog.close()
552 if os.access(changelog_filename, os.R_OK) != 0:
553 os.unlink(changelog_filename)
554 utils.move(new_changelog_filename, changelog_filename)
558 if not Options["No-Mail"] and changes["architecture"].has_key("source"):
559 Subst["__SUITE__"] = " into stable"
560 Subst["__SUMMARY__"] = summary
561 mail_message = utils.TemplateSubst(Subst,Cnf["Dir::Templates"]+"/process-accepted.install")
562 utils.send_mail(mail_message)
563 Upload.announce(short_summary, 1)
565 # Finally remove the .dak file
566 dot_dak_file = os.path.join(Cnf["Suite::Proposed-Updates::CopyDotDak"], os.path.basename(Upload.pkg.changes_file[:-8]+".dak"))
567 os.unlink(dot_dak_file)
569 ################################################################################
571 def process_it (changes_file):
572 global reject_message
576 # Absolutize the filename to avoid the requirement of being in the
577 # same directory as the .changes file.
578 pkg.changes_file = os.path.abspath(changes_file)
580 # And since handling of installs to stable munges with the CWD
581 # save and restore it.
582 pkg.directory = os.getcwd()
584 if installing_to_stable:
585 old = Upload.pkg.changes_file
586 Upload.pkg.changes_file = os.path.basename(old)
587 os.chdir(Cnf["Suite::Proposed-Updates::CopyDotDak"])
591 Upload.update_subst()
593 if installing_to_stable:
594 Upload.pkg.changes_file = old
600 os.chdir(pkg.directory)
602 ###############################################################################
605 global projectB, Logger, Urgency_Logger, installing_to_stable
607 changes_files = init()
609 # -n/--dry-run invalidates some other options which would involve things happening
610 if Options["No-Action"]:
611 Options["Automatic"] = ""
613 # Check that we aren't going to clash with the daily cron job
615 if not Options["No-Action"] and os.path.exists("%s/Archive_Maintenance_In_Progress" % (Cnf["Dir::Root"])) and not Options["No-Lock"]:
616 utils.fubar("Archive maintenance in progress. Try again later.")
618 # If running from within proposed-updates; assume an install to stable
619 if os.getcwd().find('proposed-updates') != -1:
620 installing_to_stable = 1
622 # Obtain lock if not in no-action mode and initialize the log
623 if not Options["No-Action"]:
624 lock_fd = os.open(Cnf["Dinstall::LockFile"], os.O_RDWR | os.O_CREAT)
626 fcntl.lockf(lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
628 if errno.errorcode[e.errno] == 'EACCES' or errno.errorcode[e.errno] == 'EAGAIN':
629 utils.fubar("Couldn't obtain lock; assuming another 'dak process-accepted' is already running.")
632 Logger = Upload.Logger = logging.Logger(Cnf, "process-accepted")
633 if not installing_to_stable and Cnf.get("Dir::UrgencyLog"):
634 Urgency_Logger = Urgency_Log(Cnf)
636 # Initialize the substitution template mapping global
637 bcc = "X-DAK: dak process-accepted\nX-Katie: $Revision: 1.18 $"
638 if Cnf.has_key("Dinstall::Bcc"):
639 Subst["__BCC__"] = bcc + "\nBcc: %s" % (Cnf["Dinstall::Bcc"])
641 Subst["__BCC__"] = bcc
643 # Sort the .changes files so that we process sourceful ones first
644 changes_files.sort(utils.changes_compare)
646 # Process the changes files
647 for changes_file in changes_files:
648 print "\n" + changes_file
649 process_it (changes_file)
653 if install_count > 1:
655 sys.stderr.write("Installed %d package %s, %s.\n" % (install_count, sets, utils.size_type(int(install_bytes))))
656 Logger.log(["total",install_count,install_bytes])
658 if not Options["No-Action"]:
661 Urgency_Logger.close()
663 ###############################################################################
665 if __name__ == '__main__':