]> git.decadent.org.uk Git - dak.git/blob - fernanda.py
New.
[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  James Troup <james@nocrew.org>
5 # $Id: fernanda.py,v 1.1 2002-02-12 23:08: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 # <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[-5:] == ".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
108     print "---- contents of %s ----" % (filename);
109     do_command ("dpkg -c", deb_filename);
110
111     if is_a_udeb:
112         print "---- skipping copyright for µdeb ----";
113     else:
114         print "---- copyright of %s ----" % (filename);
115         print_copyright(deb_filename);
116
117     print "---- file listing of %s ----" % (filename);
118     do_command ("ls -l", deb_filename);
119
120 def display_changes (changes_filename):
121     print "---- .changes file for %s ----" % (changes_filename);
122     file = utils.open_file (changes_filename);
123     for line in file.readlines():
124         print line[:-1]
125     print ;
126     file.close();
127
128 def check_changes (changes_filename):
129     display_changes(changes_filename);
130
131     changes = utils.parse_changes (changes_filename, 0);
132     files = utils.build_file_list(changes, "");
133     for file in files.keys():
134         if file[-4:] == ".deb" or file[-5:] == ".udeb":
135             check_deb(file);
136         if file[-4:] == ".dsc":
137             check_dsc(file);
138         # else: => byhand
139
140 def main ():
141     global Cnf, projectB, db_files, waste, excluded;
142
143     Cnf = utils.get_conf()
144
145     Arguments = [('h',"help","Fernanda::Options::Help")];
146     for i in [ "help" ]:
147         if not Cnf.has_key("Frenanda::Options::%s" % (i)):
148             Cnf["Fernanda::Options::%s" % (i)] = "";
149
150     args = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
151     Options = Cnf.SubTree("Fernanda::Options")
152
153     if Options["Help"]:
154         usage();
155
156     stdout_fd = sys.stdout;
157
158     for file in args:
159         try:
160             # Pipe output for each argument through less
161             less_fd = os.popen("less -", 'w', 0);
162             sys.stdout = less_fd;
163
164             try:
165                 if file[-8:] == ".changes":
166                     check_changes(file);
167                 elif file[-4:] == ".deb" or file[-5:] == ".udeb":
168                     check_deb(file);
169                 elif file[-4:] == ".dsc":
170                     check_dsc(file);
171                 else:
172                     utils.fubar("Unrecognised file type: '%s'." % (file));
173             finally:
174                 # Reset stdout here so future less invocations aren't FUBAR
175                 less_fd.close();
176                 sys.stdout = stdout_fd;
177         except IOError, e:
178             if errno.errorcode[e.errno] == 'EPIPE':
179                 utils.warn("[fernanda] Caught EPIPE; skipping.");
180                 pass;
181             else:
182                 raise;
183         except KeyboardInterrupt:
184             utils.warn("[fernanda] Caught C-c; skipping.");
185             pass;
186
187 #######################################################################################
188
189 if __name__ == '__main__':
190     main()
191