3 from dak_exceptions import UnknownFormatError
7 def get_format_from_string(txt):
9 Returns the SourceFormat class that corresponds to the specified .changes
10 Format value. If the string does not match any class, UnknownFormatError
14 for format in srcformats:
15 if format.re_format.match(txt):
18 raise UnknownFormatError, "Unknown format %r" % txt
20 class SourceFormat(type):
21 def __new__(cls, name, bases, attrs):
22 klass = super(SourceFormat, cls).__new__(cls, name, bases, attrs)
23 srcformats.append(klass)
25 assert str(klass.name)
26 assert iter(klass.requires)
27 assert iter(klass.disallowed)
29 klass.re_format = re.compile(klass.format)
34 def reject_msgs(cls, has):
35 if len(cls.requires) != len([x for x in cls.requires if has[x]]):
36 yield "lack of required files for format %s" % cls.name
38 for key in cls.disallowed:
40 yield "contains source files not allowed in format %s" % cls.name
42 class FormatOne(SourceFormat):
43 __metaclass__ = SourceFormat
49 disallowed = ('debian_tar', 'more_orig_tar')
52 def reject_msgs(cls, has):
53 if not (has['native_tar_gz'] or (has['orig_tar_gz'] and has['debian_diff'])):
54 yield "no .tar.gz or .orig.tar.gz+.diff.gz in 'Files' field."
55 if has['native_tar_gz'] and has['debian_diff']:
56 yield "native package with diff makes no sense"
57 if (has['orig_tar_gz'] != has['orig_tar']) or \
58 (has['native_tar_gz'] != has['native_tar']):
59 yield "contains source files not allowed in format %s" % cls.name
61 for msg in super(FormatOne, cls).reject_msgs(has):
64 class FormatThree(SourceFormat):
65 __metaclass__ = SourceFormat
68 format = r'3\.\d+ \(native\)'
70 requires = ('native_tar',)
71 disallowed = ('orig_tar', 'debian_diff', 'debian_tar', 'more_orig_tar')
73 class FormatThreeQuilt(SourceFormat):
74 __metaclass__ = SourceFormat
77 format = r'3\.\d+ \(quilt\)'
79 requires = ('orig_tar', 'debian_tar')
80 disallowed = ('debian_diff', 'native_tar')