3 """ Helper functions for the various changes 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 # <mhy> !!!!11111iiiiiioneoneoneone
28 # <dak> mhy: Error: "!!!11111iiiiiioneoneoneone" is not a valid command.
29 # <mhy> dak: oh shut up
30 # <dak> mhy: Error: "oh" is not a valid command.
32 ################################################################################
34 from regexes import re_verwithext
35 from dak_exceptions import UnknownFormatError
37 def parse_format(txt):
39 Parse a .changes Format string into a tuple representation for easy
42 >>> parse_format('1.0')
44 >>> parse_format('8.4 (hardy)')
47 If the format doesn't match these forms, raises UnknownFormatError.
50 @param txt: Format string to parse
53 @return: Parsed format
55 @raise UnknownFormatError: Unknown Format: line
58 format = re_verwithext.search(txt)
61 raise UnknownFormatError(txt)
63 format = format.groups()
66 format = int(float(format[0])), 0, format[2]
68 format = int(format[0]), int(format[1]), format[2]
75 def validate_changes_format(format, field):
77 Validate a tuple-representation of a .changes Format: field. Raises
78 UnknownFormatError if the field is invalid, otherwise return type is
82 if (format < (1, 5) or format > (1, 8)):
83 raise UnknownFormatError(repr(format))
85 if field != 'files' and format < (1, 8):
86 raise UnknownFormatError(repr(format))