X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=daklib%2Futils.py;h=47c80f3c137975468569f7b8cb354688448edfce;hb=d1d337ac1162793402ec207082be1161458b193d;hp=02278e9130f78579a8e04dea6aef8cd998a55ca8;hpb=aaa9ef21b62dad7f83af44f0b457e9ccc8a938ec;p=dak.git diff --git a/daklib/utils.py b/daklib/utils.py index 02278e91..47c80f3c 100755 --- a/daklib/utils.py +++ b/daklib/utils.py @@ -50,6 +50,9 @@ re_verwithext = re.compile(r"^(\d+)(?:\.(\d+))(?:\s+\((\S+)\))?$") re_srchasver = re.compile(r"^(\S+)\s+\((\S+)\)$") +html_escaping = {'"':'"', '&':'&', '<':'<', '>':'>'} +re_html_escaping = re.compile('|'.join(map(re.escape, html_escaping.keys()))) + default_config = "/etc/dak/dak.conf" default_apt_config = "/etc/dak/apt.conf" @@ -62,6 +65,11 @@ known_hashes = [("sha1", apt_pkg.sha1sum, (1, 8)), ################################################################################ +def html_escape(s): + return re_html_escaping.sub(lambda x: html_escaping.get(x.group(0)), s) + +################################################################################ + def open_file(filename, mode='r'): try: f = open(filename, mode) @@ -250,24 +258,28 @@ def check_hash(where, files, hashname, hashfunc): rejmsg = [] for f in files.keys(): + file_handle = None try: - file_handle = open_file(f) - - # Check for the hash entry, to not trigger a KeyError. - if not files[f].has_key(hash_key(hashname)): - rejmsg.append("%s: misses %s checksum in %s" % (f, hashname, - where)) + try: + file_handle = open_file(f) + + # Check for the hash entry, to not trigger a KeyError. + if not files[f].has_key(hash_key(hashname)): + rejmsg.append("%s: misses %s checksum in %s" % (f, hashname, + where)) + continue + + # Actually check the hash for correctness. + if hashfunc(file_handle) != files[f][hash_key(hashname)]: + rejmsg.append("%s: %s check failed in %s" % (f, hashname, + where)) + except CantOpenError: + # TODO: This happens when the file is in the pool. + # warn("Cannot open file %s" % f) continue - - # Actually check the hash for correctness. - if hashfunc(file_handle) != files[f][hash_key(hashname)]: - rejmsg.append("%s: %s check failed in %s" % (f, hashname, - where)) - except CantOpenError: - # XXX: IS THIS THE BLOODY CASE WHEN THE FILE'S IN THE POOL!? - continue finally: - file_handle.close() + if file_handle: + file_handle.close() return rejmsg ################################################################################ @@ -278,7 +290,15 @@ def check_size(where, files): rejmsg = [] for f in files.keys(): - actual_size = os.stat(f)[stat.ST_SIZE] + try: + entry = os.stat(f) + except OSError, exc: + if exc.errno == 2: + # TODO: This happens when the file is in the pool. + continue + raise + + actual_size = entry[stat.ST_SIZE] size = int(files[f]["size"]) if size != actual_size: rejmsg.append("%s: actual file size (%s) does not match size (%s) in %s" @@ -383,11 +403,15 @@ def parse_checksums(where, files, manifest, hashname): break hash, size, file = line.strip().split(' ') if not files.has_key(file): - rejmsg.append("%s: not present in files but in checksums-%s in %s" % - (file, hashname, where)) + # TODO: check for the file's entry in the original files dict, not + # the one modified by (auto)byhand and other weird stuff + # rejmsg.append("%s: not present in files but in checksums-%s in %s" % + # (file, hashname, where)) + continue if not files[file]["size"] == size: rejmsg.append("%s: size differs for files and checksums-%s entry "\ "in %s" % (file, hashname, where)) + continue files[file][hash_key(hashname)] = hash for f in files.keys(): if not files[f].has_key(hash_key(hashname)): @@ -420,7 +444,10 @@ def build_file_list(changes, is_a_dsc=0, field="files", hashname="md5sum"): format = format[:2] if is_a_dsc: - if format != (1,0): + # format = (1,0) are the only formats we currently accept, + # format = (0,0) are missing format headers of which we still + # have some in the archive. + if format != (1,0) and format != (0,0): raise UnknownFormatError, "%s" % (changes.get("format","0.0")) else: if (format < (1,5) or format > (1,8)):