]> git.decadent.org.uk Git - dak.git/blob - fernanda.py
run linda too
[dak.git] / fernanda.py
1 #!/usr/bin/env python
2
3 # Script to automate some parts of checking NEW packages
4 # Copyright (C) 2000, 2001, 2002  James Troup <james@nocrew.org>
5 # $Id: fernanda.py,v 1.5 2002-11-19 03:15:05 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 # <Omnic> elmo wrote docs?!!?!?!?!?!?!
24 # <aj> as if he wasn't scary enough before!!
25 # * aj imagines a little red furry toy sitting hunched over a computer
26 #   tapping furiously and giggling to himself
27 # <aj> eventually he stops, and his heads slowly spins around and you
28 #      see this really evil grin and then he sees you, and picks up a
29 #      knife from beside the keyboard and throws it at you, and as you
30 #      breathe your last breath, he starts giggling again
31 # <aj> but i should be telling this to my psychiatrist, not you guys,
32 #      right? :)
33
34 ################################################################################
35
36 import errno, os, re, sys
37 import utils
38 import apt_pkg
39
40 ################################################################################
41
42 Cnf = None;
43 projectB = None;
44
45 re_package = re.compile(r"^(.+?)_.*");
46 re_doc_directory = re.compile(r".*/doc/([^/]*).*");
47
48 ################################################################################
49
50 def usage (exit_code=0):
51     print """Usage: fernanda [PACKAGE]...
52 Check NEW package(s).
53
54   -h, --help                 show this help and exit
55
56 PACKAGE can be a .changes, .dsc, .deb or .udeb filename."""
57
58     sys.exit(exit_code)
59
60 ################################################################################
61
62 def do_command (command, filename):
63     o = os.popen("%s %s" % (command, filename));
64     print o.read();
65
66 def print_copyright (deb_filename):
67     package = re_package.sub(r'\1', deb_filename);
68     o = os.popen("ar p %s data.tar.gz | tar tzvf - | egrep 'usr(/share)?/doc/[^/]*/copyright' | awk '{ print $6 }' | head -n 1" % (deb_filename));
69     copyright = o.read()[:-1];
70
71     if copyright == "":
72         print "WARNING: No copyright found, please check package manually."
73         return;
74
75     doc_directory = re_doc_directory.sub(r'\1', copyright);
76     if package != doc_directory:
77         print "WARNING: wrong doc directory (expected %s, got %s)." % (package, doc_directory);
78         return;
79
80     o = os.popen("ar p %s data.tar.gz | tar xzOf - %s" % (deb_filename, copyright));
81     print o.read();
82
83 def check_dsc (dsc_filename):
84     print "---- .dsc file for %s ----" % (dsc_filename);
85     dsc_file = utils.open_file(dsc_filename);
86     for line in dsc_file.readlines():
87         print line[:-1];
88     print;
89
90 def check_deb (deb_filename):
91     filename = os.path.basename(deb_filename);
92
93     if filename.endswith(".udeb"):
94         is_a_udeb = 1;
95     else:
96         is_a_udeb = 0;
97
98     print "---- control file for %s ----" % (filename);
99     do_command ("dpkg -I", deb_filename);
100
101     if is_a_udeb:
102         print "---- skipping lintian check for µdeb ----";
103         print ;
104     else:
105         print "---- lintian check for %s ----" % (filename);
106         do_command ("lintian", deb_filename);
107         print "---- linda check for %s ----" % (filename);
108         do_command ("linda", deb_filename);
109
110     print "---- contents of %s ----" % (filename);
111     do_command ("dpkg -c", deb_filename);
112
113     if is_a_udeb:
114         print "---- skipping copyright for µdeb ----";
115     else:
116         print "---- copyright of %s ----" % (filename);
117         print_copyright(deb_filename);
118
119     print "---- file listing of %s ----" % (filename);
120     do_command ("ls -l", deb_filename);
121
122 def display_changes (changes_filename):
123     print "---- .changes file for %s ----" % (changes_filename);
124     file = utils.open_file (changes_filename);
125     for line in file.readlines():
126         print line[:-1]
127     print ;
128     file.close();
129
130 def check_changes (changes_filename):
131     display_changes(changes_filename);
132
133     changes = utils.parse_changes (changes_filename);
134     files = utils.build_file_list(changes);
135     for file in files.keys():
136         if file.endswith(".deb") or file.endswith(".udeb"):
137             check_deb(file);
138         if file.endswith(".dsc"):
139             check_dsc(file);
140         # else: => byhand
141
142 def main ():
143     global Cnf, projectB, db_files, waste, excluded;
144
145     Cnf = utils.get_conf()
146
147     Arguments = [('h',"help","Fernanda::Options::Help")];
148     for i in [ "help" ]:
149         if not Cnf.has_key("Frenanda::Options::%s" % (i)):
150             Cnf["Fernanda::Options::%s" % (i)] = "";
151
152     args = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
153     Options = Cnf.SubTree("Fernanda::Options")
154
155     if Options["Help"]:
156         usage();
157
158     stdout_fd = sys.stdout;
159
160     for file in args:
161         try:
162             # Pipe output for each argument through less
163             less_fd = os.popen("less -", 'w', 0);
164             sys.stdout = less_fd;
165
166             try:
167                 if file.endswith(".changes"):
168                     check_changes(file);
169                 elif file.endswith(".deb") or file.endswith(".udeb"):
170                     check_deb(file);
171                 elif file.endswith(".dsc"):
172                     check_dsc(file);
173                 else:
174                     utils.fubar("Unrecognised file type: '%s'." % (file));
175             finally:
176                 # Reset stdout here so future less invocations aren't FUBAR
177                 less_fd.close();
178                 sys.stdout = stdout_fd;
179         except IOError, e:
180             if errno.errorcode[e.errno] == 'EPIPE':
181                 utils.warn("[fernanda] Caught EPIPE; skipping.");
182                 pass;
183             else:
184                 raise;
185         except KeyboardInterrupt:
186             utils.warn("[fernanda] Caught C-c; skipping.");
187             pass;
188
189 #######################################################################################
190
191 if __name__ == '__main__':
192     main()
193