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.3 2002-05-18 23:54:51 troup Exp $
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.
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.
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
21 ################################################################################
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,
34 ################################################################################
36 import errno, os, re, sys
40 ################################################################################
45 re_package = re.compile(r"^(.+?)_.*");
46 re_doc_directory = re.compile(r".*/doc/([^/]*).*");
48 ################################################################################
50 def usage (exit_code=0):
51 print """Usage: fernanda [PACKAGE]...
54 -h, --help show this help and exit
56 PACKAGE can be a .changes, .dsc, .deb or .udeb filename."""
60 ################################################################################
62 def do_command (command, filename):
63 o = os.popen("%s %s" % (command, filename));
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];
72 print "WARNING: No copyright found, please check package manually."
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);
80 o = os.popen("ar p %s data.tar.gz | tar xzOf - %s" % (deb_filename, copyright));
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():
90 def check_deb (deb_filename):
91 filename = os.path.basename(deb_filename);
93 if filename[-5:] == ".udeb":
98 print "---- control file for %s ----" % (filename);
99 do_command ("dpkg -I", deb_filename);
102 print "---- skipping lintian check for µdeb ----";
105 print "---- lintian check for %s ----" % (filename);
106 do_command ("lintian", deb_filename);
108 print "---- contents of %s ----" % (filename);
109 do_command ("dpkg -c", deb_filename);
112 print "---- skipping copyright for µdeb ----";
114 print "---- copyright of %s ----" % (filename);
115 print_copyright(deb_filename);
117 print "---- file listing of %s ----" % (filename);
118 do_command ("ls -l", deb_filename);
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():
128 def check_changes (changes_filename):
129 display_changes(changes_filename);
131 changes = utils.parse_changes (changes_filename);
132 files = utils.build_file_list(changes);
133 for file in files.keys():
134 if file[-4:] == ".deb" or file[-5:] == ".udeb":
136 if file[-4:] == ".dsc":
141 global Cnf, projectB, db_files, waste, excluded;
143 Cnf = utils.get_conf()
145 Arguments = [('h',"help","Fernanda::Options::Help")];
147 if not Cnf.has_key("Frenanda::Options::%s" % (i)):
148 Cnf["Fernanda::Options::%s" % (i)] = "";
150 args = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
151 Options = Cnf.SubTree("Fernanda::Options")
156 stdout_fd = sys.stdout;
160 # Pipe output for each argument through less
161 less_fd = os.popen("less -", 'w', 0);
162 sys.stdout = less_fd;
165 if file[-8:] == ".changes":
167 elif file[-4:] == ".deb" or file[-5:] == ".udeb":
169 elif file[-4:] == ".dsc":
172 utils.fubar("Unrecognised file type: '%s'." % (file));
174 # Reset stdout here so future less invocations aren't FUBAR
176 sys.stdout = stdout_fd;
178 if errno.errorcode[e.errno] == 'EPIPE':
179 utils.warn("[fernanda] Caught EPIPE; skipping.");
183 except KeyboardInterrupt:
184 utils.warn("[fernanda] Caught C-c; skipping.");
187 #######################################################################################
189 if __name__ == '__main__':