X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=daklib%2Futils.py;h=ea2f8b7fda427e136bf037d5f22d73468bae4814;hb=5e1a34528993b82c0c57f93b16e09cc686af9c82;hp=dc201e3f9a61ff4dcced2658db3f41e570a1c032;hpb=934b2b1d73a2333c80a205f206c1b5edd2f719fb;p=dak.git diff --git a/daklib/utils.py b/daklib/utils.py index dc201e3f..ea2f8b7f 100755 --- a/daklib/utils.py +++ b/daklib/utils.py @@ -45,8 +45,10 @@ 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 ################################################################################ @@ -332,6 +334,90 @@ 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 == None: + dsc = parse_changes(dsc_filename, signing_rules=1); + if dsc_files == 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_native_tar = 0 + has_native_tar_gz = 0 + has_orig_tar = 0 + has_orig_tar_gz = 0 + has_more_orig_tar = 0 + has_debian_tar = 0 + has_debian_diff = 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(format.reject_msgs( + dsc_filename, + has_native_tar, + has_native_tar_gz, + has_debian_tar, + has_debian_diff, + has_orig_tar, + has_orig_tar_gz, + has_more_orig_tar + )) + break + + return rejmsg + +################################################################################ + def check_hash_fields(what, manifest): """ check_hash_fields ensures that there are no checksum fields in the @@ -442,10 +528,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)): @@ -696,6 +782,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):