]> git.decadent.org.uk Git - dak.git/blobdiff - dak/examine_package.py
Merge branch 'master' into security
[dak.git] / dak / examine_package.py
old mode 100644 (file)
new mode 100755 (executable)
index 182ed2d..ae3ec6c
@@ -34,7 +34,8 @@
 
 import errno, os, pg, re, sys, md5
 import apt_pkg, apt_inst
-import daklib.database, daklib.utils, daklib.queue
+from daklib import database
+from daklib import utils
 
 ################################################################################
 
@@ -62,9 +63,9 @@ re_html_escaping = re.compile('|'.join(map(re.escape, html_escaping.keys())))
 Cnf = None
 projectB = None
 
-Cnf = daklib.utils.get_conf()
+Cnf = utils.get_conf()
 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
-daklib.database.init(Cnf, projectB)
+database.init(Cnf, projectB)
 
 printed_copyrights = {}
 
@@ -101,7 +102,7 @@ def headline(s, level=2, bodyelement=None):
     if use_html:
         if bodyelement:
             print """<thead>
-                <tr><th colspan="2" class="title" onclick="toggle('%(bodyelement)s', 'table-row-group', 'table-row-group')">%(title)s</th></tr>
+                <tr><th colspan="2" class="title" onclick="toggle('%(bodyelement)s', 'table-row-group', 'table-row-group')">%(title)s <span class="toggle-msg">(click to toggle)</span></th></tr>
               </thead>"""%{"bodyelement":bodyelement,"title":html_escape(s)}
         else:
             print "<h%d>%s</h%d>" % (level, html_escape(s), level)
@@ -225,7 +226,7 @@ def read_control (filename):
     maintainer = ''
     arch = ''
 
-    deb_file = daklib.utils.open_file(filename)
+    deb_file = utils.open_file(filename)
     try:
         extracts = apt_inst.debExtractControl(deb_file)
         control = apt_pkg.ParseSection(extracts)
@@ -279,9 +280,9 @@ def read_control (filename):
 def read_changes_or_dsc (filename):
     dsc = {}
 
-    dsc_file = daklib.utils.open_file(filename)
+    dsc_file = utils.open_file(filename)
     try:
-        dsc = daklib.utils.parse_changes(filename)
+        dsc = utils.parse_changes(filename)
     except:
         return formatted_text("can't parse .dsc control info")
     dsc_file.close()
@@ -368,9 +369,12 @@ def output_deb_info(filename):
         elif key == 'Maintainer':
             field_value = maintainer
         elif key == 'Description':
-            desc = control.Find(key)
-            desc = re_newlinespace.sub('\n ', desc)
-            field_value = escape_if_needed(desc)
+            if use_html:
+                field_value = formatted_text(control.Find(key), strip=True)
+            else:
+                desc = control.Find(key)
+                desc = re_newlinespace.sub('\n ', desc)
+                field_value = escape_if_needed(desc)
         else:
             field_value = escape_if_needed(control.Find(key))
         to_print += " "+format_field(key,field_value)+'\n'
@@ -392,18 +396,18 @@ def do_lintian (filename):
 def get_copyright (deb_filename):
     package = re_package.sub(r'\1', deb_filename)
     o = os.popen("dpkg-deb -c %s | egrep 'usr(/share)?/doc/[^/]*/copyright' | awk '{print $6}' | head -n 1" % (deb_filename))
-    copyright = o.read()[:-1]
+    cright = o.read()[:-1]
 
-    if copyright == "":
+    if cright == "":
         return formatted_text("WARNING: No copyright found, please check package manually.")
 
-    doc_directory = re_doc_directory.sub(r'\1', copyright)
+    doc_directory = re_doc_directory.sub(r'\1', cright)
     if package != doc_directory:
         return formatted_text("WARNING: wrong doc directory (expected %s, got %s)." % (package, doc_directory))
 
