3 from regexes import re_verwithext
4 from dak_exceptions import UnknownFormatError
10 Parse a .changes Format string into a tuple representation for easy
13 >>> parse_format('1.0')
15 >>> parse_format('8.4 (hardy)')
18 If the format doesn't match these forms, raises UnknownFormatError.
21 format = re_verwithext.search(txt)
24 raise UnknownFormatError, txt
26 format = format.groups()
29 format = int(float(format[0])), 0, format[2]
31 format = int(format[0]), int(format[1]), format[2]
38 class SourceFormat(type):
39 def __new__(cls, name, bases, attrs):
40 klass = super(SourceFormat, cls).__new__(cls, name, bases, attrs)
41 srcformats.append(klass)
43 assert str(klass.name)
44 assert iter(klass.requires)
45 assert iter(klass.disallowed)
47 klass.re_format = re.compile(klass.format)
52 def reject_msgs(cls, has):
53 if len(cls.requires) != len([x for x in cls.requires if has[x]]):
54 yield "lack of required files for format %s" % cls.name
56 for key in cls.disallowed:
58 yield "contains source files not allowed in format %s" % cls.name
61 def validate_format(cls, format, is_a_dsc=False, field='files'):
63 Raises UnknownFormatError if the specified format tuple is not valid for
64 this format (for example, the format (1, 0) is not valid for the
65 "3.0 (quilt)" format). Return value is undefined in all other cases.
69 class FormatOne(SourceFormat):
70 __metaclass__ = SourceFormat
76 disallowed = ('debian_tar', 'more_orig_tar')
79 def reject_msgs(cls, has):
80 if not (has['native_tar_gz'] or (has['orig_tar_gz'] and has['debian_diff'])):
81 yield "no .tar.gz or .orig.tar.gz+.diff.gz in 'Files' field."
82 if has['native_tar_gz'] and has['debian_diff']:
83 yield "native package with diff makes no sense"
84 if (has['orig_tar_gz'] != has['orig_tar']) or \
85 (has['native_tar_gz'] != has['native_tar']):
86 yield "contains source files not allowed in format %s" % cls.name
88 for msg in super(FormatOne, cls).reject_msgs(has):
92 def validate_format(cls, format, is_a_dsc=False, field='files'):
93 msg = "Invalid format %s definition: %r" % (cls.name, format)
97 raise UnknownFormatError, msg
99 if (format < (1,5) or format > (1,8)):
100 raise UnknownFormatError, msg
101 if field != "files" and format < (1,8):
102 raise UnknownFormatError, msg
104 class FormatThree(SourceFormat):
105 __metaclass__ = SourceFormat
107 name = '3.x (native)'
108 format = r'3\.\d+ \(native\)'
110 requires = ('native_tar',)
111 disallowed = ('orig_tar', 'debian_diff', 'debian_tar', 'more_orig_tar')
114 def validate_format(cls, format, **kwargs):
115 if format != (3, 0, 'native'):
116 raise UnknownFormatError, "Invalid format %s definition: %r" % \
119 class FormatThreeQuilt(SourceFormat):
120 __metaclass__ = SourceFormat
123 format = r'3\.\d+ \(quilt\)'
125 requires = ('orig_tar', 'debian_tar')
126 disallowed = ('debian_diff', 'native_tar')
129 def validate_format(cls, format, **kwargs):
130 if format != (3, 0, 'quilt'):
131 raise UnknownFormatError, "Invalid format %s definition: %r" % \