1 # vim: set fileencoding=utf-8 :
3 # (C) 2006,2007,2011 Guido Günther <agx@sigxcpu.org>
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, please see
16 # <http://www.gnu.org/licenses/>
18 Debian Packaging policies
20 like allowed characters in version numbers, etc.
26 from gbp.errors import GbpError
27 from gbp.pkg.pkgpolicy import PkgPolicy
28 from gbp.pkg.compressor import Compressor
31 class DebianPkgPolicy(PkgPolicy):
33 Packaging policy for Debian Source Packages
35 >>> DebianPkgPolicy.is_valid_upstreamversion('1:9.8.4.dfsg.P1-6')
37 >>> DebianPkgPolicy.is_valid_upstreamversion('-1')
41 # Valid package names according to Debian Policy Manual 5.6.1:
42 # "Package names (both source and binary, see Package, Section 5.6.7)
43 # must consist only of lower case letters (a-z), digits (0-9), plus (+)
44 # and minus (-) signs, and periods (.). They must be at least two
45 # characters long and must start with an alphanumeric character."
46 packagename_re = re.compile(r"^[a-zA-Z0-9][a-zA-Z0-9\.\+\-~]+$")
47 packagename_msg = """Package names must be at least two characters long, start with an
48 alphanumeric and can only containg letters (a-z,A-Z), digits
49 (0-9), plus signs (+), minus signs (-), periods (.) and hyphens (~)"""
51 # Valid upstream versions according to Debian Policy Manual 5.6.12:
52 # "The upstream_version may contain only alphanumerics[32] and the
53 # characters . + - : ~ (full stop, plus, hyphen, colon, tilde) and
54 # should start with a digit. If there is no debian_revision then hyphens
55 # are not allowed; if there is no epoch then colons are not allowed."
56 # Since we don't know about any epochs and debian revisions yet, the
57 # last two conditions are not checked.
58 upstreamversion_re = re.compile(r"^[0-9][a-zA-Z0-9\.\+\-\:\~]*$")
59 upstreamversion_msg = """Upstream version numbers must start with a digit and can only containg lower case
60 letters (a-z), digits (0-9), full stops (.), plus signs (+), minus signs
61 (-), colons (:) and tildes (~)"""
63 # Valid characters in a debian version
64 debianversion_chars = 'a-zA-Z\\d.~+-'
67 def build_tarball_name(name, version, compression, dir=None, component=None):
69 Given a source package's I{name}, I{version} and I{compression}
70 return the name of the corresponding upstream tarball.
72 >>> DebianPkgPolicy.build_tarball_name('foo', '1.0', 'bzip2')
73 'foo_1.0.orig.tar.bz2'
74 >>> DebianPkgPolicy.build_tarball_name('bar', '0.0~git1234', 'xz')
75 'bar_0.0~git1234.orig.tar.xz'
76 >>> DebianPkgPolicy.build_tarball_name('bar', '0.0~git1234', 'xz', component="foo")
77 'bar_0.0~git1234.orig-foo.tar.xz'
79 @param name: the source package's name
81 @param version: the upstream version
83 @param compression: the desired compression
84 @type compression: C{str}
85 @param dir: a directory to prepend
87 @return: the tarballs name corresponding to the input parameters
91 ext = Compressor.Exts[compression]
93 raise GbpError("Unknown compression type '%s'" % compression)
94 sub = '-{0}'.format(component) if component else ''
95 tarball = "%s_%s.orig%s.tar.%s" % (name, version, sub, ext)
97 tarball = os.path.join(dir, tarball)