2 # vim:set et ts=4 sw=4:
4 """ Handles NEW and BYHAND packages
6 @contact: Debian FTP Master <ftpmaster@debian.org>
7 @copyright: 2001, 2002, 2003, 2004, 2005, 2006 James Troup <james@nocrew.org>
8 @copyright: 2009 Joerg Jaspert <joerg@debian.org>
9 @license: GNU General Public License version 2 or later
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 ################################################################################
27 # 23:12|<aj> I will not hush!
29 # 23:12|<aj> Where there is injustice in the world, I shall be there!
30 # 23:13|<aj> I shall not be silenced!
31 # 23:13|<aj> The world shall know!
32 # 23:13|<aj> The world *must* know!
33 # 23:13|<elmo> oh dear, he's gone back to powerpuff girls... ;-)
34 # 23:13|<aj> yay powerpuff girls!!
35 # 23:13|<aj> buttercup's my favourite, who's yours?
36 # 23:14|<aj> you're backing away from the keyboard right now aren't you?
37 # 23:14|<aj> *AREN'T YOU*?!
38 # 23:15|<aj> I will not be treated like this.
39 # 23:15|<aj> I shall have my revenge.
40 # 23:15|<aj> I SHALL!!!
42 ################################################################################
44 from __future__ import with_statement
55 import apt_pkg, apt_inst
56 import examine_package
57 from daklib import database
58 from daklib import logging
59 from daklib import queue
60 from daklib import utils
61 from daklib.regexes import re_no_epoch, re_default_answer, re_isanum
62 from daklib.dak_exceptions import CantOpenError, AlreadyLockedError, CantGetLockError
65 Cnf = None #: Configuration, apt_pkg.Configuration
68 projectB = None #: database connection, pgobject
76 ################################################################################
77 ################################################################################
78 ################################################################################
80 def reject (str, prefix="Rejected: "):
83 reject_message += prefix + str + "\n"
87 files = Upload.pkg.files
90 for f in files.keys():
91 # The .orig.tar.gz can disappear out from under us is it's a
92 # duplicate of one in the archive.
93 if not files.has_key(f):
95 # Check that the source still exists
96 if files[f]["type"] == "deb":
97 source_version = files[f]["source version"]
98 source_package = files[f]["source package"]
99 if not Upload.pkg.changes["architecture"].has_key("source") \
100 and not Upload.source_exists(source_package, source_version, Upload.pkg.changes["distribution"].keys()):
101 source_epochless_version = re_no_epoch.sub('', source_version)
102 dsc_filename = "%s_%s.dsc" % (source_package, source_epochless_version)
104 for q in ["Accepted", "Embargoed", "Unembargoed", "Newstage"]:
105 if Cnf.has_key("Dir::Queue::%s" % (q)):
106 if os.path.exists(Cnf["Dir::Queue::%s" % (q)] + '/' + dsc_filename):
109 reject("no source found for %s %s (%s)." % (source_package, source_version, f))
111 # Version and file overwrite checks
112 if files[f]["type"] == "deb":
113 reject(Upload.check_binary_against_db(f), "")
114 elif files[f]["type"] == "dsc":
115 reject(Upload.check_source_against_db(f), "")
116 (reject_msg, is_in_incoming) = Upload.check_dsc_against_db(f)
117 reject(reject_msg, "")
119 if reject_message.find("Rejected") != -1:
121 if Options["No-Action"] or Options["Automatic"] or Options["Trainee"]:
124 print "REJECT\n" + reject_message,
125 prompt = "[R]eject, Skip, Quit ?"
127 while prompt.find(answer) == -1:
128 answer = utils.our_raw_input(prompt)
129 m = re_default_answer.match(prompt)
132 answer = answer[:1].upper()
135 Upload.do_reject(0, reject_message)
136 os.unlink(Upload.pkg.changes_file[:-8]+".dak")
146 ################################################################################
148 def indiv_sg_compare (a, b):
149 """Sort by source name, source, version, 'have source', and
150 finally by filename."""
151 # Sort by source version
152 q = apt_pkg.VersionCompare(a["version"], b["version"])
156 # Sort by 'have source'
157 a_has_source = a["architecture"].get("source")
158 b_has_source = b["architecture"].get("source")
159 if a_has_source and not b_has_source:
161 elif b_has_source and not a_has_source:
164 return cmp(a["filename"], b["filename"])
166 ############################################################
168 def sg_compare (a, b):
171 """Sort by have note, source already in database and time of oldest upload."""
173 a_note_state = a["note_state"]
174 b_note_state = b["note_state"]
175 if a_note_state < b_note_state:
177 elif a_note_state > b_note_state:
179 # Sort by source already in database (descending)
180 source_in_database = cmp(a["source_in_database"], b["source_in_database"])
181 if source_in_database:
182 return -source_in_database
184 # Sort by time of oldest upload
185 return cmp(a["oldest"], b["oldest"])
187 def sort_changes(changes_files):
188 """Sort into source groups, then sort each source group by version,
189 have source, filename. Finally, sort the source groups by have
190 note, time of oldest upload of each source upload."""
191 if len(changes_files) == 1:
196 # Read in all the .changes files
197 for filename in changes_files:
199 Upload.pkg.changes_file = filename
202 cache[filename] = copy.copy(Upload.pkg.changes)
203 cache[filename]["filename"] = filename
205 sorted_list.append(filename)
207 # Divide the .changes into per-source groups
209 for filename in cache.keys():
210 source = cache[filename]["source"]
211 if not per_source.has_key(source):
212 per_source[source] = {}
213 per_source[source]["list"] = []
214 per_source[source]["list"].append(cache[filename])
215 # Determine oldest time and have note status for each source group
216 for source in per_source.keys():
217 q = projectB.query("SELECT 1 FROM source WHERE source = '%s'" % source)
219 per_source[source]["source_in_database"] = len(ql)>0
220 source_list = per_source[source]["list"]
221 first = source_list[0]
222 oldest = os.stat(first["filename"])[stat.ST_MTIME]
224 for d in per_source[source]["list"]:
225 mtime = os.stat(d["filename"])[stat.ST_MTIME]
228 have_note += (database.has_new_comment(d["source"], d["version"], True))
229 per_source[source]["oldest"] = oldest
231 per_source[source]["note_state"] = 0; # none
232 elif have_note < len(source_list):
233 per_source[source]["note_state"] = 1; # some
235 per_source[source]["note_state"] = 2; # all
236 per_source[source]["list"].sort(indiv_sg_compare)
237 per_source_items = per_source.items()
238 per_source_items.sort(sg_compare)
239 for i in per_source_items:
240 for j in i[1]["list"]:
241 sorted_list.append(j["filename"])
244 ################################################################################
246 class Section_Completer:
250 q = projectB.query("SELECT section FROM section")
251 for i in q.getresult():
252 self.sections.append(i[0])
254 def complete(self, text, state):
258 for word in self.sections:
260 self.matches.append(word)
262 return self.matches[state]
266 ############################################################
268 class Priority_Completer:
272 q = projectB.query("SELECT priority FROM priority")
273 for i in q.getresult():
274 self.priorities.append(i[0])
276 def complete(self, text, state):
280 for word in self.priorities:
282 self.matches.append(word)
284 return self.matches[state]
288 ################################################################################
290 def print_new (new, indexed, file=sys.stdout):
291 queue.check_valid(new)
294 for pkg in new.keys():
296 section = new[pkg]["section"]
297 priority = new[pkg]["priority"]
298 if new[pkg]["section id"] == -1:
301 if new[pkg]["priority id"] == -1:
305 line = "(%s): %-20s %-20s %-20s" % (index, pkg, priority, section)
307 line = "%-20s %-20s %-20s" % (pkg, priority, section)
308 line = line.strip()+'\n'
310 note = database.get_new_comments(Upload.pkg.changes.get("source"))
316 ################################################################################
318 def index_range (index):
322 return "1-%s" % (index)
324 ################################################################################
325 ################################################################################
328 # Write the current data to a temporary file
329 (fd, temp_filename) = utils.temp_filename()
330 temp_file = os.fdopen(fd, 'w')
331 print_new (new, 0, temp_file)
333 # Spawn an editor on that file
334 editor = os.environ.get("EDITOR","vi")
335 result = os.system("%s %s" % (editor, temp_filename))
337 utils.fubar ("%s invocation failed for %s." % (editor, temp_filename), result)
338 # Read the edited data back in
339 temp_file = utils.open_file(temp_filename)
340 lines = temp_file.readlines()
342 os.unlink(temp_filename)
349 # Pad the list if necessary
350 s[len(s):3] = [None] * (3-len(s))
351 (pkg, priority, section) = s[:3]
352 if not new.has_key(pkg):
353 utils.warn("Ignoring unknown package '%s'" % (pkg))
355 # Strip off any invalid markers, print_new will readd them.
356 if section.endswith("[!]"):
357 section = section[:-3]
358 if priority.endswith("[!]"):
359 priority = priority[:-3]
360 for f in new[pkg]["files"]:
361 Upload.pkg.files[f]["section"] = section
362 Upload.pkg.files[f]["priority"] = priority
363 new[pkg]["section"] = section
364 new[pkg]["priority"] = priority
366 ################################################################################
368 def edit_index (new, index):
369 priority = new[index]["priority"]
370 section = new[index]["section"]
371 ftype = new[index]["type"]
374 print "\t".join([index, priority, section])
378 prompt = "[B]oth, Priority, Section, Done ? "
380 prompt = "[S]ection, Done ? "
381 edit_priority = edit_section = 0
383 while prompt.find(answer) == -1:
384 answer = utils.our_raw_input(prompt)
385 m = re_default_answer.match(prompt)
388 answer = answer[:1].upper()
395 edit_priority = edit_section = 1
401 readline.set_completer(Priorities.complete)
403 while not got_priority:
404 new_priority = utils.our_raw_input("New priority: ").strip()
405 if new_priority not in Priorities.priorities:
406 print "E: '%s' is not a valid priority, try again." % (new_priority)
409 priority = new_priority
413 readline.set_completer(Sections.complete)
415 while not got_section:
416 new_section = utils.our_raw_input("New section: ").strip()
417 if new_section not in Sections.sections:
418 print "E: '%s' is not a valid section, try again." % (new_section)
421 section = new_section
423 # Reset the readline completer
424 readline.set_completer(None)
426 for f in new[index]["files"]:
427 Upload.pkg.files[f]["section"] = section
428 Upload.pkg.files[f]["priority"] = priority
429 new[index]["priority"] = priority
430 new[index]["section"] = section
433 ################################################################################
435 def edit_overrides (new):
446 prompt = "(%s) edit override <n>, Editor, Done ? " % (index_range(index))
449 while not got_answer:
450 answer = utils.our_raw_input(prompt)
451 if not answer.isdigit():
452 answer = answer[:1].upper()
453 if answer == "E" or answer == "D":
455 elif re_isanum.match (answer):
457 if (answer < 1) or (answer > index):
458 print "%s is not a valid index (%s). Please retry." % (answer, index_range(index))
467 edit_index (new, new_index[answer])
471 ################################################################################
474 # Write the current data to a temporary file
475 (fd, temp_filename) = utils.temp_filename()
476 editor = os.environ.get("EDITOR","vi")
479 os.system("%s %s" % (editor, temp_filename))
480 temp_file = utils.open_file(temp_filename)
481 newnote = temp_file.read().rstrip()
484 print utils.prefix_multi_line_string(newnote," ")
485 prompt = "[D]one, Edit, Abandon, Quit ?"
487 while prompt.find(answer) == -1:
488 answer = utils.our_raw_input(prompt)
489 m = re_default_answer.search(prompt)
492 answer = answer[:1].upper()
493 os.unlink(temp_filename)
500 database.add_new_comment(Upload.pkg.changes["source"], Upload.pkg.changes["version"], newnote, utils.whoami(), bool(Options["Trainee"]))
502 ################################################################################
506 less_fd = os.popen("less -R -", 'w', 0)
507 stdout_fd = sys.stdout
510 changes = utils.parse_changes (Upload.pkg.changes_file)
511 examine_package.display_changes(changes['distribution'], Upload.pkg.changes_file)
512 files = Upload.pkg.files
513 for f in files.keys():
514 if files[f].has_key("new"):
515 ftype = files[f]["type"]
517 examine_package.check_deb(changes['distribution'], f)
519 examine_package.check_dsc(changes['distribution'], f)
521 examine_package.output_package_relations()
522 sys.stdout = stdout_fd
524 if e.errno == errno.EPIPE:
525 utils.warn("[examine_package] Caught EPIPE; skipping.")
529 except KeyboardInterrupt:
530 utils.warn("[examine_package] Caught C-c; skipping.")
533 ################################################################################
535 ## FIXME: horribly Debian specific
537 def do_bxa_notification():
538 files = Upload.pkg.files
540 for f in files.keys():
541 if files[f]["type"] == "deb":
542 control = apt_pkg.ParseSection(apt_inst.debExtractControl(utils.open_file(f)))
544 summary += "Package: %s\n" % (control.Find("Package"))
545 summary += "Description: %s\n" % (control.Find("Description"))
546 Upload.Subst["__BINARY_DESCRIPTIONS__"] = summary
547 bxa_mail = utils.TemplateSubst(Upload.Subst,Cnf["Dir::Templates"]+"/process-new.bxa_notification")
548 utils.send_mail(bxa_mail)
550 ################################################################################
552 def add_overrides (new):
553 changes = Upload.pkg.changes
554 files = Upload.pkg.files
556 projectB.query("BEGIN WORK")
557 for suite in changes["suite"].keys():
558 suite_id = database.get_suite_id(suite)
559 for pkg in new.keys():
560 component_id = database.get_component_id(new[pkg]["component"])
561 type_id = database.get_override_type_id(new[pkg]["type"])
562 priority_id = new[pkg]["priority id"]
563 section_id = new[pkg]["section id"]
564 projectB.query("INSERT INTO override (suite, component, type, package, priority, section, maintainer) VALUES (%s, %s, %s, '%s', %s, %s, '')" % (suite_id, component_id, type_id, pkg, priority_id, section_id))
565 for f in new[pkg]["files"]:
566 if files[f].has_key("new"):
570 projectB.query("COMMIT WORK")
572 if Cnf.FindB("Dinstall::BXANotify"):
573 do_bxa_notification()
575 ################################################################################
577 def prod_maintainer (note):
578 # Here we prepare an editor and get them ready to prod...
579 (fd, temp_filename) = utils.temp_filename()
580 temp_file = os.fdopen(fd, 'w')
583 temp_file.write(line)
585 editor = os.environ.get("EDITOR","vi")
588 os.system("%s %s" % (editor, temp_filename))
589 temp_fh = utils.open_file(temp_filename)
590 prod_message = "".join(temp_fh.readlines())
592 print "Prod message:"
593 print utils.prefix_multi_line_string(prod_message," ",include_blank_lines=1)
594 prompt = "[P]rod, Edit, Abandon, Quit ?"
596 while prompt.find(answer) == -1:
597 answer = utils.our_raw_input(prompt)
598 m = re_default_answer.search(prompt)
601 answer = answer[:1].upper()
602 os.unlink(temp_filename)
608 # Otherwise, do the proding...
609 user_email_address = utils.whoami() + " <%s>" % (
610 Cnf["Dinstall::MyAdminAddress"])
614 Subst["__FROM_ADDRESS__"] = user_email_address
615 Subst["__PROD_MESSAGE__"] = prod_message
616 Subst["__CC__"] = "Cc: " + Cnf["Dinstall::MyEmailAddress"]
618 prod_mail_message = utils.TemplateSubst(
619 Subst,Cnf["Dir::Templates"]+"/process-new.prod")
621 # Send the prod mail if appropriate
622 if not Cnf["Dinstall::Options::No-Mail"]:
623 utils.send_mail(prod_mail_message)
625 print "Sent proding message"
627 ################################################################################
631 files = Upload.pkg.files
632 changes = Upload.pkg.changes
634 # Make a copy of distribution we can happily trample on
635 changes["suite"] = copy.copy(changes["distribution"])
637 # Fix up the list of target suites
638 for suite in changes["suite"].keys():
639 override = Cnf.Find("Suite::%s::OverrideSuite" % (suite))
641 (olderr, newerr) = (database.get_suite_id(suite) == -1,
642 database.get_suite_id(override) == -1)
644 (oinv, newinv) = ("", "")
645 if olderr: oinv = "invalid "
646 if newerr: ninv = "invalid "
647 print "warning: overriding %ssuite %s to %ssuite %s" % (
648 oinv, suite, ninv, override)
649 del changes["suite"][suite]
650 changes["suite"][override] = 1
652 for suite in changes["suite"].keys():
653 suite_id = database.get_suite_id(suite)
655 utils.fubar("%s has invalid suite '%s' (possibly overriden). say wha?" % (changes, suite))
657 # The main NEW processing loop
660 # Find out what's new
661 new = queue.determine_new(changes, files, projectB)
667 if Options["No-Action"] or Options["Automatic"]:
670 (broken, note) = print_new(new, 0)
673 if not broken and not note:
674 prompt = "Add overrides, "
676 print "W: [!] marked entries must be fixed before package can be processed."
678 print "W: note must be removed before package can be processed."
679 prompt += "RemOve all notes, Remove note, "
681 prompt += "Edit overrides, Check, Manual reject, Note edit, Prod, [S]kip, Quit ?"
683 while prompt.find(answer) == -1:
684 answer = utils.our_raw_input(prompt)
685 m = re_default_answer.search(prompt)
688 answer = answer[:1].upper()
690 if answer == 'A' and not Options["Trainee"]:
693 done = add_overrides (new)
694 Logger.log([utils.getusername(), "NEW ACCEPT: %s" % (Upload.pkg.changes_file)])
695 except CantGetLockError:
696 print "Hello? Operator! Give me the number for 911!"
697 print "Dinstall in the locked area, cant process packages, come back later"
700 elif answer == 'E' and not Options["Trainee"]:
701 new = edit_overrides (new)
702 elif answer == 'M' and not Options["Trainee"]:
703 aborted = Upload.do_reject(manual=1,
704 reject_message=Options["Manual-Reject"],
705 note=database.get_new_comments(changes.get("source", "")))
707 Logger.log([utils.getusername(), "NEW REJECT: %s" % (Upload.pkg.changes_file)])
708 os.unlink(Upload.pkg.changes_file[:-8]+".dak")
711 edit_note(database.get_new_comments(changes.get("source", "")))
712 elif answer == 'P' and not Options["Trainee"]:
713 prod_maintainer(database.get_new_comments(changes.get("source", "")))
714 Logger.log([utils.getusername(), "NEW PROD: %s" % (Upload.pkg.changes_file)])
715 elif answer == 'R' and not Options["Trainee"]:
716 confirm = utils.our_raw_input("Really clear note (y/N)? ").lower()
718 database.delete_new_comments(changes.get("source"), changes.get("version"))
719 elif answer == 'O' and not Options["Trainee"]:
720 confirm = utils.our_raw_input("Really clear all notes (y/N)? ").lower()
722 database.delete_all_new_comments(changes.get("source"))
729 ################################################################################
730 ################################################################################
731 ################################################################################
733 def usage (exit_code=0):
734 print """Usage: dak process-new [OPTION]... [CHANGES]...
735 -a, --automatic automatic run
736 -h, --help show this help and exit.
737 -C, --comments-dir=DIR use DIR as comments-dir, for [o-]p-u-new
738 -m, --manual-reject=MSG manual reject with `msg'
739 -n, --no-action don't do anything
740 -t, --trainee FTP Trainee mode
741 -V, --version display the version number and exit"""
744 ################################################################################
747 global Cnf, Options, Logger, Upload, projectB, Sections, Priorities
749 Cnf = utils.get_conf()
751 Arguments = [('a',"automatic","Process-New::Options::Automatic"),
752 ('h',"help","Process-New::Options::Help"),
753 ('C',"comments-dir","Process-New::Options::Comments-Dir", "HasArg"),
754 ('m',"manual-reject","Process-New::Options::Manual-Reject", "HasArg"),
755 ('t',"trainee","Process-New::Options::Trainee"),
756 ('n',"no-action","Process-New::Options::No-Action")]
758 for i in ["automatic", "help", "manual-reject", "no-action", "version", "comments-dir", "trainee"]:
759 if not Cnf.has_key("Process-New::Options::%s" % (i)):
760 Cnf["Process-New::Options::%s" % (i)] = ""
762 changes_files = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
763 if len(changes_files) == 0 and not Cnf.get("Process-New::Options::Comments-Dir",""):
764 changes_files = utils.get_changes_files(Cnf["Dir::Queue::New"])
766 Options = Cnf.SubTree("Process-New::Options")
771 Upload = queue.Upload(Cnf)
773 if not Options["No-Action"]:
775 Logger = Upload.Logger = logging.Logger(Cnf, "process-new")
776 except CantOpenError, e:
777 Options["Trainee"] = "True"
779 projectB = Upload.projectB
781 Sections = Section_Completer()
782 Priorities = Priority_Completer()
783 readline.parse_and_bind("tab: complete")
787 ################################################################################
792 files = Upload.pkg.files
796 for f in files.keys():
797 if files[f]["type"] == "byhand":
798 if os.path.exists(f):
799 print "W: %s still present; please process byhand components and try again." % (f)
805 if Options["No-Action"]:
808 if Options["Automatic"] and not Options["No-Action"]:
810 prompt = "[A]ccept, Manual reject, Skip, Quit ?"
812 prompt = "Manual reject, [S]kip, Quit ?"
814 while prompt.find(answer) == -1:
815 answer = utils.our_raw_input(prompt)
816 m = re_default_answer.search(prompt)
819 answer = answer[:1].upper()
827 Logger.log([utils.getusername(), "BYHAND ACCEPT: %s" % (Upload.pkg.changes_file)])
828 except CantGetLockError:
829 print "Hello? Operator! Give me the number for 911!"
830 print "Dinstall in the locked area, cant process packages, come back later"
832 Logger.log([utils.getusername(), "BYHAND REJECT: %s" % (Upload.pkg.changes_file)])
833 Upload.do_reject(1, Options["Manual-Reject"])
834 os.unlink(Upload.pkg.changes_file[:-8]+".dak")
842 ################################################################################
844 def check_daily_lock():
846 Raises CantGetLockError if the dinstall daily.lock exists.
850 os.open(Cnf["Process-New::DinstallLockFile"], os.O_RDONLY | os.O_CREAT | os.O_EXCL)
852 if e.errno == errno.EEXIST or e.errno == errno.EACCES:
853 raise CantGetLockError
855 os.unlink(Cnf["Process-New::DinstallLockFile"])
858 @contextlib.contextmanager
859 def lock_package(package):
861 Lock C{package} so that noone else jumps in processing it.
863 @type package: string
864 @param package: source package name to lock
867 path = os.path.join(Cnf["Process-New::LockDir"], package)
869 fd = os.open(path, os.O_CREAT | os.O_EXCL | os.O_RDONLY)
871 if e.errno == errno.EEXIST or e.errno == errno.EACCES:
872 user = pwd.getpwuid(os.stat(path)[stat.ST_UID])[4].split(',')[0].replace('.', '')
873 raise AlreadyLockedError, user
880 def move_to_dir (dest, perms=0660, changesperms=0664):
881 utils.move (Upload.pkg.changes_file, dest, perms=changesperms)
882 file_keys = Upload.pkg.files.keys()
884 utils.move (f, dest, perms=perms)
886 def is_source_in_queue_dir(qdir):
887 entries = [ x for x in os.listdir(qdir) if x.startswith(Upload.pkg.changes["source"])
888 and x.endswith(".changes") ]
889 for entry in entries:
891 u = queue.Upload(Cnf)
892 u.pkg.changes_file = os.path.join(qdir, entry)
894 if not u.pkg.changes["architecture"].has_key("source"):
895 # another binary upload, ignore
897 if Upload.pkg.changes["version"] != u.pkg.changes["version"]:
898 # another version, ignore
904 def move_to_holding(suite, queue_dir):
905 print "Moving to %s holding area." % (suite.upper(),)
906 if Options["No-Action"]:
908 Logger.log(["Moving to %s" % (suite,), Upload.pkg.changes_file])
909 Upload.dump_vars(queue_dir)
910 move_to_dir(queue_dir, perms=0664)
911 os.unlink(Upload.pkg.changes_file[:-8]+".dak")
914 if Options["No-Action"]:
916 (summary, short_summary) = Upload.build_summaries()
917 Upload.accept(summary, short_summary, targetdir=Cnf["Dir::Queue::Newstage"])
918 os.unlink(Upload.pkg.changes_file[:-8]+".dak")
920 def do_accept_stableupdate(suite, q):
921 queue_dir = Cnf["Dir::Queue::%s" % (q,)]
922 if not Upload.pkg.changes["architecture"].has_key("source"):
923 # It is not a sourceful upload. So its source may be either in p-u
924 # holding, in new, in accepted or already installed.
925 if is_source_in_queue_dir(queue_dir):
926 # It's in p-u holding, so move it there.
927 print "Binary-only upload, source in %s." % (q,)
928 move_to_holding(suite, queue_dir)
929 elif Upload.source_exists(Upload.pkg.changes["source"],
930 Upload.pkg.changes["version"]):
931 # dak tells us that there is source available. At time of
932 # writing this means that it is installed, so put it into
934 print "Binary-only upload, source installed."
935 Logger.log([utils.getusername(), "PUNEW ACCEPT: %s" % (Upload.pkg.changes_file)])
937 elif is_source_in_queue_dir(Cnf["Dir::Queue::Accepted"]):
938 # The source is in accepted, the binary cleared NEW: accept it.
939 print "Binary-only upload, source in accepted."
940 Logger.log([utils.getusername(), "PUNEW ACCEPT: %s" % (Upload.pkg.changes_file)])
942 elif is_source_in_queue_dir(Cnf["Dir::Queue::New"]):
943 # It's in NEW. We expect the source to land in p-u holding
945 print "Binary-only upload, source in new."
946 move_to_holding(suite, queue_dir)
947 elif is_source_in_queue_dir(Cnf["Dir::Queue::Newstage"]):
948 # It's in newstage. Accept into the holding area
949 print "Binary-only upload, source in newstage."
950 Logger.log([utils.getusername(), "PUNEW ACCEPT: %s" % (Upload.pkg.changes_file)])
953 # No case applicable. Bail out. Return will cause the upload
956 print "Stable update failed. Source not found."
959 # We are handling a sourceful upload. Move to accepted if currently
960 # in p-u holding and to p-u holding otherwise.
961 if is_source_in_queue_dir(queue_dir):
962 print "Sourceful upload in %s, accepting." % (q,)
965 move_to_holding(suite, queue_dir)
969 if not Options["No-Action"]:
970 (summary, short_summary) = Upload.build_summaries()
971 if Cnf.FindB("Dinstall::SecurityQueueHandling"):
972 Upload.dump_vars(Cnf["Dir::Queue::Embargoed"])
973 move_to_dir(Cnf["Dir::Queue::Embargoed"])
974 Upload.queue_build("embargoed", Cnf["Dir::Queue::Embargoed"])
975 # Check for override disparities
976 Upload.Subst["__SUMMARY__"] = summary
978 # Stable updates need to be copied to proposed-updates holding
979 # area instead of accepted. Sourceful uploads need to go
980 # to it directly, binaries only if the source has not yet been
982 for suite, q in [("proposed-updates", "ProposedUpdates"),
983 ("oldstable-proposed-updates", "OldProposedUpdates")]:
984 if not Upload.pkg.changes["distribution"].has_key(suite):
986 return do_accept_stableupdate(suite, q)
987 # Just a normal upload, accept it...
990 def check_status(files):
992 for f in files.keys():
993 if files[f]["type"] == "byhand":
995 elif files[f].has_key("new"):
999 def do_pkg(changes_file):
1000 Upload.pkg.changes_file = changes_file
1002 Upload.update_vars()
1003 Upload.update_subst()
1004 files = Upload.pkg.files
1007 with lock_package(Upload.pkg.changes["source"]):
1011 (new, byhand) = check_status(files)
1017 (new, byhand) = check_status(files)
1019 if not new and not byhand:
1023 except CantGetLockError:
1024 print "Hello? Operator! Give me the number for 911!"
1025 print "Dinstall in the locked area, cant process packages, come back later"
1026 except AlreadyLockedError, e:
1027 print "Seems to be locked by %s already, skipping..." % (e)
1029 ################################################################################
1032 accept_count = Upload.accept_count
1033 accept_bytes = Upload.accept_bytes
1037 if accept_count > 1:
1039 sys.stderr.write("Accepted %d package %s, %s.\n" % (accept_count, sets, utils.size_type(int(accept_bytes))))
1040 Logger.log([utils.getusername(), "total",accept_count,accept_bytes])
1042 if not Options["No-Action"] and not Options["Trainee"]:
1045 ################################################################################
1047 def do_comments(dir, opref, npref, line, fn):
1048 for comm in [ x for x in os.listdir(dir) if x.startswith(opref) ]:
1049 lines = open("%s/%s" % (dir, comm)).readlines()
1050 if len(lines) == 0 or lines[0] != line + "\n": continue
1051 changes_files = [ x for x in os.listdir(".") if x.startswith(comm[7:]+"_")
1052 and x.endswith(".changes") ]
1053 changes_files = sort_changes(changes_files)
1054 for f in changes_files:
1055 f = utils.validate_changes_file_arg(f, 0)
1058 fn(f, "".join(lines[1:]))
1060 if opref != npref and not Options["No-Action"]:
1061 newcomm = npref + comm[len(opref):]
1062 os.rename("%s/%s" % (dir, comm), "%s/%s" % (dir, newcomm))
1064 ################################################################################
1066 def comment_accept(changes_file, comments):
1067 Upload.pkg.changes_file = changes_file
1069 Upload.update_vars()
1070 Upload.update_subst()
1071 files = Upload.pkg.files
1074 return # dak wants to REJECT, crap
1076 (new, byhand) = check_status(files)
1077 if not new and not byhand:
1080 ################################################################################
1082 def comment_reject(changes_file, comments):
1083 Upload.pkg.changes_file = changes_file
1085 Upload.update_vars()
1086 Upload.update_subst()
1089 pass # dak has its own reasons to reject as well, which is fine
1092 print "REJECT\n" + reject_message,
1093 if not Options["No-Action"]:
1094 Upload.do_reject(0, reject_message)
1095 os.unlink(Upload.pkg.changes_file[:-8]+".dak")
1097 ################################################################################
1100 changes_files = init()
1101 if len(changes_files) > 50:
1102 sys.stderr.write("Sorting changes...\n")
1103 changes_files = sort_changes(changes_files)
1105 # Kill me now? **FIXME**
1106 Cnf["Dinstall::Options::No-Mail"] = ""
1107 bcc = "X-DAK: dak process-new\nX-Katie: lisa $Revision: 1.31 $"
1108 if Cnf.has_key("Dinstall::Bcc"):
1109 Upload.Subst["__BCC__"] = bcc + "\nBcc: %s" % (Cnf["Dinstall::Bcc"])
1111 Upload.Subst["__BCC__"] = bcc
1113 commentsdir = Cnf.get("Process-New::Options::Comments-Dir","")
1115 if changes_files != []:
1116 sys.stderr.write("Can't specify any changes files if working with comments-dir")
1118 do_comments(commentsdir, "ACCEPT.", "ACCEPTED.", "OK", comment_accept)
1119 do_comments(commentsdir, "REJECT.", "REJECTED.", "NOTOK", comment_reject)
1121 for changes_file in changes_files:
1122 changes_file = utils.validate_changes_file_arg(changes_file, 0)
1123 if not changes_file:
1125 print "\n" + changes_file
1127 do_pkg (changes_file)
1131 ################################################################################
1133 if __name__ == '__main__':