Package daklib :: Module srcformats
[hide private]
[frames] | no frames]

Source Code for Module daklib.srcformats

  1  """ Helper functions for the various source formats 
  2   
  3  @contact: Debian FTPMaster <ftpmaster@debian.org> 
  4  @copyright: 2009, 2010  Joerg Jaspert <joerg@debian.org> 
  5  @copyright: 2009  Chris Lamb <lamby@debian.org> 
  6  @license: GNU General Public License version 2 or later 
  7  """ 
  8   
  9  # This program is free software; you can redistribute it and/or modify 
 10  # it under the terms of the GNU General Public License as published by 
 11  # the Free Software Foundation; either version 2 of the License, or 
 12  # (at your option) any later version. 
 13   
 14  # This program is distributed in the hope that it will be useful, 
 15  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 16  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 17  # GNU General Public License for more details. 
 18   
 19  # You should have received a copy of the GNU General Public License 
 20  # along with this program; if not, write to the Free Software 
 21  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 22   
 23  ################################################################################ 
 24   
 25  # <sgran> hey, I think something's wrong with your git repo 
 26  # <sgran> when I git pulled this last time, I got something that looked almost 
 27  #         like python instead of dak 
 28  # <mhy> sgran: slander 
 29  # <sgran> sorry, I take it back, I've had a better look now 
 30   
 31  ################################################################################ 
 32   
 33  import re 
 34   
 35  from .dak_exceptions import UnknownFormatError 
 36   
 37  srcformats = [] 
38 39 40 -def get_format_from_string(txt):
41 """ 42 Returns the SourceFormat class that corresponds to the specified .changes 43 Format value. If the string does not match any class, UnknownFormatError 44 is raised. 45 """ 46 47 for format in srcformats: 48 if format.re_format.match(txt): 49 return format 50 51 raise UnknownFormatError("Unknown format %r" % txt)
52
53 54 -class SourceFormat(type):
55 - def __new__(cls, name, bases, attrs):
56 klass = super(SourceFormat, cls).__new__(cls, name, bases, attrs) 57 srcformats.append(klass) 58 59 assert str(klass.name) 60 assert iter(klass.requires) 61 assert iter(klass.disallowed) 62 63 klass.re_format = re.compile(klass.format) 64 65 return klass
66 67 @classmethod
68 - def reject_msgs(cls, has):
69 if len(cls.requires) != len([x for x in cls.requires if has[x]]): 70 yield "lack of required files for format %s" % cls.name 71 72 for key in cls.disallowed: 73 if has[key]: 74 yield "contains source files not allowed in format %s" % cls.name
75
76 77 -class FormatOne(SourceFormat, metaclass=SourceFormat):
78 name = '1.0' 79 format = r'1\.0' 80 81 requires = () 82 disallowed = ('debian_tar', 'more_orig_tar') 83 84 @classmethod
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 93 94 for msg in super(FormatOne, cls).reject_msgs(has): 95 yield msg
96
97 98 -class FormatThree(SourceFormat, metaclass=SourceFormat):
99 name = '3.x (native)' 100 format = r'3\.\d+ \(native\)' 101 102 requires = ('native_tar',) 103 disallowed = ('orig_tar', 'debian_diff', 'debian_tar', 'more_orig_tar')
104
105 106 -class FormatThreeQuilt(SourceFormat, metaclass=SourceFormat):
107 name = '3.x (quilt)' 108 format = r'3\.\d+ \(quilt\)' 109 110 requires = ('orig_tar', 'debian_tar') 111 disallowed = ('debian_diff', 'native_tar')
112