4 Checks Debian packages from Incoming
5 @contact: Debian FTP Master <ftpmaster@debian.org>
6 @copyright: 2000, 2001, 2002, 2003, 2004, 2005, 2006 James Troup <james@nocrew.org>
7 @copyright: 2009 Joerg Jaspert <joerg@debian.org>
8 @copyright: 2009 Mark Hymers <mhy@debian.org>
9 @copyright: 2009 Frank Lichtenheld <djpig@debian.org>
10 @license: GNU General Public License version 2 or later
13 # This program is free software; you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation; either version 2 of the License, or
16 # (at your option) any later version.
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 # based on process-unchecked and process-accepted
29 ## pu|pa: locking (daily.lock)
30 ## pu|pa: parse arguments -> list of changes files
31 ## pa: initialize urgency log
32 ## pu|pa: sort changes list
36 ## pu: copy CHG to tempdir
37 ## pu: check CHG signature
38 ## pu: parse changes file
40 ## pu: check distribution (mappings, rejects)
41 ## pu: copy FILES to tempdir
42 ## pu: check whether CHG already exists in CopyChanges
43 ## pu: check whether FILES already exist in one of the policy queues
45 ## pu: extract control information
46 ## pu: various checks on control information
47 ## pu|pa: search for source (in CHG, projectb, policy queues)
48 ## pu|pa: check whether "Version" fulfills target suite requirements/suite propagation
49 ## pu|pa: check whether deb already exists in the pool
51 ## pu: various checks on filenames and CHG consistency
52 ## pu: if isdsc: check signature
56 ## //pu: check whether file already exists in the pool
57 ## pu: store what "Component" the package is currently in
58 ## pu: check whether we found everything we were looking for in CHG
60 ## pu: check whether we need and have ONE DSC
62 ## pu: various checks //maybe drop some of the in favor of lintian
63 ## pu|pa: check whether "Version" fulfills target suite requirements/suite propagation
64 ## pu: check whether DSC_FILES is consistent with "Format"
65 ## for src in DSC_FILES:
66 ## pu|pa: check whether file already exists in the pool (with special handling for .orig.tar.gz)
67 ## pu: create new tempdir
68 ## pu: create symlink mirror of source
70 ## pu: extract changelog information for BTS
71 ## //pu: create missing .orig symlink
72 ## pu: check with lintian
74 ## pu: check checksums and sizes
75 ## for file in DSC_FILES:
76 ## pu: check checksums and sizes
77 ## pu: CHG: check urgency
79 ## pu: extract contents list and check for dubious timestamps
80 ## pu: check that the uploader is actually allowed to upload the package
82 ### if stable_install:
83 ### pa: remove from p-u
85 ### pa: move CHG to morgue
86 ### pa: append data to ChangeLog
88 ### pa: remove .dak file
90 ### pa: add dsc to db:
91 ### for file in DSC_FILES:
92 ### pa: add file to file
93 ### pa: add file to dsc_files
94 ### pa: create source entry
95 ### pa: update source associations
96 ### pa: update src_uploaders
98 ### pa: add deb to db:
99 ### pa: add file to file
100 ### pa: find source entry
101 ### pa: create binaries entry
102 ### pa: update binary associations
103 ### pa: .orig component move
104 ### pa: move files to pool
106 ### pa: move CHG to done/
107 ### pa: change entry in queue_build
108 ## pu: use dispatch table to choose target queue:
110 ## pu: write .dak file
114 ## pu: run autobyhand script
115 ## pu: if stuff left, do byhand or accept
116 ## elsif targetqueue in (oldstable, stable, embargo, unembargo):
117 ## pu: write .dak file
118 ## pu: check overrides
122 ## pu: write .dak file
123 ## pu: move to ACCEPTED
125 ## pu: create files for BTS
126 ## pu: create entry in queue_build
127 ## pu: check overrides
131 ## Parsing changes (check for duplicates)
135 # New check layout (TODO: Implement)
139 ### version checks (suite)
153 ### src relation check
156 ## Database insertion (? copy from stuff)
157 ### BYHAND / NEW / Policy queues
162 from errno import EACCES, EAGAIN
168 from sqlalchemy.orm.exc import NoResultFound
170 from daklib import daklog
171 from daklib.queue import *
172 from daklib.queue_install import *
173 from daklib import utils
174 from daklib.dbconn import *
175 from daklib.urgencylog import UrgencyLog
176 from daklib.summarystats import SummaryStats
177 from daklib.holding import Holding
178 from daklib.config import Config
179 from daklib.regexes import re_match_expired
181 ###############################################################################
186 ###############################################################################
188 def usage (exit_code=0):
189 print """Usage: dak process-upload [OPTION]... [CHANGES]...
190 -a, --automatic automatic run
191 -h, --help show this help and exit.
192 -n, --no-action don't do anything
193 -p, --no-lock don't check lockfile !! for cron.daily only !!
194 -s, --no-mail don't send any mail
195 -V, --version display the version number and exit"""
198 ###############################################################################
201 if not Options["No-Action"]:
202 # Clean out the queue files
203 session = DBConn().session()
204 session.execute("DELETE FROM changes_pending_files WHERE id NOT IN (SELECT file_id FROM changes_pending_files_map )")
209 def action(u, session):
215 # changes["distribution"] may not exist in corner cases
216 # (e.g. unreadable changes files)
217 if not u.pkg.changes.has_key("distribution") or not isinstance(u.pkg.changes["distribution"], dict):
218 u.pkg.changes["distribution"] = {}
220 (summary, short_summary) = u.build_summaries()
222 (prompt, answer) = ("", "XXX")
223 if Options["No-Action"] or Options["Automatic"]:
228 pi = u.package_info()
231 chg = session.query(DBChange).filter_by(changesname=os.path.basename(u.pkg.changes_file)).one()
232 except NoResultFound as e:
235 if len(u.rejects) > 0:
236 if u.upload_too_new():
237 print "SKIP (too new)\n" + pi,
238 prompt = "[S]kip, Quit ?"
240 print "REJECT\n" + pi
241 prompt = "[R]eject, Skip, Quit ?"
242 if Options["Automatic"]:
245 # Are we headed for NEW / BYHAND / AUTOBYHAND?
246 # Note that policy queues are no longer handled here
247 qu = determine_target(u)
249 print "%s for %s\n%s%s" % ( qu.upper(), ", ".join(u.pkg.changes["distribution"].keys()), pi, summary)
250 queuekey = qu[0].upper()
251 if queuekey in "RQSA":
253 prompt = "[D]ivert, Skip, Quit ?"
255 prompt = "[%s]%s, Skip, Quit ?" % (queuekey, qu[1:].lower())
256 if Options["Automatic"]:
259 # Does suite have a policy_queue configured
261 for s in u.pkg.changes["distribution"].keys():
262 suite = get_suite(s, session)
263 if suite.policy_queue:
264 if not chg or chg.approved_for_id != suite.policy_queue.policy_queue_id:
265 # This routine will check whether the upload is a binary
266 # upload when the source is already in the target suite. If
267 # so, we skip the policy queue, otherwise we go there.
268 divert = package_to_suite(u, suite.suite_name, session=session)
270 print "%s for %s\n%s%s" % ( suite.policy_queue.queue_name.upper(),
271 ", ".join(u.pkg.changes["distribution"].keys()),
274 prompt = "[P]olicy, Skip, Quit ?"
275 policyqueue = suite.policy_queue
276 if Options["Automatic"]:
281 print "ACCEPT\n" + pi + summary,
282 prompt = "[A]ccept, Skip, Quit ?"
283 if Options["Automatic"]:
286 while prompt.find(answer) == -1:
287 answer = utils.our_raw_input(prompt)
288 m = re_default_answer.match(prompt)
291 answer = answer[:1].upper()
294 os.chdir(u.pkg.directory)
298 chg = u.pkg.add_known_changes(holding.holding_dir, session=session, logger=Logger)
300 u.accept(summary, short_summary, session)
302 chg.clean_from_queue()
307 chg = u.pkg.add_known_changes(holding.holding_dir, session=session, logger=Logger)
308 package_to_queue(u, summary, short_summary, policyqueue, chg, session)
311 elif answer == queuekey:
313 chg = u.pkg.add_known_changes(holding.holding_dir, session=session, logger=Logger)
314 QueueInfo[qu]["process"](u, summary, short_summary, chg, session)
323 ###############################################################################
327 if not Options["No-Action"]:
330 def process_it(changes_file, session):
333 Logger.log(["Processing changes file", changes_file])
339 # TODO: Actually implement using pending* tables so that we don't lose track
343 u.pkg.changes_file = changes_file
344 u.pkg.directory = os.getcwd()
346 origchanges = os.path.abspath(u.pkg.changes_file)
348 # Some defaults in case we can't fully process the .changes file
349 u.pkg.changes["maintainer2047"] = cnf["Dinstall::MyEmailAddress"]
350 u.pkg.changes["changedby2047"] = cnf["Dinstall::MyEmailAddress"]
352 # debian-{devel-,}-changes@lists.debian.org toggles writes access based on this header
353 bcc = "X-DAK: dak process-upload"
354 if cnf.has_key("Dinstall::Bcc"):
355 u.Subst["__BCC__"] = bcc + "\nBcc: %s" % (cnf["Dinstall::Bcc"])
357 u.Subst["__BCC__"] = bcc
359 # Remember where we are so we can come back after cd-ing into the
360 # holding directory. TODO: Fix this stupid hack
361 u.prevdir = os.getcwd()
364 # If this is the Real Thing(tm), copy things into a private
365 # holding directory first to avoid replacable file races.
366 if not Options["No-Action"]:
367 holding.chdir_to_holding()
369 # Absolutize the filename to avoid the requirement of being in the
370 # same directory as the .changes file.
371 holding.copy_to_holding(origchanges)
373 # Relativize the filename so we use the copy in holding
374 # rather than the original...
375 changespath = os.path.basename(u.pkg.changes_file)
377 changespath = origchanges
379 (u.pkg.changes["fingerprint"], rejects) = utils.check_signature(changespath)
381 if u.pkg.changes["fingerprint"]:
382 valid_changes_p = u.load_changes(changespath)
384 for reason in rejects:
385 if re_match_expired.match(reason):
386 # Hrm, key expired. Lets see if we can still parse the .changes before
387 # we reject. Then we would be able to mail the maintainer, instead of
388 # just silently dropping the upload.
389 u.load_changes(changespath)
390 valid_changes_p = False
391 u.rejects.extend(rejects)
394 u.check_distributions()
395 u.check_files(not Options["No-Action"])
396 valid_dsc_p = u.check_dsc(not Options["No-Action"])
397 if valid_dsc_p and not Options["No-Action"]:
400 if valid_dsc_p and not Options["No-Action"] and not len(u.rejects):
404 u.check_signed_by_key()
408 except (SystemExit, KeyboardInterrupt):
414 traceback.print_exc(file=sys.stderr)
417 # Restore previous WD
420 ###############################################################################
423 global Options, Logger
426 summarystats = SummaryStats()
430 Arguments = [('a',"automatic","Dinstall::Options::Automatic"),
431 ('h',"help","Dinstall::Options::Help"),
432 ('n',"no-action","Dinstall::Options::No-Action"),
433 ('p',"no-lock", "Dinstall::Options::No-Lock"),
434 ('s',"no-mail", "Dinstall::Options::No-Mail"),
435 ('d',"directory", "Dinstall::Options::Directory", "HasArg")]
437 for i in ["automatic", "help", "no-action", "no-lock", "no-mail",
438 "version", "directory"]:
439 if not cnf.has_key("Dinstall::Options::%s" % (i)):
440 cnf["Dinstall::Options::%s" % (i)] = ""
442 changes_files = apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
443 Options = cnf.SubTree("Dinstall::Options")
448 # -n/--dry-run invalidates some other options which would involve things happening
449 if Options["No-Action"]:
450 Options["Automatic"] = ""
452 # Check that we aren't going to clash with the daily cron job
453 if not Options["No-Action"] and os.path.exists("%s/daily.lock" % (cnf["Dir::Lock"])) and not Options["No-Lock"]:
454 utils.fubar("Archive maintenance in progress. Try again later.")
456 # Obtain lock if not in no-action mode and initialize the log
457 if not Options["No-Action"]:
458 lock_fd = os.open(os.path.join(cnf["Dir::Lock"], 'dinstall.lock'), os.O_RDWR | os.O_CREAT)
460 fcntl.lockf(lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
462 if errno.errorcode[e.errno] == 'EACCES' or errno.errorcode[e.errno] == 'EAGAIN':
463 utils.fubar("Couldn't obtain lock; assuming another 'dak process-upload' is already running.")
467 # Initialise UrgencyLog() - it will deal with the case where we don't
468 # want to log urgencies
469 urgencylog = UrgencyLog()
471 Logger = daklog.Logger("process-upload", Options["No-Action"])
473 # If we have a directory flag, use it to find our files
474 if cnf["Dinstall::Options::Directory"] != "":
475 # Note that we clobber the list of files we were given in this case
476 # so warn if the user has done both
477 if len(changes_files) > 0:
478 utils.warn("Directory provided so ignoring files given on command line")
480 changes_files = utils.get_changes_files(cnf["Dinstall::Options::Directory"])
481 Logger.log(["Using changes files from directory", cnf["Dinstall::Options::Directory"], len(changes_files)])
482 elif not len(changes_files) > 0:
483 utils.fubar("No changes files given and no directory specified")
485 Logger.log(["Using changes files from command-line", len(changes_files)])
487 # Sort the .changes files so that we process sourceful ones first
488 changes_files.sort(utils.changes_compare)
490 # Process the changes files
491 for changes_file in changes_files:
492 print "\n" + changes_file
493 session = DBConn().session()
494 process_it(changes_file, session)
497 if summarystats.accept_count:
499 if summarystats.accept_count > 1:
501 print "Installed %d package %s, %s." % (summarystats.accept_count, sets,
502 utils.size_type(int(summarystats.accept_bytes)))
503 Logger.log(["total", summarystats.accept_count, summarystats.accept_bytes])
505 if summarystats.reject_count:
507 if summarystats.reject_count > 1:
509 print "Rejected %d package %s." % (summarystats.reject_count, sets)
510 Logger.log(["rejected", summarystats.reject_count])
514 if not Options["No-Action"]:
519 ###############################################################################
521 if __name__ == '__main__':