3 from regexes import re_verwithext
4 from dak_exceptions import UnknownFormatError
8 class SourceFormat(type):
9 def __new__(cls, name, bases, attrs):
10 klass = super(SourceFormat, cls).__new__(cls, name, bases, attrs)
11 srcformats.append(klass)
13 assert str(klass.name)
14 assert iter(klass.requires)
15 assert iter(klass.disallowed)
17 klass.re_format = re.compile(klass.format)
22 def reject_msgs(cls, has):
23 if len(cls.requires) != len([x for x in cls.requires if has[x]]):
24 yield "lack of required files for format %s" % cls.name
26 for key in cls.disallowed:
28 yield "contains source files not allowed in format %s" % cls.name
31 def parse_format(cls, txt, is_a_dsc=False, field='files'):
32 format = re_verwithext.search(txt)
34 raise UnknownFormatError, txt
36 format = format.groups()
38 format = int(float(format[0])), 0, format[2]
40 format = int(format[0]), int(format[1]), format[2]
45 # format = (0,0) are missing format headers of which we still
46 # have some in the archive.
47 if format != (1,0) and format != (0,0) and \
48 format != (3,0,"quilt") and format != (3,0,"native"):
49 raise UnknownFormatError, txt
51 if (format < (1,5) or format > (1,8)):
52 raise UnknownFormatError, txt
53 if field != "files" and format < (1,8):
54 raise UnknownFormatError, txt
58 class FormatOne(SourceFormat):
59 __metaclass__ = SourceFormat
65 disallowed = ('debian_tar', 'more_orig_tar')
68 def reject_msgs(cls, has):
69 if not (has['native_tar_gz'] or (has['orig_tar_gz'] and has['debian_diff'])):
70 yield "no .tar.gz or .orig.tar.gz+.diff.gz in 'Files' field."
71 if has['native_tar_gz'] and has['debian_diff']:
72 yield "native package with diff makes no sense"
73 if (has['orig_tar_gz'] != has['orig_tar']) or \
74 (has['native_tar_gz'] != has['native_tar']):
75 yield "contains source files not allowed in format %s" % cls.name
77 for msg in super(FormatOne, cls).reject_msgs(has):
80 class FormatThree(SourceFormat):
81 __metaclass__ = SourceFormat
84 format = r'3\.\d+ \(native\)'
86 requires = ('native_tar',)
87 disallowed = ('orig_tar', 'debian_diff', 'debian_tar', 'more_orig_tar')
89 class FormatThreeQuilt(SourceFormat):
90 __metaclass__ = SourceFormat
93 format = r'3\.\d+ \(quilt\)'
95 requires = ('orig_tar', 'debian_tar')
96 disallowed = ('debian_diff', 'native_tar')