X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=dak%2Fexamine_package.py;h=c7ab7ad5865c8d9619cd9951acc8086e2610bbad;hb=d1d337ac1162793402ec207082be1161458b193d;hp=d452d71ca64359df7261fae40142c0798aa244df;hpb=1408d82381556c9e2b3eaa04412846c766a011db;p=dak.git diff --git a/dak/examine_package.py b/dak/examine_package.py index d452d71c..c7ab7ad5 100755 --- a/dak/examine_package.py +++ b/dak/examine_package.py @@ -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 ################################################################################ @@ -54,17 +55,14 @@ re_version = re.compile('^(.*)\((.*)\)') re_newlinespace = re.compile('\n') re_spacestrip = re.compile('(\s)') -html_escaping = {'"':'"', '&':'&', '<':'<', '>':'>'} -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 = {} @@ -88,12 +86,9 @@ PACKAGE can be a .changes, .dsc, .deb or .udeb filename.""" ################################################################################ # probably xml.sax.saxutils would work as well -def html_escape(s): - return re_html_escaping.sub(lambda x: html_escaping.get(x.group(0)), s) - def escape_if_needed(s): if use_html: - return re_html_escaping.sub(lambda x: html_escaping.get(x.group(0)), s) + return utils.re_html_escaping.sub(lambda x: utils.html_escaping.get(x.group(0)), s) else: return s @@ -102,9 +97,9 @@ def headline(s, level=2, bodyelement=None): if bodyelement: print """ %(title)s (click to toggle) - """%{"bodyelement":bodyelement,"title":html_escape(s)} + """%{"bodyelement":bodyelement,"title":utils.html_escape(s)} else: - print "%s" % (level, html_escape(s), level) + print "%s" % (level, utils.html_escape(s), level) else: print "---- %s ----" % (s) @@ -129,7 +124,7 @@ html_colours = { def colour_output(s, colour): if use_html: - return ("%s%s%s" % (html_colours[colour][0], html_escape(s), html_colours[colour][1])) + return ("%s%s%s" % (html_colours[colour][0], utils.html_escape(s), html_colours[colour][1])) else: return ("%s%s%s" % (ansi_colours[colour], s, ansi_colours['end'])) @@ -145,7 +140,7 @@ def formatted_text(s, strip=False): if use_html: if strip: s = s.strip() - return "
%s
" % (html_escape(s)) + return "
%s
" % (utils.html_escape(s)) else: return s @@ -225,7 +220,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 +274,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() @@ -398,8 +393,7 @@ def get_copyright (deb_filename): cright = o.read()[:-1] if cright == "": - print_formatted_text("WARNING: No copyright found, please check package manually.") - return + return formatted_text("WARNING: No copyright found, please check package manually.") doc_directory = re_doc_directory.sub(r'\1', cright) if package != doc_directory: @@ -407,16 +401,15 @@ def get_copyright (deb_filename): o = os.popen("dpkg-deb --fsys-tarfile %s | tar xvOf - %s 2>/dev/null" % (deb_filename, cright)) cright = o.read() - crightmd5 = md5.md5(cright).hexdigest() + copyrightmd5 = md5.md5(cright).hexdigest() res = "" - if printed_copyrights.has_key(crightmd5) and printed_copyrights[crightmd5] != "%s (%s)" % (package, deb_filename): - res += formatted_text( "NOTE: Copyright is the same as %s.\n" % \ - (printed_copyrights[crightmd5])) + if printed_copyrights.has_key(copyrightmd5) and printed_copyrights[copyrightmd5] != "%s (%s)" % (package, deb_filename): + res += formatted_text( "NOTE: Copyright is the same as %s.\n\n" % \ + (printed_copyrights[copyrightmd5])) else: - printed_copyrights[crightmd5] = "%s (%s)" % (package, deb_filename) - res += formatted_text(cright) - return res + printed_copyrights[copyrightmd5] = "%s (%s)" % (package, deb_filename) + return res+formatted_text(cright) def check_dsc (dsc_filename): (dsc) = read_changes_or_dsc(dsc_filename) @@ -459,11 +452,11 @@ def check_deb (deb_filename): # Read a file, strip the signature and return the modified contents as # a string. def strip_pgp_signature (filename): - f = daklib.utils.open_file (filename) + file = utils.open_file (filename) contents = "" inside_signature = 0 skip_next = 0 - for line in f.readlines(): + for line in file.readlines(): if line[:-1] == "": continue if inside_signature: @@ -481,7 +474,7 @@ def strip_pgp_signature (filename): inside_signature = 0 continue contents += line - f.close() + file.close() return contents def display_changes(changes_filename): @@ -491,8 +484,8 @@ 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) + 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) @@ -503,7 +496,7 @@ def check_changes (changes_filename): 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"), @@ -531,24 +524,24 @@ def main (): if f.endswith(".changes"): check_changes(f) elif f.endswith(".deb") or f.endswith(".udeb"): - check_deb(f) + check_deb(file) elif f.endswith(".dsc"): check_dsc(f) else: - daklib.utils.fubar("Unrecognised file type: '%s'." % (f)) + utils.fubar("Unrecognised file type: '%s'." % (f)) finally: if not Options["Html-Output"]: # Reset stdout here so future less invocations aren't FUBAR less_fd.close() sys.stdout = stdout_fd except IOError, e: - if e.errno == errno.EPIPE: - daklib.utils.warn("[examine-package] Caught EPIPE; skipping.") + if errno.errorcode[e.errno] == 'EPIPE': + 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 #######################################################################################