aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2012-05-25 10:35:06 +0200
committerGuido Günther <agx@sigxcpu.org>2012-05-25 10:45:13 +0200
commita116edd739e9ff529058a2d9df6fe67bdb17670d (patch)
tree9815dfdfa489c4ad9e1cc5bd0b87712759b82bd0
parenta5f0d875d7779b2001fda0f436a4710dfa9a5d77 (diff)
Refactor deb helpers: move PristineTar class
Based on a patch by Markus Lehtonen This refactor is preparation to the upcoming rpm support.
-rw-r--r--gbp/deb/git.py6
-rw-r--r--gbp/deb/pristinetar.py100
-rw-r--r--gbp/pkg/pristinetar.py115
-rw-r--r--tests/test_PristineTar.py12
4 files changed, 128 insertions, 105 deletions
diff --git a/gbp/deb/git.py b/gbp/deb/git.py
index 3f99805..7e13b5e 100644
--- a/gbp/deb/git.py
+++ b/gbp/deb/git.py
@@ -18,14 +18,14 @@
import re
from gbp.git import GitRepository, GitRepositoryError
-from gbp.deb.pristinetar import PristineTar
+from gbp.deb.pristinetar import DebianPristineTar
class DebianGitRepository(GitRepository):
"""A git repository that holds the source of a Debian package"""
def __init__(self, path):
super(DebianGitRepository, self).__init__(path)
- self.pristine_tar = PristineTar(self)
+ self.pristine_tar = DebianPristineTar(self)
def find_version(self, format, version):
"""
@@ -123,7 +123,7 @@ class DebianGitRepository(GitRepository):
The name of the pristine-tar branch, whether it already exists or
not.
"""
- return PristineTar.branch
+ return DebianPristineTar.branch
def has_pristine_tar_branch(self):
"""
diff --git a/gbp/deb/pristinetar.py b/gbp/deb/pristinetar.py
index a2f191f..d7ce75b 100644
--- a/gbp/deb/pristinetar.py
+++ b/gbp/deb/pristinetar.py
@@ -16,100 +16,8 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""Handle checkin and checkout of archives from the pristine-tar branch"""
-import os, re
-import gbp.log
-from gbp.command_wrappers import Command
-from gbp.pkg import compressor_opts
-from gbp.deb import DebianPkgPolicy
-
-class PristineTar(Command):
- """The pristine-tar branch in a git repository"""
- cmd='/usr/bin/pristine-tar'
- branch = 'pristine-tar'
-
- def __init__(self, repo):
- self.repo = repo
- super(PristineTar, self).__init__(self.cmd, cwd=repo.path)
-
- def has_commit(self, package, version, comp_type=None):
- """
- Do we have a pristine-tar commit for package I{package} at version
- {version} with compression type I{comp_type}?
-
- @param package: the package to look for
- @type package: C{str}
- @param version: the upstream version to look for
- @type version: C{str}
- @param comp_type: the compression type
- @type comp_type: C{str}
- """
- return True if self.get_commit(package, version, comp_type) else False
-
- def get_commit(self, package, version, comp_type=None):
- """
- Get the pristine-tar commit of package I{package} in version I{version}
- and compression type I{comp_type}
-
- @param package: the package to look for
- @type package: C{str}
- @param version: the version to look for
- @param comp_type: the compression type
- @type comp_type: C{str}
- """
- if not self.repo.has_pristine_tar_branch():
- return None
-
- if not comp_type:
- ext = '\w\+'
- else:
- ext = compressor_opts[comp_type][1]
-
- regex = ('pristine-tar .* %s_%s\.orig\.tar\.%s' %
- (package, version, ext))
- commits = self.repo.grep_log(regex, self.branch)
- if commits:
- commit = commits[-1]
- gbp.log.debug("Found pristine-tar commit at '%s'" % commit)
- return commit
- return None
-
- def _checkout(self, archive):
- self.run_error = 'Couldn\'t checkout "%s"' % os.path.basename(archive)
- self.__call__(['checkout', archive])
-
- def checkout(self, package, version, comp_type, output_dir):
- """
- Checkout the orig tarball for package I{package} of I{version} and
- compression type I{comp_type} to I{output_dir}
-
- @param package: the package to generate the orig tarball for
- @type package: C{str}
- @param version: the version to check generate the orig tarball for
- @type version: C{str}
- @param comp_type: the compression type of the tarball
- @type comp_type: C{str}
- @param output_dir: the directory to put the tarball into
- @type output_dir: C{str}
- """
- name = DebianPkgPolicy.build_tarball_name(package,
- version,
- comp_type,
- output_dir)
- self._checkout(name)
-
- def commit(self, archive, upstream):
- """
- Commit an archive I{archive} to the pristine tar branch using upstream
- branch ${upstream}.
-
- @param archive: the archive to commit
- @type archive: C{str}
- @param upstream: the upstream branch to diff against
- @type upstream: C{str}
- """
- ref = 'refs/heads/%s' % upstream
-
- self.run_error = ("Couldn't commit to '%s' with upstream '%s'" %
- (self.branch, upstream))
- self.__call__(['commit', archive, upstream])
+from gbp.pkg.pristinetar import PristineTar
+class DebianPristineTar(PristineTar):
+ """The pristine-tar branch in a Debian git repository"""
+ pass
diff --git a/gbp/pkg/pristinetar.py b/gbp/pkg/pristinetar.py
new file mode 100644
index 0000000..a2f191f
--- /dev/null
+++ b/gbp/pkg/pristinetar.py
@@ -0,0 +1,115 @@
+# vim: set fileencoding=utf-8 :
+#
+# (C) 2012 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
+"""Handle checkin and checkout of archives from the pristine-tar branch"""
+
+import os, re
+import gbp.log
+from gbp.command_wrappers import Command
+from gbp.pkg import compressor_opts
+from gbp.deb import DebianPkgPolicy
+
+class PristineTar(Command):
+ """The pristine-tar branch in a git repository"""
+ cmd='/usr/bin/pristine-tar'
+ branch = 'pristine-tar'
+
+ def __init__(self, repo):
+ self.repo = repo
+ super(PristineTar, self).__init__(self.cmd, cwd=repo.path)
+
+ def has_commit(self, package, version, comp_type=None):
+ """
+ Do we have a pristine-tar commit for package I{package} at version
+ {version} with compression type I{comp_type}?
+
+ @param package: the package to look for
+ @type package: C{str}
+ @param version: the upstream version to look for
+ @type version: C{str}
+ @param comp_type: the compression type
+ @type comp_type: C{str}
+ """
+ return True if self.get_commit(package, version, comp_type) else False
+
+ def get_commit(self, package, version, comp_type=None):
+ """
+ Get the pristine-tar commit of package I{package} in version I{version}
+ and compression type I{comp_type}
+
+ @param package: the package to look for
+ @type package: C{str}
+ @param version: the version to look for
+ @param comp_type: the compression type
+ @type comp_type: C{str}
+ """
+ if not self.repo.has_pristine_tar_branch():
+ return None
+
+ if not comp_type:
+ ext = '\w\+'
+ else:
+ ext = compressor_opts[comp_type][1]
+
+ regex = ('pristine-tar .* %s_%s\.orig\.tar\.%s' %
+ (package, version, ext))
+ commits = self.repo.grep_log(regex, self.branch)
+ if commits:
+ commit = commits[-1]
+ gbp.log.debug("Found pristine-tar commit at '%s'" % commit)
+ return commit
+ return None
+
+ def _checkout(self, archive):
+ self.run_error = 'Couldn\'t checkout "%s"' % os.path.basename(archive)
+ self.__call__(['checkout', archive])
+
+ def checkout(self, package, version, comp_type, output_dir):
+ """
+ Checkout the orig tarball for package I{package} of I{version} and
+ compression type I{comp_type} to I{output_dir}
+
+ @param package: the package to generate the orig tarball for
+ @type package: C{str}
+ @param version: the version to check generate the orig tarball for
+ @type version: C{str}
+ @param comp_type: the compression type of the tarball
+ @type comp_type: C{str}
+ @param output_dir: the directory to put the tarball into
+ @type output_dir: C{str}
+ """
+ name = DebianPkgPolicy.build_tarball_name(package,
+ version,
+ comp_type,
+ output_dir)
+ self._checkout(name)
+
+ def commit(self, archive, upstream):
+ """
+ Commit an archive I{archive} to the pristine tar branch using upstream
+ branch ${upstream}.
+
+ @param archive: the archive to commit
+ @type archive: C{str}
+ @param upstream: the upstream branch to diff against
+ @type upstream: C{str}
+ """
+ ref = 'refs/heads/%s' % upstream
+
+ self.run_error = ("Couldn't commit to '%s' with upstream '%s'" %
+ (self.branch, upstream))
+ self.__call__(['commit', archive, upstream])
+
diff --git a/tests/test_PristineTar.py b/tests/test_PristineTar.py
index f7eb588..8a64524 100644
--- a/tests/test_PristineTar.py
+++ b/tests/test_PristineTar.py
@@ -3,7 +3,7 @@
"""
Test pristine-tar related methods in
- - L{gbp.deb.PristineTar}
+ - L{gbp.deb.DebianPristineTar}
and
@@ -38,7 +38,7 @@ def test_empty_repo():
Methods tested:
- L{gbp.deb.git.DebianGitRepository.has_pristine_tar_branch}
- - L{gbp.deb.pristinetar.PristineTar.has_commit}
+ - L{gbp.deb.pristinetar.DebianPristineTar.has_commit}
>>> import gbp.deb.git
>>> repo = gbp.deb.git.DebianGitRepository(repo_dir)
@@ -80,7 +80,7 @@ def test_pristine_tar_commit():
Commit the delta to the pristine-tar branch
Methods tested:
- - L{gbp.deb.pristinetar.PristineTar.commit}
+ - L{gbp.deb.pristinetar.DebianPristineTar.commit}
>>> import gbp.deb.git
>>> repo = gbp.deb.git.DebianGitRepository(repo_dir)
@@ -92,8 +92,8 @@ def test_pristine_has_commit():
Find delta on the pristine tar branch
Methods tested:
- - L{gbp.deb.pristinetar.PristineTar.has_commit}
- - L{gbp.deb.pristinetar.PristineTar.get_commit}
+ - L{gbp.deb.pristinetar.DebianPristineTar.has_commit}
+ - L{gbp.pkg.pristinetar.PristineTar.get_commit}
>>> import gbp.deb.git
>>> repo = gbp.deb.git.DebianGitRepository(repo_dir)
@@ -114,7 +114,7 @@ def test_pristine_tar_checkout():
Checkout a tarball using pristine-tar
Methods tested:
- - L{gbp.deb.pristinetar.PristineTar.checkout}
+ - L{gbp.deb.pristinetar.DebianPristineTar.checkout}
>>> import gbp.deb.git
>>> repo = gbp.deb.git.DebianGitRepository(repo_dir)