]> git.decadent.org.uk Git - dak.git/blob - lisa
note support
[dak.git] / lisa
1 #!/usr/bin/env python
2
3 # Handles NEW and BYHAND packages
4 # Copyright (C) 2001, 2002  James Troup <james@nocrew.org>
5 # $Id: lisa,v 1.11 2002-05-18 23:55:07 troup Exp $
6
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
21 ################################################################################
22
23 # 23:12|<aj> I will not hush!
24 # 23:12|<elmo> :>
25 # 23:12|<aj> Where there is injustice in the world, I shall be there!
26 # 23:13|<aj> I shall not be silenced!
27 # 23:13|<aj> The world shall know!
28 # 23:13|<aj> The world *must* know!
29 # 23:13|<elmo> oh dear, he's gone back to powerpuff girls... ;-)
30 # 23:13|<aj> yay powerpuff girls!!
31 # 23:13|<aj> buttercup's my favourite, who's yours?
32 # 23:14|<aj> you're backing away from the keyboard right now aren't you?
33 # 23:14|<aj> *AREN'T YOU*?!
34 # 23:15|<aj> I will not be treated like this.
35 # 23:15|<aj> I shall have my revenge.
36 # 23:15|<aj> I SHALL!!!
37
38 ################################################################################
39
40 # TODO
41 # ----
42
43 # We don't check error codes very thoroughly; the old 'trust jennifer'
44 # chess nut... db_access calls in particular
45
46 # Possible TODO
47 # -------------
48
49 # Handle multiple different section/priorities (?)
50 # hardcoded debianness (debian-installer, source priority etc.) (?)
51 # Slang/ncurses interface (?)
52 # write changed sections/priority back to katie for later processing (?)
53
54 ################################################################################
55
56 import copy, errno, os, readline, string, stat, sys, tempfile;
57 import apt_pkg, apt_inst;
58 import db_access, fernanda, katie, logging, utils;
59
60 # Globals
61 lisa_version = "$Revision: 1.11 $";
62
63 Cnf = None;
64 Options = None;
65 Katie = None;
66 projectB = None;
67 Logger = None;
68
69 Priorities = None;
70 Sections = None;
71
72 ################################################################################
73 ################################################################################
74 ################################################################################
75
76 def determine_new (changes, files):
77     new = {};
78
79     # Build up a list of potentially new things
80     for file in files.keys():
81         f = files[file];
82         # Skip byhand elements
83         if f["type"] == "byhand":
84             continue;
85         pkg = f["package"];
86         priority = f["priority"];
87         section = f["section"];
88         # FIXME: unhardcode
89         if section == "non-US/main":
90             section = "non-US";
91         type = get_type(f);
92         component = f["component"];
93
94         if type == "dsc":
95             priority = "source";
96         if not new.has_key(pkg):
97             new[pkg] = {};
98             new[pkg]["priority"] = priority;
99             new[pkg]["section"] = section;
100             new[pkg]["type"] = type;
101             new[pkg]["component"] = component;
102             new[pkg]["files"] = [];
103         else:
104             old_type = new[pkg]["type"];
105             if old_type != type:
106                 # source gets trumped by deb or udeb
107                 if old_type == "dsc":
108                     new[pkg]["priority"] = priority;
109                     new[pkg]["section"] = section;
110                     new[pkg]["type"] = type;
111                     new[pkg]["component"] = component;
112         new[pkg]["files"].append(file);
113         if f.has_key("othercomponents"):
114             new[pkg]["othercomponents"] = f["othercomponents"];
115
116     for suite in changes["suite"].keys():
117         suite_id = db_access.get_suite_id(suite);
118         for pkg in new.keys():
119             component_id = db_access.get_component_id(new[pkg]["component"]);
120             type_id = db_access.get_override_type_id(new[pkg]["type"]);
121             q = projectB.query("SELECT package FROM override WHERE package = '%s' AND suite = %s AND component = %s AND type = %s" % (pkg, suite_id, component_id, type_id));
122             ql = q.getresult();
123             if ql:
124                 for file in new[pkg]["files"]:
125                     if files[file].has_key("new"):
126                         del files[file]["new"];
127                 del new[pkg];
128
129     if changes["suite"].has_key("stable"):
130         print "WARNING: overrides will be added for stable!";
131     for pkg in new.keys():
132         if new[pkg].has_key("othercomponents"):
133             print "WARNING: %s already present in %s distribution." % (pkg, new[pkg]["othercomponents"]);
134
135     return new;
136
137 ################################################################################
138
139 # Sort by 'have note', 'have source', by ctime, by source name, by
140 # source version number, and finally by filename
141
142 def changes_compare (a, b):
143     try:
144         a_changes = utils.parse_changes(a);
145     except:
146         return 1;
147
148     try:
149         b_changes = utils.parse_changes(b);
150     except:
151         return -1;
152
153     utils.cc_fix_changes (a_changes);
154     utils.cc_fix_changes (b_changes);
155
156     # Sort by 'have note';
157     a_has_note = a_changes.get("lisa note");
158     b_has_note = b_changes.get("lisa note");
159     if a_has_note and not b_has_note:
160         return -1;
161     elif b_has_note and not a_has_note:
162         return 1;
163
164     # Sort by 'have source'
165     a_has_source = a_changes["architecture"].get("source");
166     b_has_source = b_changes["architecture"].get("source");
167     if a_has_source and not b_has_source:
168         return -1;
169     elif b_has_source and not a_has_source:
170         return 1;
171
172     # Sort by ctime
173     a_ctime = os.stat(a)[stat.ST_CTIME];
174     b_ctime = os.stat(b)[stat.ST_CTIME];
175     q = cmp (a_ctime, b_ctime);
176     if q:
177         return -q;
178
179     # Sort by source name
180     a_source = a_changes.get("source");
181     b_source = b_changes.get("source");
182     q = cmp (a_source, b_source);
183     if q:
184         return q;
185
186     # Sort by source version
187     a_version = a_changes.get("version");
188     b_version = b_changes.get("version");
189     q = apt_pkg.VersionCompare(a_version, b_version);
190     if q:
191         return q;
192
193     # Fall back to sort by filename
194     return cmp(a, b);
195
196 ################################################################################
197
198 class Section_Completer:
199     def __init__ (self):
200         self.sections = [];
201         q = projectB.query("SELECT section FROM section");
202         for i in q.getresult():
203             self.sections.append(i[0]);
204
205     def complete(self, text, state):
206         if state == 0:
207             self.matches = [];
208             n = len(text);
209             for word in self.sections:
210                 if word[:n] == text:
211                     self.matches.append(word);
212         try:
213             return self.matches[state]
214         except IndexError:
215             return None
216
217 ############################################################
218
219 class Priority_Completer:
220     def __init__ (self):
221         self.priorities = [];
222         q = projectB.query("SELECT priority FROM priority");
223         for i in q.getresult():
224             self.priorities.append(i[0]);
225
226     def complete(self, text, state):
227         if state == 0:
228             self.matches = [];
229             n = len(text);
230             for word in self.priorities:
231                 if word[:n] == text:
232                     self.matches.append(word);
233         try:
234             return self.matches[state]
235         except IndexError:
236             return None
237
238 ################################################################################
239
240 def check_valid (new):
241     for pkg in new.keys():
242         section = new[pkg]["section"];
243         priority = new[pkg]["priority"];
244         type = new[pkg]["type"];
245         new[pkg]["section id"] = db_access.get_section_id(section);
246         new[pkg]["priority id"] = db_access.get_priority_id(new[pkg]["priority"]);
247         # Sanity checks
248         if (section == "debian-installer" and type != "udeb") or \
249            (section != "debian-installer" and type == "udeb"):
250             new[pkg]["section id"] = -1;
251         if (priority == "source" and type != "dsc") or \
252            (priority != "source" and type == "dsc"):
253             new[pkg]["priority id"] = -1;
254
255 ################################################################################
256
257 def print_new (new, indexed, file=sys.stdout):
258     check_valid(new);
259     broken = 0;
260     index = 0;
261     for pkg in new.keys():
262         index = index + 1;
263         section = new[pkg]["section"];
264         priority = new[pkg]["priority"];
265         if new[pkg]["section id"] == -1:
266             section = section + "[!]";
267             broken = 1;
268         if new[pkg]["priority id"] == -1:
269             priority = priority + "[!]";
270             broken = 1;
271         if indexed:
272             line = "(%s): %-20s %-20s %-20s" % (index, pkg, priority, section);
273         else:
274             line = "%-20s %-20s %-20s" % (pkg, priority, section);
275         line = string.strip(line)+'\n';
276         file.write(line);
277     note = Katie.pkg.changes.get("lisa note");
278     if note:
279         print "*"*75;
280         print note;
281         print "*"*75;
282     return broken, note;
283
284 ################################################################################
285
286 def get_type (f):
287     # Determine the type
288     if f.has_key("dbtype"):
289         type = f["dbtype"];
290     elif f["type"] == "orig.tar.gz" or f["type"] == "tar.gz" or f["type"] == "diff.gz" or f["type"] == "dsc":
291         type = "dsc";
292     else:
293         utils.fubar("invalid type (%s) for new.  Dazed, confused and sure as heck not continuing." % (type));
294
295     # Validate the override type
296     type_id = db_access.get_override_type_id(type);
297     if type_id == -1:
298         utils.fubar("invalid type (%s) for new.  Say wha?" % (type));
299
300     return type;
301
302 ################################################################################
303
304 def index_range (index):
305     if index == 1:
306         return "1";
307     else:
308         return "1-%s" % (index);
309
310 ################################################################################
311 ################################################################################
312
313 def edit_new (new):
314     # Write the current data to a temporary file
315     temp_filename = tempfile.mktemp();
316     fd = os.open(temp_filename, os.O_RDWR|os.O_CREAT|os.O_EXCL, 0700);
317     os.close(fd);
318     temp_file = utils.open_file(temp_filename, 'w');
319     print_new (new, 0, temp_file);
320     temp_file.close();
321     # Spawn an editor on that file
322     editor = os.environ.get("EDITOR","vi")
323     result = os.system("%s %s" % (editor, temp_filename))
324     if result != 0:
325         utils.fubar ("%s invocation failed for %s." % (editor, temp_filename), result)
326     # Read the edited data back in
327     temp_file = utils.open_file(temp_filename);
328     lines = temp_file.readlines();
329     temp_file.close();
330     os.unlink(temp_filename);
331     # Parse the new data
332     for line in lines:
333         line = string.strip(line[:-1]);
334         if line == "":
335             continue;
336         s = string.split(line);
337         # Pad the list if necessary
338         s[len(s):3] = [None] * (3-len(s));
339         (pkg, priority, section) = s[:3];
340         if not new.has_key(pkg):
341             utils.warn("Ignoring unknown package '%s'" % (pkg));
342         else:
343             # Strip off any invalid markers, print_new will readd them.
344             if section[-3:] == "[!]":
345                 section = section[:-3];
346             if priority[-3:] == "[!]":
347                 priority = priority[:-3];
348             for file in new[pkg]["files"]:
349                 Katie.pkg.files[file]["section"] = section;
350                 Katie.pkg.files[file]["priority"] = priority;
351             new[pkg]["section"] = section;
352             new[pkg]["priority"] = priority;
353
354 ################################################################################
355
356 def edit_index (new, index):
357     priority = new[index]["priority"]
358     section = new[index]["section"]
359     type = new[index]["type"];
360     done = 0
361     while not done:
362         print string.join([index, priority, section], '\t');
363
364         answer = "XXX";
365         if type != "dsc":
366             prompt = "[B]oth, Priority, Section, Done ? ";
367         else:
368             prompt = "[S]ection, Done ? ";
369         edit_priority = edit_section = 0;
370
371         while string.find(prompt, answer) == -1:
372             answer = utils.our_raw_input(prompt);
373             m = katie.re_default_answer.match(prompt)
374             if answer == "":
375                 answer = m.group(1)
376             answer = string.upper(answer[:1])
377
378         if answer == 'P':
379             edit_priority = 1;
380         elif answer == 'S':
381             edit_section = 1;
382         elif answer == 'B':
383             edit_priority = edit_section = 1;
384         elif answer == 'D':
385             done = 1;
386
387         # Edit the priority
388         if edit_priority:
389             readline.set_completer(Priorities.complete);
390             got_priority = 0;
391             while not got_priority:
392                 new_priority = string.strip(utils.our_raw_input("New priority: "));
393                 if Priorities.priorities.count(new_priority) == 0:
394                     print "E: '%s' is not a valid priority, try again." % (new_priority);
395                 else:
396                     got_priority = 1;
397                     priority = new_priority;
398
399         # Edit the section
400         if edit_section:
401             readline.set_completer(Sections.complete);
402             got_section = 0;
403             while not got_section:
404                 new_section = string.strip(utils.our_raw_input("New section: "));
405                 if Sections.sections.count(new_section) == 0:
406                     print "E: '%s' is not a valid section, try again." % (new_section);
407                 else:
408                     got_section = 1;
409                     section = new_section;
410
411         # Reset the readline completer
412         readline.set_completer(None);
413
414     for file in new[index]["files"]:
415         Katie.pkg.files[file]["section"] = section;
416         Katie.pkg.files[file]["priority"] = priority;
417     new[index]["priority"] = priority;
418     new[index]["section"] = section;
419     return new;
420
421 ################################################################################
422
423 def edit_overrides (new):
424     print;
425     done = 0
426     while not done:
427         print_new (new, 1);
428         new_index = {};
429         index = 0;
430         for i in new.keys():
431             index = index + 1;
432             new_index[index] = i;
433
434         prompt = "(%s) edit override <n>, Editor, Done ? " % (index_range(index));
435
436         got_answer = 0
437         while not got_answer:
438             answer = utils.our_raw_input(prompt);
439             answer = string.upper(answer[:1]);
440             if answer == "E" or answer == "D":
441                 got_answer = 1;
442             elif katie.re_isanum.match (answer):
443                 answer = int(answer);
444                 if (answer < 1) or (answer > index):
445                     print "%s is not a valid index (%s).  Please retry." % (index_range(index), answer);
446                 else:
447                     got_answer = 1;
448
449         if answer == 'E':
450             edit_new(new);
451         elif answer == 'D':
452             done = 1;
453         else:
454             edit_index (new, new_index[answer]);
455
456     return new;
457
458 ################################################################################
459
460 def edit_note(note):
461     # Write the current data to a temporary file
462     temp_filename = tempfile.mktemp();
463     fd = os.open(temp_filename, os.O_RDWR|os.O_CREAT|os.O_EXCL, 0700);
464     os.close(fd);
465     temp_file = utils.open_file(temp_filename, 'w');
466     temp_file.write(note);
467     temp_file.close();
468     editor = os.environ.get("EDITOR","vi")
469     answer = 'E';
470     while answer == 'E':
471         os.system("%s %s" % (editor, temp_filename))
472         temp_file = utils.open_file(temp_filename);
473         note = string.rstrip(temp_file.read());
474         temp_file.close();
475         print "Note:";
476         print utils.prefix_multi_line_string(note,"  ");
477         prompt = "[D]one, Edit, Abandon, Quit ?"
478         answer = "XXX";
479         while string.find(prompt, answer) == -1:
480             answer = utils.our_raw_input(prompt);
481             m = katie.re_default_answer.search(prompt);
482             if answer == "":
483                 answer = m.group(1);
484             answer = string.upper(answer[:1]);
485     os.unlink(temp_filename);
486     if answer == 'A':
487         return;
488     elif answer == 'Q':
489         sys.exit(0);
490     Katie.pkg.changes["lisa note"] = note;
491     Katie.dump_vars(Cnf["Dir::Queue::New"]);
492
493 ################################################################################
494
495 def check_pkg ():
496     try:
497         less_fd = os.popen("less -", 'w', 0);
498         stdout_fd = sys.stdout;
499         try:
500             sys.stdout = less_fd;
501             fernanda.display_changes(Katie.pkg.changes_file);
502             files = Katie.pkg.files;
503             for file in files.keys():
504                 if files[file].has_key("new"):
505                     type = files[file]["type"];
506                     if type == "deb":
507                         fernanda.check_deb(file);
508                     elif type == "dsc":
509                         fernanda.check_dsc(file);
510         finally:
511             sys.stdout = stdout_fd;
512     except IOError, e:
513         if errno.errorcode[e.errno] == 'EPIPE':
514             utils.warn("[fernanda] Caught EPIPE; skipping.");
515             pass;
516         else:
517             raise;
518     except KeyboardInterrupt:
519         utils.warn("[fernanda] Caught C-c; skipping.");
520         pass;
521
522 ################################################################################
523
524 ## FIXME: horribly Debian specific
525
526 def do_bxa_notification():
527     files = Katie.pkg.files;
528     summary = "";
529     for file in files.keys():
530         if files[file]["type"] == "deb":
531             control = apt_pkg.ParseSection(apt_inst.debExtractControl(utils.open_file(file)));
532             summary = summary + "\n";
533             summary = summary + "Package: %s\n" % (control.Find("Package"));
534             summary = summary + "Description: %s\n" % (control.Find("Description"));
535     Katie.Subst["__BINARY_DESCRIPTIONS__"] = summary;
536     bxa_mail = utils.TemplateSubst(Katie.Subst,Cnf["Dir::Templates"]+"/lisa.bxa_notification");
537     utils.send_mail(bxa_mail,"");
538
539 ################################################################################
540
541 def add_overrides (new):
542     changes = Katie.pkg.changes;
543     files = Katie.pkg.files;
544
545     projectB.query("BEGIN WORK");
546     for suite in changes["suite"].keys():
547         suite_id = db_access.get_suite_id(suite);
548         for pkg in new.keys():
549             component_id = db_access.get_component_id(new[pkg]["component"]);
550             type_id = db_access.get_override_type_id(new[pkg]["type"]);
551             priority_id = new[pkg]["priority id"];
552             section_id = new[pkg]["section id"];
553             projectB.query("INSERT INTO override (suite, component, type, package, priority, section) VALUES (%s, %s, %s, '%s', %s, %s)" % (suite_id, component_id, type_id, pkg, priority_id, section_id));
554             for file in new[pkg]["files"]:
555                 if files[file].has_key("new"):
556                     del files[file]["new"];
557             del new[pkg];
558
559     projectB.query("COMMIT WORK");
560
561     if Cnf.FindB("Dinstall::BXANotify"):
562         do_bxa_notification();
563
564 ################################################################################
565
566 def do_new():
567     print "NEW\n";
568     files = Katie.pkg.files;
569     changes = Katie.pkg.changes;
570
571     # Make a copy of distribution we can happily trample on
572     changes["suite"] = copy.copy(changes["distribution"]);
573
574     # Fix up the list of target suites
575     for suite in changes["suite"].keys():
576         override = Cnf.Find("Suite::%s::OverrideSuite" % (suite));
577         if override:
578             del changes["suite"][suite];
579             changes["suite"][override] = 1;
580     # Validate suites
581     for suite in changes["suite"].keys():
582         suite_id = db_access.get_suite_id(suite);
583         if suite_id == -1:
584             utils.fubar("%s has invalid suite '%s' (possibly overriden).  say wha?" % (changes, suite));
585
586     # The main NEW processing loop
587     done = 0;
588     while not done:
589         # Find out what's new
590         new = determine_new(changes, files);
591
592         if not new:
593             break;
594
595         answer = "XXX";
596         if Options["No-Action"] or Options["Automatic"]:
597             answer = 'S';
598
599         (broken, note) = print_new(new, 0);
600         prompt = "";
601         if not broken:
602             prompt = "Add overrides, ";
603         else:
604             print "W: [!] marked entries must be fixed before package can be processed.";
605         if note:
606             print "W: note must be removed before package can be processed.";
607             prompt = prompt + "Remove note, ";
608         prompt = prompt + "Edit overrides, Check, Manual reject, Note edit, [S]kip, Quit ?";
609
610         while string.find(prompt, answer) == -1:
611             answer = utils.our_raw_input(prompt);
612             m = katie.re_default_answer.search(prompt);
613             if answer == "":
614                 answer = m.group(1)
615             answer = string.upper(answer[:1])
616
617         if answer == 'A':
618             done = add_overrides (new);
619         elif answer == 'C':
620             check_pkg();
621         elif answer == 'E':
622             new = edit_overrides (new);
623         elif answer == 'M':
624             aborted = Katie.do_reject(1, Options["Manual-Reject"]);
625             if not aborted:
626                 os.unlink(Katie.pkg.changes_file[:-8]+".katie");
627                 done = 1;
628         elif answer == 'N':
629             edit_note(changes.get("lisa note", ""));
630         elif answer == 'R':
631             confirm = string.lower(utils.our_raw_input("Really clear note (y/N)? "));
632             if confirm == "y":
633                 del changes["lisa note"];
634         elif answer == 'S':
635             done = 1;
636         elif answer == 'Q':
637             sys.exit(0)
638
639 ################################################################################
640 ################################################################################
641 ################################################################################
642
643 def usage (exit_code=0):
644     print """Usage: lisa [OPTION]... [CHANGES]...
645   -a, --automatic           automatic run
646   -h, --help                show this help and exit.
647   -m, --manual-reject=MSG   manual reject with `msg'
648   -n, --no-action           don't do anything
649   -V, --version             display the version number and exit"""
650     sys.exit(exit_code)
651
652 ################################################################################
653
654 def init():
655     global Cnf, Options, Logger, Katie, projectB, Sections, Priorities;
656
657     Cnf = utils.get_conf();
658
659     Arguments = [('a',"automatic","Lisa::Options::Automatic"),
660                  ('h',"help","Lisa::Options::Help"),
661                  ('m',"manual-reject","Lisa::Options::Manual-Reject", "HasArg"),
662                  ('n',"no-action","Lisa::Options::No-Action"),
663                  ('V',"version","Lisa::Options::Version")];
664
665     for i in ["automatic", "help", "manual-reject", "no-action", "version"]:
666         if not Cnf.has_key("Lisa::Options::%s" % (i)):
667             Cnf["Lisa::Options::%s" % (i)] = "";
668
669     changes_files = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
670     Options = Cnf.SubTree("Lisa::Options")
671
672     if Options["Help"]:
673         usage();
674
675     if Options["Version"]:
676         print "lisa %s" % (lisa_version);
677         sys.exit(0);
678
679     Katie = katie.Katie(Cnf);
680
681     if not Options["No-Action"]:
682         Logger = Katie.Logger = logging.Logger(Cnf, "lisa");
683
684     projectB = Katie.projectB;
685
686     Sections = Section_Completer();
687     Priorities = Priority_Completer();
688     readline.parse_and_bind("tab: complete");
689
690     return changes_files;
691
692 ################################################################################
693
694 def do_byhand():
695     done = 0;
696     while not done:
697         files = Katie.pkg.files;
698         will_install = 1;
699         byhand = [];
700
701         for file in files.keys():
702             if files[file]["type"] == "byhand":
703                 if os.path.exists(file):
704                     print "W: %s still present; please process byhand components and try again." % (file);
705                     will_install = 0;
706                 else:
707                     byhand.append(file);
708
709         answer = "XXXX";
710         if Options["No-Action"]:
711             answer = "S";
712         if will_install:
713             if Options["Automatic"] and not Options["No-Action"]:
714                 answer = 'A';
715             prompt = "[A]ccept, Manual reject, Skip, Quit ?";
716         else:
717             prompt = "Manual reject, [S]kip, Quit ?";
718
719         while string.find(prompt, answer) == -1:
720             answer = utils.our_raw_input(prompt);
721             m = katie.re_default_answer.search(prompt);
722             if answer == "":
723                 answer = m.group(1);
724             answer = string.upper(answer[:1]);
725
726         if answer == 'A':
727             done = 1;
728             for file in byhand:
729                 del files[file];
730         elif answer == 'M':
731             Katie.do_reject(1, Options["Manual-Reject"]);
732             os.unlink(Katie.pkg.changes_file[:-8]+".katie");
733             done = 1;
734         elif answer == 'S':
735             done = 1;
736         elif answer == 'Q':
737             sys.exit(0);
738
739 ################################################################################
740
741 def do_accept():
742     print "ACCEPT";
743     if not Options["No-Action"]:
744         (summary, short_summary) = Katie.build_summaries();
745         Katie.accept(summary, short_summary);
746         os.unlink(Katie.pkg.changes_file[:-8]+".katie");
747
748 def check_status(files):
749     new = byhand = 0;
750     for file in files.keys():
751         if files[file]["type"] == "byhand":
752             byhand = 1;
753         elif files[file].has_key("new"):
754             new = 1;
755     return (new, byhand);
756
757 def do_pkg(changes_file):
758     Katie.pkg.changes_file = changes_file;
759     Katie.init_vars();
760     Katie.update_vars();
761     Katie.update_subst();
762     files = Katie.pkg.files;
763
764     (new, byhand) = check_status(files);
765     if new or byhand:
766         if new:
767             do_new();
768         if byhand:
769             do_byhand();
770         (new, byhand) = check_status(files);
771
772     if not new and not byhand:
773         do_accept();
774
775 ################################################################################
776
777 def end():
778     accept_count = Katie.accept_count;
779     accept_bytes = Katie.accept_bytes;
780
781     if accept_count:
782         sets = "set"
783         if accept_count > 1:
784             sets = "sets"
785         sys.stderr.write("Accepted %d package %s, %s.\n" % (accept_count, sets, utils.size_type(int(accept_bytes))));
786         Logger.log(["total",accept_count,accept_bytes]);
787
788     if not Options["No-Action"]:
789         Logger.close();
790
791 ################################################################################
792
793 def main():
794     changes_files = init();
795     changes_files.sort(changes_compare);
796
797     # Kill me now? **FIXME**
798     Cnf["Dinstall::Options::No-Mail"] = "";
799     bcc = "X-Katie: %s" % (lisa_version);
800     if Cnf.has_key("Dinstall::Bcc"):
801         Katie.Subst["__BCC__"] = bcc + "\nBcc: %s" % (Cnf["Dinstall::Bcc"]);
802     else:
803         Katie.Subst["__BCC__"] = bcc;
804
805     for changes_file in changes_files:
806         changes_file = utils.validate_changes_file_arg(changes_file, 0);
807         if not changes_file:
808             continue;
809         print "\n" + changes_file;
810         do_pkg (changes_file);
811
812     end();
813
814 ################################################################################
815
816 if __name__ == '__main__':
817     main()