from gbp.errors import GbpError
from gbp.git import GitRepositoryError
from gbp.deb.changelog import ChangeLog, NoChangeLogError
+from gbp.pkg import (PkgPolicy, compressor_opts, compressor_aliases)
# 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.~+-'
-# 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-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 (~)"""
-
-# compression types, extra options and extensions
-compressor_opts = { 'gzip' : [ '-n', 'gz' ],
- 'bzip2' : [ '', 'bz2' ],
- 'lzma' : [ '', 'lzma' ],
- 'xz' : [ '', 'xz' ] }
-
-# Map frequently used names of compression types to the internal ones:
-compressor_aliases = { 'bz2' : 'bzip2',
- 'gz' : 'gzip', }
+
+class DebianPkgPolicy(PkgPolicy):
+ """Packaging policy for Debian"""
+
+ # 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-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 (~)"""
+
class DpkgCompareVersions(gbpc.Command):
cmd='/usr/bin/dpkg'
compression)
-def is_valid_packagename(name):
- "Is this a valid Debian package name?"
- return packagename_re.match(name)
-
-def is_valid_upstreamversion(version):
- "Is this a valid upstream version number?"
- return upstreamversion_re.match(version)
-
-def get_compression(orig_file):
- """
- Given an orig file return the compression used
-
- >>> get_compression("abc.tar.gz")
- 'gzip'
- >>> get_compression("abc.tar.bz2")
- 'bzip2'
- >>> get_compression("abc.tar.foo")
- >>> get_compression("abc")
- """
- try:
- ext = orig_file.rsplit('.',1)[1]
- except IndexError:
- return None
- for (c, o) in compressor_opts.iteritems():
- if o[1] == ext:
- return c
- return None
-
-
-def has_orig(orig_file, dir):
- "Check if orig tarball exists in dir"
- try:
- os.stat( os.path.join(dir, orig_file) )
- except OSError:
- return False
- return True
-
-def symlink_orig(orig_file, orig_dir, output_dir, force=False):
- """
- symlink orig tarball from orig_dir to output_dir
- @return: True if link was created or src == dst
- False in case of error or src doesn't exist
- """
- orig_dir = os.path.abspath(orig_dir)
- output_dir = os.path.abspath(output_dir)
-
- if orig_dir == output_dir:
- return True
-
- src = os.path.join(orig_dir, orig_file)
- dst = os.path.join(output_dir, orig_file)
- if not os.access(src, os.F_OK):
- return False
- try:
- if os.access(dst, os.F_OK) and force:
- os.unlink(dst)
- os.symlink(src, dst)
- except OSError:
- return False
- return True
-
-
def parse_uscan(out):
"""
Parse the uscan output return (True, tarball) if a new version was
import os, re
import gbp.log
from gbp.command_wrappers import Command
-from gbp.deb import UpstreamSource, compressor_opts
+from gbp.pkg import compressor_opts
+from gbp.deb import UpstreamSource
class PristineTar(Command):
"""The pristine-tar branch in a git repository"""
--- /dev/null
+# vim: set fileencoding=utf-8 :
+#
+# (C) 2006,2007 Guido Guenther <agx@sigxcpu.org>
+# (C) 2012 Intel Corporation <markus.lehtonen@linux.intel.com>
+# 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
+"""Common functionality of the Debian/RPM package helpers"""
+
+import os
+import re
+import glob
+
+import gbp.log
+import gbp.command_wrappers as gbpc
+from gbp.errors import GbpError
+from gbp.command_wrappers import Command
+
+# compression types, extra options and extensions
+compressor_opts = { 'gzip' : [ '-n', 'gz' ],
+ 'bzip2' : [ '', 'bz2' ],
+ 'lzma' : [ '', 'lzma' ],
+ 'xz' : [ '', 'xz' ] }
+
+# Map frequently used names of compression types to the internal ones:
+compressor_aliases = { 'bz2' : 'bzip2',
+ 'gz' : 'gzip', }
+
+class PkgPolicy(object):
+ @classmethod
+ def is_valid_packagename(cls, name):
+ "Is this a valid package name?"
+ return cls.packagename_re.match(name)
+
+ @classmethod
+ def is_valid_upstreamversion(cls, version):
+ "Is this a valid upstream version number?"
+ return cls.upstreamversion_re.match(version)
+
+ @staticmethod
+ def get_compression(orig_file):
+ """
+ Given an orig file return the compression used
+
+ >>> PkgPolicy.get_compression("abc.tar.gz")
+ 'gzip'
+ >>> PkgPolicy.get_compression("abc.tar.bz2")
+ 'bzip2'
+ >>> PkgPolicy.get_compression("abc.tar.foo")
+ >>> PkgPolicy.get_compression("abc")
+ """
+ try:
+ ext = orig_file.rsplit('.',1)[1]
+ except IndexError:
+ return None
+ for (c, o) in compressor_opts.iteritems():
+ if o[1] == ext:
+ return c
+ return None
+
+ @staticmethod
+ def has_orig(orig_file, dir):
+ "Check if orig tarball exists in dir"
+ try:
+ os.stat( os.path.join(dir, orig_file) )
+ except OSError:
+ return False
+ return True
+
+ @staticmethod
+ def symlink_orig(orig_file, orig_dir, output_dir, force=False):
+ """
+ symlink orig tarball from orig_dir to output_dir
+ @return: True if link was created or src == dst
+ False in case of error or src doesn't exist
+ """
+ orig_dir = os.path.abspath(orig_dir)
+ output_dir = os.path.abspath(output_dir)
+
+ if orig_dir == output_dir:
+ return True
+
+ src = os.path.join(orig_dir, orig_file)
+ dst = os.path.join(output_dir, orig_file)
+ if not os.access(src, os.F_OK):
+ return False
+ try:
+ if os.access(dst, os.F_OK) and force:
+ os.unlink(dst)
+ os.symlink(src, dst)
+ except OSError:
+ return False
+ return True
+
git_archive_submodules,
git_archive_single, dump_tree,
write_wc, drop_index)
+from gbp.pkg import (compressor_opts, compressor_aliases)
def git_archive(repo, cp, output_dir, treeish, comp_type, comp_level, with_submodules):
"create a compressed orig tarball in output_dir using git_archive"
try:
- comp_opts = du.compressor_opts[comp_type][0]
+ comp_opts = compressor_opts[comp_type][0]
except KeyError:
raise GbpError, "Unsupported compression type '%s'" % comp_type
# look in tarball_dir first, if found force a symlink to it
if options.tarball_dir:
gbp.log.debug("Looking for orig tarball '%s' at '%s'" % (orig_file, tarball_dir))
- if not du.symlink_orig(orig_file, tarball_dir, output_dir, force=True):
+ if not du.DebianPkgPolicy.symlink_orig(orig_file, tarball_dir, output_dir, force=True):
gbp.log.info("Orig tarball '%s' not found at '%s'" % (orig_file, tarball_dir))
else:
gbp.log.info("Orig tarball '%s' found at '%s'" % (orig_file, tarball_dir))
# build an orig unless the user forbids it, always build (and overwrite pre-existing) if user forces it
- if options.force_create or (not options.no_create_orig and not du.has_orig(orig_file, output_dir)):
+ if options.force_create or (not options.no_create_orig and not du.DebianPkgPolicy.has_orig(orig_file, output_dir)):
if not pristine_tar_build_orig(repo, cp, output_dir, options):
upstream_tree = git_archive_build_orig(repo, cp, output_dir, options)
if options.pristine_tar_commit:
upstream_version = cp['Upstream-Version']
if comp_type != 'auto':
- comp_type = du.compressor_aliases.get(comp_type, comp_type)
+ comp_type = compressor_aliases.get(comp_type, comp_type)
try:
- dummy = du.compressor_opts[comp_type]
+ dummy = compressor_opts[comp_type]
except KeyError:
gbp.log.warn("Unknown compression type - guessing.")
comp_type = 'auto'
if not tarball_dir:
tarball_dir = '..'
detected = None
- for comp in du.compressor_opts.keys():
- if du.has_orig(du.orig_file(cp, comp), tarball_dir):
+ for comp in compressor_opts.keys():
+ if du.DebianPkgPolicy.has_orig(du.orig_file(cp, comp), tarball_dir):
if detected is not None:
raise GbpError, "Multiple orig tarballs found."
detected = comp
else:
commit = repo.pristine_tar_branch
tarball = repo.get_subject(commit)
- comp_type = du.get_compression(tarball)
+ comp_type = du.DebianPkgPolicy.get_compression(tarball)
gbp.log.debug("Determined compression type '%s'" % comp_type)
if not comp_type:
comp_type = 'gzip'
import re
import tempfile
import gbp.command_wrappers as gbpc
-from gbp.deb import (do_uscan, parse_changelog_repo,
- is_valid_packagename, packagename_msg,
- is_valid_upstreamversion, upstreamversion_msg)
+from gbp.deb import (DebianPkgPolicy, do_uscan, parse_changelog_repo)
from gbp.deb.changelog import ChangeLog, NoChangeLogError
from gbp.deb.git import (GitRepositoryError, DebianGitRepository)
from gbp.config import GbpOptionParserDebian, GbpOptionGroup, no_upstream_branch_msg
except NoChangeLogError:
if options.interactive:
sourcepackage = ask_package_name(guessed_package,
- is_valid_packagename,
- packagename_msg)
+ DebianPkgPolicy.is_valid_packagename,
+ DebianPkgPolicy.packagename_msg)
else:
if guessed_package:
sourcepackage = guessed_package
else:
if options.interactive:
version = ask_package_version(guessed_version,
- is_valid_upstreamversion,
- upstreamversion_msg)
+ DebianPkgPolicy.is_valid_upstreamversion,
+ DebianPkgPolicy.upstreamversion_msg)
else:
if guessed_version:
version = guessed_version
import unittest
from gbp.scripts import buildpackage
-from gbp.deb import (has_orig, orig_file)
+from gbp.deb import (DebianPkgPolicy, orig_file)
from gbp.errors import GbpError
class MockGitRepository:
self.assertEqual("bzip2", guessed)
def test_has_orig_false(self):
- self.assertFalse(has_orig(orig_file(self.cp, 'gzip'), self.tmpdir))
+ self.assertFalse(DebianPkgPolicy.has_orig(orig_file(self.cp, 'gzip'), self.tmpdir))
def test_has_orig_true(self):
open(os.path.join(self.tmpdir, 'source_1.2.orig.tar.gz'), "w").close()
- self.assertTrue(has_orig(orig_file(self.cp, 'gzip'), self.tmpdir))
+ self.assertTrue(DebianPkgPolicy.has_orig(orig_file(self.cp, 'gzip'), self.tmpdir))
def test_guess_comp_type_bzip2(self):
repo = MockGitRepository(with_branch=False)