3 """ Helper functions for the various source formats
5 @contact: Debian FTPMaster <ftpmaster@debian.org>
6 @copyright: 2009, 2010 Joerg Jaspert <joerg@debian.org>
7 @copyright: 2009 Chris Lamb <lamby@debian.org>
8 @license: GNU General Public License version 2 or later
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 ################################################################################
27 # <sgran> hey, I think something's wrong with your git repo
28 # <sgran> when I git pulled this last time, I got something that looked almost
29 # like python instead of dak
30 # <mhy> sgran: slander
31 # <sgran> sorry, I take it back, I've had a better look now
33 ################################################################################
36 from dak_exceptions import UnknownFormatError
40 def get_format_from_string(txt):
42 Returns the SourceFormat class that corresponds to the specified .changes
43 Format value. If the string does not match any class, UnknownFormatError
47 for format in srcformats:
48 if format.re_format.match(txt):
51 raise UnknownFormatError("Unknown format %r" % txt)
53 class SourceFormat(type):
54 def __new__(cls, name, bases, attrs):
55 klass = super(SourceFormat, cls).__new__(cls, name, bases, attrs)
56 srcformats.append(klass)
58 assert str(klass.name)
59 assert iter(klass.requires)
60 assert iter(klass.disallowed)
62 klass.re_format = re.compile(klass.format)
67 def reject_msgs(cls, has):
68 if len(cls.requires) != len([x for x in cls.requires if has[x]]):
69 yield "lack of required files for format %s" % cls.name
71 for key in cls.disallowed:
73 yield "contains source files not allowed in format %s" % cls.name
75 class FormatOne(SourceFormat):
76 __metaclass__ = SourceFormat
82 disallowed = ('debian_tar', 'more_orig_tar')
85 def reject_msgs(cls, has):
86 if not (has['native_tar_gz'] or (has['orig_tar_gz'] and has['debian_diff'])):
87 yield "no .tar.gz or .orig.tar.gz+.diff.gz in 'Files' field."
88 if has['native_tar_gz'] and has['debian_diff']:
89 yield "native package with diff makes no sense"
90 if (has['orig_tar_gz'] != has['orig_tar']) or \
91 (has['native_tar_gz'] != has['native_tar']):
92 yield "contains source files not allowed in format %s" % cls.name
94 for msg in super(FormatOne, cls).reject_msgs(has):
97 class FormatThree(SourceFormat):
98 __metaclass__ = SourceFormat
100 name = '3.x (native)'
101 format = r'3\.\d+ \(native\)'
103 requires = ('native_tar',)
104 disallowed = ('orig_tar', 'debian_diff', 'debian_tar', 'more_orig_tar')
106 class FormatThreeQuilt(SourceFormat):
107 __metaclass__ = SourceFormat
110 format = r'3\.\d+ \(quilt\)'
112 requires = ('orig_tar', 'debian_tar')
113 disallowed = ('debian_diff', 'native_tar')