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)
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]
48 if format != (1,0) and \
49 format != (3,0,"quilt") and format != (3,0,"native"):
50 raise UnknownFormatError, txt
52 if (format < (1,5) or format > (1,8)):
53 raise UnknownFormatError, txt
54 if field != "files" and format < (1,8):
55 raise UnknownFormatError, txt
59 class FormatOne(SourceFormat):
60 __metaclass__ = SourceFormat
66 disallowed = ('debian_tar', 'more_orig_tar')
69 def reject_msgs(cls, has):
70 if not (has['native_tar_gz'] or (has['orig_tar_gz'] and has['debian_diff'])):
71 yield "no .tar.gz or .orig.tar.gz+.diff.gz in 'Files' field."
72 if has['native_tar_gz'] and has['debian_diff']:
73 yield "native package with diff makes no sense"
74 if (has['orig_tar_gz'] != has['orig_tar']) or \
75 (has['native_tar_gz'] != has['native_tar']):
76 yield "contains source files not allowed in format %s" % cls.name
78 for msg in super(FormatOne, cls).reject_msgs(has):
81 class FormatThree(SourceFormat):
82 __metaclass__ = SourceFormat
85 format = r'3\.\d+ \(native\)'
87 requires = ('native_tar',)
88 disallowed = ('orig_tar', 'debian_diff', 'debian_tar', 'more_orig_tar')
90 class FormatThreeQuilt(SourceFormat):
91 __metaclass__ = SourceFormat
94 format = r'3\.\d+ \(quilt\)'
96 requires = ('orig_tar', 'debian_tar')
97 disallowed = ('debian_diff', 'native_tar')