X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=daklib%2Futils.py;h=c4f93fe5f651cc2b8bc5c6b82861a548f554aebc;hb=9dd35112e98631a7e367d2dd6cc3b05ba1a4ea3a;hp=32cba98f03443ec560faed686d839b9381f760f3;hpb=f558a3d8c95f65f905d46681c1d43e6986fee256;p=dak.git diff --git a/daklib/utils.py b/daklib/utils.py index 32cba98f..c4f93fe5 100755 --- a/daklib/utils.py +++ b/daklib/utils.py @@ -45,8 +45,11 @@ from dak_exceptions import * from textutils import fix_maintainer from regexes import re_html_escaping, html_escaping, re_single_line_field, \ re_multi_line_field, re_srchasver, re_verwithext, \ - re_parse_maintainer, re_taint_free, re_gpg_uid, re_re_mark, \ - re_whitespace_comment + re_parse_maintainer, re_taint_free, re_gpg_uid, \ + re_re_mark, re_whitespace_comment, re_issource + +from srcformats import srcformats +from collections import defaultdict ################################################################################ @@ -332,6 +335,79 @@ def check_size(where, files): ################################################################################ +def check_dsc_files(dsc_filename, dsc=None, dsc_files=None): + """ + Verify that the files listed in the Files field of the .dsc are + those expected given the announced Format. + + @type dsc_filename: string + @param dsc_filename: path of .dsc file + + @type dsc: dict + @param dsc: the content of the .dsc parsed by C{parse_changes()} + + @type dsc_files: dict + @param dsc_files: the file list returned by C{build_file_list()} + + @rtype: list + @return: all errors detected + """ + rejmsg = [] + + # Parse the file if needed + if dsc is None: + dsc = parse_changes(dsc_filename, signing_rules=1); + + if dsc_files is None: + dsc_files = build_file_list(dsc, is_a_dsc=1) + + # Ensure .dsc lists proper set of source files according to the format + # announced + has = defaultdict(lambda: 0) + + for f in dsc_files.keys(): + m = re_issource.match(f) + if not m: + rejmsg.append("%s: %s in Files field not recognised as source." + % (dsc_filename, f)) + continue + ftype = m.group(3) + if ftype == "orig.tar.gz": + has['orig_tar_gz'] += 1 + has['orig_tar'] += 1 + elif ftype == "diff.gz": + has['debian_diff'] += 1 + elif ftype == "tar.gz": + has['native_tar_gz'] += 1 + has['native_tar'] += 1 + elif re.match(r"debian\.tar\.(gz|bz2|lzma)", ftype): + has['debian_tar'] += 1 + elif re.match(r"orig\.tar\.(gz|bz2|lzma)", ftype): + has['orig_tar'] += 1 + elif re.match(r"tar\.(gz|bz2|lzma)", ftype): + has['native_tar'] += 1 + elif re.match(r"orig-.+\.tar\.(gz|bz2|lzma)", ftype): + has['more_orig_tar'] += 1 + else: + reject("%s: unexpected source file '%s'" % (dsc_filename, f)) + if has['orig_tar'] > 1: + rejmsg.append("%s: lists multiple .orig tarballs." % (dsc_filename)) + if has['native_tar'] > 1: + rejmsg.append("%s: lists multiple native tarballs." % (dsc_filename)) + if has['debian_tar'] > 1 or has['debian_diff'] > 1: + rejmsg.append("%s: lists multiple debian diff/tarballs." % (dsc_filename)) + + for format in srcformats: + if format.re_format.match(dsc['format']): + rejmsg.extend([ + '%s: %s' % (dsc_filename, x) for x in format.reject_msgs(has) + ]) + break + + return rejmsg + +################################################################################ + def check_hash_fields(what, manifest): """ check_hash_fields ensures that there are no checksum fields in the @@ -394,7 +470,12 @@ def parse_checksums(where, files, manifest, hashname): for line in manifest[field].split('\n'): if not line: break - checksum, size, checkfile = line.strip().split(' ') + clist = line.strip().split(' ') + if len(clist) == 3: + checksum, size, checkfile = clist + else: + rejmsg.append("Cannot parse checksum line [%s]" % (line)) + continue if not files.has_key(checkfile): # TODO: check for the file's entry in the original files dict, not # the one modified by (auto)byhand and other weird stuff @@ -437,10 +518,10 @@ def build_file_list(changes, is_a_dsc=0, field="files", hashname="md5sum"): format = format[:2] if is_a_dsc: - # 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): + if format != (1,0) and format != (0,0) and \ + format != (3,0,"quilt") and format != (3,0,"native"): raise UnknownFormatError, "%s" % (changes.get("format","0.0")) else: if (format < (1,5) or format > (1,8)): @@ -691,6 +772,9 @@ def warn(msg): def whoami (): return pwd.getpwuid(os.getuid())[4].split(',')[0].replace('.', '') +def getusername (): + return pwd.getpwuid(os.getuid())[0] + ################################################################################ def size_type (c):