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):
32 format = re_verwithext.search(txt)
35 raise UnknownFormatError, txt
37 format = format.groups()
40 format = int(float(format[0])), 0, format[2]
42 format = int(format[0]), int(format[1]), format[2]
50 def validate_format(cls, format, is_a_dsc=False, field='files'):
52 if format != (1,0) and \
53 format != (3,0,"quilt") and format != (3,0,"native"):
54 raise UnknownFormatError, repr(format)
56 if (format < (1,5) or format > (1,8)):
57 raise UnknownFormatError, repr(format)
58 if field != "files" and format < (1,8):
59 raise UnknownFormatError, repr(format)
61 class FormatOne(SourceFormat):
62 __metaclass__ = SourceFormat
68 disallowed = ('debian_tar', 'more_orig_tar')
71 def reject_msgs(cls, has):
72 if not (has['native_tar_gz'] or (has['orig_tar_gz'] and has['debian_diff'])):
73 yield "no .tar.gz or .orig.tar.gz+.diff.gz in 'Files' field."
74 if has['native_tar_gz'] and has['debian_diff']:
75 yield "native package with diff makes no sense"
76 if (has['orig_tar_gz'] != has['orig_tar']) or \
77 (has['native_tar_gz'] != has['native_tar']):
78 yield "contains source files not allowed in format %s" % cls.name
80 for msg in super(FormatOne, cls).reject_msgs(has):
83 class FormatThree(SourceFormat):
84 __metaclass__ = SourceFormat
87 format = r'3\.\d+ \(native\)'
89 requires = ('native_tar',)
90 disallowed = ('orig_tar', 'debian_diff', 'debian_tar', 'more_orig_tar')
92 class FormatThreeQuilt(SourceFormat):
93 __metaclass__ = SourceFormat
96 format = r'3\.\d+ \(quilt\)'
98 requires = ('orig_tar', 'debian_tar')
99 disallowed = ('debian_diff', 'native_tar')