diff options
author | Guido Günther <agx@sigxcpu.org> | 2013-03-29 15:24:02 +0100 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2013-03-29 15:36:26 +0100 |
commit | 62d3b9989919664fa81a317d8af320671a94803f (patch) | |
tree | 173799376b25d4f8de3e532453e93a9e0facdcf6 /gbp/deb | |
parent | a9bf9cfd4b31076c54d4e377c1b31b5bd69f8661 (diff) | |
download | git-buildpackage-62d3b9989919664fa81a317d8af320671a94803f.tar.gz git-buildpackage-62d3b9989919664fa81a317d8af320671a94803f.tar.bz2 git-buildpackage-62d3b9989919664fa81a317d8af320671a94803f.zip |
Move DebianPkgPolicy to separate module
Diffstat (limited to 'gbp/deb')
-rw-r--r-- | gbp/deb/__init__.py | 67 | ||||
-rw-r--r-- | gbp/deb/policy.py | 83 |
2 files changed, 87 insertions, 63 deletions
diff --git a/gbp/deb/__init__.py b/gbp/deb/__init__.py index 4aadad37..3f0bfc38 100644 --- a/gbp/deb/__init__.py +++ b/gbp/deb/__init__.py @@ -23,75 +23,16 @@ import subprocess import gbp.command_wrappers as gbpc from gbp.errors import GbpError from gbp.git import GitRepositoryError +from gbp.pkg import UpstreamSource + +# Make sure these are available with 'import gbp.deb' from gbp.deb.changelog import ChangeLog, NoChangeLogError -from gbp.pkg import (PkgPolicy, UpstreamSource, compressor_opts) +from gbp.deb.policy import DebianPkgPolicy # When trying to parse a version-number from a dsc or changes file, these are # the valid characters. debian_version_chars = 'a-zA-Z\d.~+-' - -class DebianPkgPolicy(PkgPolicy): - """ - Packaging policy for Debian Source Packages - - >>> DebianPkgPolicy.is_valid_upstreamversion('1:9.8.4.dfsg.P1-6') - True - >>> DebianPkgPolicy.is_valid_upstreamversion('-1') - False - """ - - # Valid package names according to Debian Policy Manual 5.6.1: - # "Package names (both source and binary, see Package, Section 5.6.7) - # must consist only of lower case letters (a-z), digits (0-9), plus (+) - # and minus (-) signs, and periods (.). They must be at least two - # characters long and must start with an alphanumeric character." - packagename_re = re.compile("^[a-zA-Z0-9][a-zA-Z0-9\.\+\-~]+$") - packagename_msg = """Package names must be at least two characters long, start with an - alphanumeric and can only containg letters (a-z,A-Z), digits - (0-9), plus signs (+), minus signs (-), periods (.) and hyphens (~)""" - - # Valid upstream versions according to Debian Policy Manual 5.6.12: - # "The upstream_version may contain only alphanumerics[32] and the - # characters . + - : ~ (full stop, plus, hyphen, colon, tilde) and - # should start with a digit. If there is no debian_revision then hyphens - # are not allowed; if there is no epoch then colons are not allowed." - # Since we don't know about any epochs and debian revisions yet, the - # last two conditions are not checked. - upstreamversion_re = re.compile("^[0-9][a-zA-Z0-9\.\+\-\:\~]*$") - upstreamversion_msg = """Upstream version numbers must start with a digit and can only containg lower case - letters (a-z), digits (0-9), full stops (.), plus signs (+), minus signs - (-), colons (:) and tildes (~)""" - - @staticmethod - def build_tarball_name(name, version, compression, dir=None): - """ - Given a source package's I{name}, I{version} and I{compression} - return the name of the corresponding upstream tarball. - - >>> DebianPkgPolicy.build_tarball_name('foo', '1.0', 'bzip2') - 'foo_1.0.orig.tar.bz2' - >>> DebianPkgPolicy.build_tarball_name('bar', '0.0~git1234', 'xz') - 'bar_0.0~git1234.orig.tar.xz' - - @param name: the source package's name - @type name: C{str} - @param version: the upstream version - @type version: C{str} - @param compression: the desired compression - @type compression: C{str} - @param dir: a directory to prepend - @type dir: C{str} - @return: the tarballs name corresponding to the input parameters - @rtype: C{str} - """ - ext = compressor_opts[compression][1] - tarball = "%s_%s.orig.tar.%s" % (name, version, ext) - if dir: - tarball = os.path.join(dir, tarball) - return tarball - - class DpkgCompareVersions(gbpc.Command): cmd='/usr/bin/dpkg' diff --git a/gbp/deb/policy.py b/gbp/deb/policy.py new file mode 100644 index 00000000..9c1b018e --- /dev/null +++ b/gbp/deb/policy.py @@ -0,0 +1,83 @@ +# vim: set fileencoding=utf-8 : +# +# (C) 2006,2007,2011 Guido Günther <agx@sigxcpu.org> +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +"""provides some debian source package related helpers""" + +import os +import re + +from gbp.pkg import (PkgPolicy, compressor_opts) + + +class DebianPkgPolicy(PkgPolicy): + """ + Packaging policy for Debian Source Packages + + >>> DebianPkgPolicy.is_valid_upstreamversion('1:9.8.4.dfsg.P1-6') + True + >>> DebianPkgPolicy.is_valid_upstreamversion('-1') + False + """ + + # Valid package names according to Debian Policy Manual 5.6.1: + # "Package names (both source and binary, see Package, Section 5.6.7) + # must consist only of lower case letters (a-z), digits (0-9), plus (+) + # and minus (-) signs, and periods (.). They must be at least two + # characters long and must start with an alphanumeric character." + packagename_re = re.compile("^[a-zA-Z0-9][a-zA-Z0-9\.\+\-~]+$") + packagename_msg = """Package names must be at least two characters long, start with an + alphanumeric and can only containg letters (a-z,A-Z), digits + (0-9), plus signs (+), minus signs (-), periods (.) and hyphens (~)""" + + # Valid upstream versions according to Debian Policy Manual 5.6.12: + # "The upstream_version may contain only alphanumerics[32] and the + # characters . + - : ~ (full stop, plus, hyphen, colon, tilde) and + # should start with a digit. If there is no debian_revision then hyphens + # are not allowed; if there is no epoch then colons are not allowed." + # Since we don't know about any epochs and debian revisions yet, the + # last two conditions are not checked. + upstreamversion_re = re.compile("^[0-9][a-zA-Z0-9\.\+\-\:\~]*$") + upstreamversion_msg = """Upstream version numbers must start with a digit and can only containg lower case + letters (a-z), digits (0-9), full stops (.), plus signs (+), minus signs + (-), colons (:) and tildes (~)""" + + @staticmethod + def build_tarball_name(name, version, compression, dir=None): + """ + Given a source package's I{name}, I{version} and I{compression} + return the name of the corresponding upstream tarball. + + >>> DebianPkgPolicy.build_tarball_name('foo', '1.0', 'bzip2') + 'foo_1.0.orig.tar.bz2' + >>> DebianPkgPolicy.build_tarball_name('bar', '0.0~git1234', 'xz') + 'bar_0.0~git1234.orig.tar.xz' + + @param name: the source package's name + @type name: C{str} + @param version: the upstream version + @type version: C{str} + @param compression: the desired compression + @type compression: C{str} + @param dir: a directory to prepend + @type dir: C{str} + @return: the tarballs name corresponding to the input parameters + @rtype: C{str} + """ + ext = compressor_opts[compression][1] + tarball = "%s_%s.orig.tar.%s" % (name, version, ext) + if dir: + tarball = os.path.join(dir, tarball) + return tarball |