-    o = os.popen("dpkg-deb --fsys-tarfile %s | tar xvOf - %s 2>/dev/null" % (deb_filename, copyright))
-    copyright = o.read()
-    copyrightmd5 = md5.md5(copyright).hexdigest()
+    o = os.popen("dpkg-deb --fsys-tarfile %s | tar xvOf - %s 2>/dev/null" % (deb_filename, cright))
+    cright = o.read()
+    copyrightmd5 = md5.md5(cright).hexdigest()
 
     res = ""
     if printed_copyrights.has_key(copyrightmd5) and printed_copyrights[copyrightmd5] != "%s (%s)" % (package, deb_filename):
@@ -411,7 +415,7 @@ def get_copyright (deb_filename):
                                (printed_copyrights[copyrightmd5]))
     else:
         printed_copyrights[copyrightmd5] = "%s (%s)" % (package, deb_filename)
-    return res+formatted_text(copyright)
+    return res+formatted_text(cright)
 
 def check_dsc (dsc_filename):
     (dsc) = read_changes_or_dsc(dsc_filename)
@@ -454,7 +458,7 @@ def check_deb (deb_filename):
 # Read a file, strip the signature and return the modified contents as
 # a string.
 def strip_pgp_signature (filename):
-    file = daklib.utils.open_file (filename)
+    file = utils.open_file (filename)
     contents = ""
     inside_signature = 0
     skip_next = 0
@@ -486,19 +490,19 @@ def display_changes(changes_filename):
 def check_changes (changes_filename):
     display_changes(changes_filename)
 
-    changes = daklib.utils.parse_changes (changes_filename)
-    files = daklib.utils.build_file_list(changes)
-    for file in files.keys():
-        if file.endswith(".deb") or file.endswith(".udeb"):
-            check_deb(file)
-        if file.endswith(".dsc"):
-            check_dsc(file)
+    changes = utils.parse_changes (changes_filename)
+    files = utils.build_file_list(changes)
+    for f in files.keys():
+        if f.endswith(".deb") or f.endswith(".udeb"):
+            check_deb(f)
+        if f.endswith(".dsc"):
+            check_dsc(f)
         # else: => byhand
 
 def main ():
     global Cnf, projectB, db_files, waste, excluded
 
-#    Cnf = daklib.utils.get_conf()
+#    Cnf = utils.get_conf()
 
     Arguments = [('h',"help","Examine-Package::Options::Help"),
                  ('H',"html-output","Examine-Package::Options::Html-Output"),
@@ -515,7 +519,7 @@ def main ():
 
     stdout_fd = sys.stdout
 
-    for file in args:
+    for f in args:
         try:
             if not Options["Html-Output"]:
                 # Pipe output for each argument through less
@@ -523,14 +527,14 @@ def main ():
                 # -R added to display raw control chars for colour
                 sys.stdout = less_fd
             try:
-                if file.endswith(".changes"):
-                    check_changes(file)
-                elif file.endswith(".deb") or file.endswith(".udeb"):
+                if f.endswith(".changes"):
+                    check_changes(f)
+                elif f.endswith(".deb") or f.endswith(".udeb"):
                     check_deb(file)
-                elif file.endswith(".dsc"):
-                    check_dsc(file)
+                elif f.endswith(".dsc"):
+                    check_dsc(f)
                 else:
-                    daklib.utils.fubar("Unrecognised file type: '%s'." % (file))
+                    utils.fubar("Unrecognised file type: '%s'." % (f))
             finally:
                 if not Options["Html-Output"]:
                     # Reset stdout here so future less invocations aren't FUBAR
@@ -538,12 +542,12 @@ def main ():
                     sys.stdout = stdout_fd
         except IOError, e:
             if errno.errorcode[e.errno] == 'EPIPE':
-                daklib.utils.warn("[examine-package] Caught EPIPE; skipping.")
+                utils.warn("[examine-package] Caught EPIPE; skipping.")
                 pass
             else:
                 raise
         except KeyboardInterrupt:
-            daklib.utils.warn("[examine-package] Caught C-c; skipping.")
+            utils.warn("[examine-package] Caught C-c; skipping.")
             pass
 
 #######################################################################################