X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=dak%2Fexamine_package.py;h=5cb1a77e9a6fb8dcbd3e62d511056d4dfe08edd8;hb=7b16dbdee739c035838740b7284927020033bee1;hp=5a35a99da9f7a28836fa955debec1b8bad37f60e;hpb=317c4c7f173540de71907f1e527437d88f48a3b9;p=dak.git diff --git a/dak/examine_package.py b/dak/examine_package.py index 5a35a99d..5cb1a77e 100755 --- a/dak/examine_package.py +++ b/dak/examine_package.py @@ -42,6 +42,12 @@ to stdout. Those functions can be used in multithreaded parts of dak. ################################################################################ +# suppress some deprecation warnings in squeeze related to md5 module +import warnings +warnings.filterwarnings('ignore', \ + "the md5 module is deprecated; use hashlib instead", \ + DeprecationWarning) + import errno import os import re @@ -54,7 +60,8 @@ import commands import threading from daklib import utils -from daklib.dbconn import DBConn, get_binary_from_name_suite +from daklib.dbconn import DBConn, get_component_by_package_suite +from daklib.gpg import SignedFile from daklib.regexes import html_escaping, re_html_escaping, re_version, re_spacestrip, \ re_contrib, re_nonfree, re_localhost, re_newlinespace, \ re_package, re_doc_directory @@ -64,8 +71,8 @@ from daklib.regexes import html_escaping, re_html_escaping, re_version, re_space Cnf = None Cnf = utils.get_conf() -changes_lock = threading.Lock() -printed_copyrights = {} +printed = threading.local() +printed.copyrights = {} package_relations = {} #: Store relations of packages for later output # default is to not output html. @@ -111,18 +118,22 @@ ansi_colours = { 'main': "\033[36m", 'contrib': "\033[33m", 'nonfree': "\033[31m", + 'provides': "\033[35m", 'arch': "\033[32m", 'end': "\033[0m", 'bold': "\033[1m", - 'maintainer': "\033[32m"} + 'maintainer': "\033[32m", + 'distro': "\033[1m\033[41m"} html_colours = { 'main': ('',""), 'contrib': ('',""), 'nonfree': ('',""), + 'provides': ('',""), 'arch': ('',""), 'bold': ('',""), - 'maintainer': ('',"")} + 'maintainer': ('',""), + 'distro': ('',"")} def colour_output(s, colour): if use_html: @@ -298,6 +309,9 @@ def read_changes_or_dsc (suite, filename, session = None): elif k == "architecture": if (dsc["architecture"] != "any"): dsc['architecture'] = colour_output(dsc["architecture"], 'arch') + elif k == "distribution": + if dsc["distribution"] not in ('unstable', 'experimental'): + dsc['distribution'] = colour_output(dsc["distribution"], 'distro') elif k in ("files","changes","description"): if use_html: dsc[k] = formatted_text(dsc[k], strip=True) @@ -311,13 +325,38 @@ def read_changes_or_dsc (suite, filename, session = None): filecontents = '\n'.join(map(lambda x: format_field(x,dsc[x.lower()]), keysinorder))+'\n' return filecontents +def get_provides(suite): + provides = set() + session = DBConn().session() + query = '''SELECT DISTINCT value + FROM binaries_metadata m + JOIN bin_associations b + ON b.bin = m.bin_id + WHERE key_id = ( + SELECT key_id + FROM metadata_keys + WHERE key = 'Provides' ) + AND b.suite = ( + SELECT id + FROM suite + WHERE suite_name = '%(suite)s' + OR codename = '%(suite)s')''' % \ + {'suite': suite} + for p in session.execute(query): + for e in p: + for i in e.split(','): + provides.add(i.strip()) + session.close() + return provides + def create_depends_string (suite, depends_tree, session = None): result = "" if suite == 'experimental': - suite_where = "in ('experimental','unstable')" + suite_list = ['experimental','unstable'] else: - suite_where = "= '%s'" % suite + suite_list = [suite] + provides = set() comma_count = 1 for l in depends_tree: if (comma_count >= 2): @@ -328,17 +367,16 @@ def create_depends_string (suite, depends_tree, session = None): result += " | " # doesn't do version lookup yet. - res = get_binary_from_name_suite(d['name'], suite_where, session) - if res.rowcount > 0: - i = res.fetchone() - + component = get_component_by_package_suite(d['name'], suite_list, \ + session = session) + if component is not None: adepends = d['name'] if d['version'] != '' : adepends += " (%s)" % (d['version']) - if i[2] == "contrib": + if component == "contrib": result += colour_output(adepends, "contrib") - elif i[2] == "non-free": + elif component == "non-free": result += colour_output(adepends, "nonfree") else : result += colour_output(adepends, "main") @@ -346,7 +384,12 @@ def create_depends_string (suite, depends_tree, session = None): adepends = d['name'] if d['version'] != '' : adepends += " (%s)" % (d['version']) - result += colour_output(adepends, "bold") + if not provides: + provides = get_provides(suite) + if d['name'] in provides: + result += colour_output(adepends, "provides") + else: + result += colour_output(adepends, "bold") or_count += 1 comma_count += 1 return result @@ -416,7 +459,7 @@ def do_lintian (filename): return do_command("lintian --show-overrides --color always", filename, 1) def get_copyright (deb_filename): - global changes_lock, printed_copyrights + global printed 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)) @@ -434,13 +477,11 @@ def get_copyright (deb_filename): copyrightmd5 = md5.md5(cright).hexdigest() res = "" - changes_lock.acquire() - if printed_copyrights.has_key(copyrightmd5) and printed_copyrights[copyrightmd5] != "%s (%s)" % (package, deb_filename): + 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])) + (printed.copyrights[copyrightmd5])) else: - printed_copyrights[copyrightmd5] = "%s (%s)" % (package, deb_filename) - changes_lock.release() + printed.copyrights[copyrightmd5] = "%s (%s)" % (package, deb_filename) return res+formatted_text(cright) def get_readme_source (dsc_filename): @@ -518,37 +559,15 @@ def check_deb (suite, deb_filename, session = None): # Read a file, strip the signature and return the modified contents as # a string. def strip_pgp_signature (filename): - inputfile = utils.open_file (filename) - contents = "" - inside_signature = 0 - skip_next = 0 - for line in inputfile.readlines(): - if line[:-1] == "": - continue - if inside_signature: - continue - if skip_next: - skip_next = 0 - continue - if line.startswith("-----BEGIN PGP SIGNED MESSAGE"): - skip_next = 1 - continue - if line.startswith("-----BEGIN PGP SIGNATURE"): - inside_signature = 1 - continue - if line.startswith("-----END PGP SIGNATURE"): - inside_signature = 0 - continue - contents += line - inputfile.close() - return contents + with utils.open_file(filename) as f: + data = f.read() + signedfile = SignedFile(data, keyrings=(), require_signature=False) + return signedfile.contents def display_changes(suite, changes_filename): - global changes_lock, printed_copyrights + global printed changes = read_changes_or_dsc(suite, changes_filename) - changes_lock.acquire() - printed_copyrights = {} - changes_lock.release() + printed.copyrights = {} return foldable_output(changes_filename, "changes", changes, norow=True) def check_changes (changes_filename):