]> git.decadent.org.uk Git - dak.git/blob - fernanda
add functional help to melanie
[dak.git] / fernanda
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,v 1.2 2001-06-22 22:53:14 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, string, 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 do_command (command, filename):
51     o = os.popen("%s %s" % (command, filename));
52     print o.read();
53
54 def print_copyright (deb_filename):
55     package = re_package.sub(r'\1', deb_filename);
56     o = os.popen("ar p %s data.tar.gz | tar tzvf - | egrep 'usr(/share)?/doc/[^/]*/copyright' | awk '{ print $6 }' | head -n 1" % (deb_filename));
57     copyright = o.read()[:-1];
58
59     if copyright == "":
60         print "WARNING: No copyright found, please check package manually."
61         return;
62
63     doc_directory = re_doc_directory.sub(r'\1', copyright);
64     if package != doc_directory:
65         print "WARNING: wrong doc directory (expected %s, got %s)." % (package, doc_directory);
66         return;
67
68     o = os.popen("ar p %s data.tar.gz | tar xzOf - %s" % (deb_filename, copyright));
69     print o.read();
70
71 def check_dsc (dsc_filename):
72     dsc = utils.parse_changes(dsc_filename, 1);
73     files = utils.build_file_list(dsc, 1);
74
75     print "---- .dsc file for %s ----" % (dsc_filename);
76     dsc_file = utils.open_file(dsc_filename, 'r');
77     for line in dsc_file.readlines():
78         print line[:-1];
79     print;
80
81 def check_deb (deb_filename):
82     filename = os.path.basename(deb_filename);
83
84     if filename[-5:] == ".udeb":
85         is_a_udeb = 1;
86     else:
87         is_a_udeb = 0;
88
89     print "---- control file for %s ----" % (filename);
90     do_command ("dpkg -I", deb_filename);
91     
92     if is_a_udeb:
93         print "---- skipping lintian check for µdeb ----";
94         print ;
95     else:
96         print "---- lintian check for %s ----" % (filename);
97         do_command ("lintian", deb_filename);
98
99     print "---- contents of %s ----" % (filename);
100     do_command ("dpkg -c", deb_filename);
101
102     if is_a_udeb:
103         print "---- skipping copyright for µdeb ----";
104     else:
105         print "---- copyright of %s ----" % (filename);
106         print_copyright(deb_filename);
107
108     print "---- file listing of %s ----" % (filename);
109     do_command ("ls -l", deb_filename);
110
111 def check_changes (changes_filename):
112     changes = utils.parse_changes (changes_filename, 0);
113     
114     print "---- .changes file for %s ----" % (changes_filename);
115     file = utils.open_file (changes_filename, 'r');
116     for line in file.readlines():
117         print line[:-1]
118     print ;
119     file.close();
120     
121     files = utils.build_file_list(changes, "");
122     
123     for file in files.keys():
124         if file[-4:] == ".deb" or file[-5:] == ".udeb":
125             check_deb(file);
126         if file[-4:] == ".dsc":
127             check_dsc(file);
128         # else: => byhand
129
130 def main ():
131     global Cnf, projectB, db_files, waste, excluded;
132
133     apt_pkg.init();
134     
135     Cnf = apt_pkg.newConfiguration();
136     apt_pkg.ReadConfigFileISC(Cnf,utils.which_conf_file());
137
138     Arguments = [('D',"debug","Jennifer::Options::Debug", "IntVal"),
139                  ('h',"help","Jennifer::Options::Help"),
140                  ('v',"version","Jennifer::Options::Version")];
141
142     args = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
143     stdout_fd = sys.stdout;
144     
145     for file in args:
146         try:
147             # Pipe output for each argument through less
148             less_fd = os.popen("less -", 'w', 0);
149             sys.stdout = less_fd;
150
151             try:
152                 if file[-8:] == ".changes":
153                     check_changes(file);
154                 elif file[-4:] == ".deb" or file[-5:] == ".udeb":
155                     check_deb(file);
156                 elif file[-4:] == ".dsc":
157                     check_dsc(file);
158                 else:
159                     utils.fubar("Unrecognised file type: '%s'." % (file));
160             finally:
161                 # Reset stdout here so future less invocations aren't FUBAR
162                 less_fd.close();
163                 sys.stdout = stdout_fd;
164         except IOError, e:
165             if errno.errorcode[e.errno] == 'EPIPE':
166                 utils.warn("[fernanda] Caught EPIPE; skipping.");
167                 pass;
168             else:
169                 raise;
170         except KeyboardInterrupt:
171             utils.warn("[fernanda] Caught C-c; skipping.");
172             pass;
173
174 #######################################################################################
175
176 if __name__ == '__main__':
177     main()
178