diff options
author | Guido Günther <agx@sigxcpu.org> | 2012-01-13 09:07:19 +0100 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2012-01-22 19:45:26 +0100 |
commit | 5b5dbf61244708d9d234a3ef90ce85cd4f35f259 (patch) | |
tree | 4ac0abfab8629011418c4bc6852b423295b1a2f3 | |
parent | 63b24cef4db5277eff7b38bbe359fc30f9d28b90 (diff) | |
download | git-buildpackage-5b5dbf61244708d9d234a3ef90ce85cd4f35f259.tar.gz git-buildpackage-5b5dbf61244708d9d234a3ef90ce85cd4f35f259.tar.bz2 git-buildpackage-5b5dbf61244708d9d234a3ef90ce85cd4f35f259.zip |
PristineTar: move to separate module
and make it accessible from GitRepository to group
checkout/checkin/lookup.
-rw-r--r-- | gbp/command_wrappers.py | 18 | ||||
-rw-r--r-- | gbp/deb/git.py | 23 | ||||
-rw-r--r-- | gbp/deb/pristinetar.py | 113 | ||||
-rwxr-xr-x | gbp/scripts/buildpackage.py | 15 | ||||
-rwxr-xr-x | gbp/scripts/clone.py | 10 | ||||
-rw-r--r-- | gbp/scripts/create_remote_repo.py | 6 | ||||
-rw-r--r-- | gbp/scripts/import_dsc.py | 2 | ||||
-rw-r--r-- | gbp/scripts/import_orig.py | 2 | ||||
-rwxr-xr-x | gbp/scripts/pull.py | 7 | ||||
-rw-r--r-- | tests/05_test_detection.py | 5 | ||||
-rw-r--r-- | tests/test_Changelog.py | 2 |
11 files changed, 163 insertions, 40 deletions
diff --git a/gbp/command_wrappers.py b/gbp/command_wrappers.py index 856ad1b7..f22375d8 100644 --- a/gbp/command_wrappers.py +++ b/gbp/command_wrappers.py @@ -126,24 +126,6 @@ class RunAtCommand(Command): raise -class PristineTar(Command): - cmd='/usr/bin/pristine-tar' - branch='pristine-tar' - - def __init__(self): - if not os.access(self.cmd, os.X_OK): - raise GbpError, "%s not found - cannot use pristine-tar" % self.cmd - Command.__init__(self, self.cmd) - - def commit(self, archive, branch): - self.run_error = 'Couldn\'t commit to "%s"' % branch - self.__call__(['commit', archive, branch]) - - def checkout(self, archive): - self.run_error = 'Couldn\'t checkout "%s"' % os.path.basename(archive) - self.__call__(['checkout', archive]) - - class UnpackTarArchive(Command): """Wrap tar to unpack a compressed tar archive""" def __init__(self, archive, dir, filters=[], compression=None): diff --git a/gbp/deb/git.py b/gbp/deb/git.py index aa19f82a..3f998051 100644 --- a/gbp/deb/git.py +++ b/gbp/deb/git.py @@ -18,10 +18,15 @@ import re from gbp.git import GitRepository, GitRepositoryError +from gbp.deb.pristinetar import PristineTar 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) + def find_version(self, format, version): """ Check if a certain version is stored in this repo and return the SHA1 @@ -112,4 +117,22 @@ class DebianGitRepository(GitRepository): return version return None + @property + def pristine_tar_branch(self): + """ + The name of the pristine-tar branch, whether it already exists or + not. + """ + return PristineTar.branch + + def has_pristine_tar_branch(self): + """ + Wheter the repo has a I{pristine-tar} branch. + + @return: C{True} if the repo has pristine-tar commits already, C{False} + otherwise + @rtype: C{Bool} + """ + return True if self.has_branch(self.pristine_tar_branch) else False + # vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·: diff --git a/gbp/deb/pristinetar.py b/gbp/deb/pristinetar.py new file mode 100644 index 00000000..4478ad42 --- /dev/null +++ b/gbp/deb/pristinetar.py @@ -0,0 +1,113 @@ +# 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 +from gbp.command_wrappers import Command +from gbp.deb import UpstreamSource, compressor_opts + +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) + + 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 = UpstreamSource.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/gbp/scripts/buildpackage.py b/gbp/scripts/buildpackage.py index db6f055e..3e3df10f 100755 --- a/gbp/scripts/buildpackage.py +++ b/gbp/scripts/buildpackage.py @@ -27,7 +27,7 @@ import tempfile import shutil import gbp.deb as du from gbp.command_wrappers import (Command, - RunAtCommand, CommandExecFailed, PristineTar, + RunAtCommand, CommandExecFailed, RemoveTree, CatenateTarArchive) from gbp.config import (GbpOptionParser, GbpOptionGroup) from gbp.deb.git import (GitRepositoryError, DebianGitRepository) @@ -321,10 +321,11 @@ def pristine_tar_build_orig(repo, cp, output_dir, options): @return: True: orig tarball build, False: noop """ if options.pristine_tar: - pt = PristineTar() if not repo.has_branch(pt.branch): - gbp.log.warn('Pristine-tar branch "%s" not found' % pt.branch) - pt.checkout(os.path.join(output_dir, du.orig_file(cp, options.comp_type))) + gbp.log.warn('Pristine-tar branch "%s" not found' % + repo.pristine_tar.branch) + repo.pristine_tar.checkout(os.path.join(output_dir, + du.orig_file(cp, options.comp_type))) return True else: return False @@ -376,7 +377,7 @@ def guess_comp_type(repo, comp_type, cp, tarball_dir): comp_type = 'auto' if comp_type == 'auto': - if not repo.has_branch(PristineTar.branch): + if not repo.has_pristine_tar_branch(): if not tarball_dir: tarball_dir = '..' detected = None @@ -391,12 +392,12 @@ def guess_comp_type(repo, comp_type, cp, tarball_dir): comp_type = 'gzip' else: regex = 'pristine-tar .* %s_%s\.orig.tar\.' % (srcpkg, upstream_version) - commits = repo.grep_log(regex, PristineTar.branch) + commits = repo.grep_log(regex, repo.pristine_tar_branch) if commits: commit = commits[-1] gbp.log.debug("Found pristine-tar commit at '%s'" % commit) else: - commit = PristineTar.branch + commit = repo.pristine_tar_branch tarball = repo.get_subject(commit) comp_type = du.get_compression(tarball) gbp.log.debug("Determined compression type '%s'" % comp_type) diff --git a/gbp/scripts/clone.py b/gbp/scripts/clone.py index 2c4a93b8..5dffbd09 100755 --- a/gbp/scripts/clone.py +++ b/gbp/scripts/clone.py @@ -22,9 +22,9 @@ import sys import os, os.path from gbp.config import (GbpOptionParser, GbpOptionGroup) -from gbp.git import (GitRepositoryError, GitRepository) -from gbp.command_wrappers import (Command, CommandExecFailed, - PristineTar) +from gbp.deb.git import DebianGitRepository +from gbp.git import (GitRepository, GitRepositoryError) +from gbp.command_wrappers import (Command, CommandExecFailed) from gbp.errors import GbpError import gbp.log @@ -72,7 +72,7 @@ def main(argv): pass try: - repo = GitRepository.clone(os.path.curdir, source, options.depth) + repo = DebianGitRepository.clone(os.path.curdir, source, options.depth) os.chdir(repo.path) # Reparse the config files of the cloned repository so we pick up the @@ -90,7 +90,7 @@ def main(argv): else: # only track gbp's default branches branches = [ options.debian_branch, options.upstream_branch ] if options.pristine_tar: - branches += [ PristineTar.branch ] + branches += [ repo.pristine_tar_branch ] gbp.log.debug('Will track branches: %s' % branches) for branch in branches: remote = 'origin/%s' % branch diff --git a/gbp/scripts/create_remote_repo.py b/gbp/scripts/create_remote_repo.py index 09158252..d00963c8 100644 --- a/gbp/scripts/create_remote_repo.py +++ b/gbp/scripts/create_remote_repo.py @@ -27,7 +27,7 @@ import subprocess import tty, termios import re from gbp.deb.changelog import ChangeLog, NoChangeLogError -from gbp.command_wrappers import (CommandExecFailed, PristineTar, GitCommand) +from gbp.command_wrappers import (CommandExecFailed, GitCommand) from gbp.config import (GbpOptionParser, GbpOptionGroup) from gbp.errors import GbpError from gbp.git import (GitRepositoryError, GitRepository) @@ -177,8 +177,8 @@ def main(argv): if repo.has_branch(branch): branches += [ branch ] - if repo.has_branch(PristineTar.branch) and options.pristine_tar: - branches += [ PristineTar.branch ] + if repo.has_pristine_tar_branch() and options.pristine_tar: + branches += [ repo.pristine_tar_branch ] try: cp = ChangeLog(filename=changelog) diff --git a/gbp/scripts/import_dsc.py b/gbp/scripts/import_dsc.py index ce65f8cf..6aed3c2e 100644 --- a/gbp/scripts/import_dsc.py +++ b/gbp/scripts/import_dsc.py @@ -306,7 +306,7 @@ def main(argv): if is_empty: repo.create_branch(options.upstream_branch, commit) if options.pristine_tar: - gbpc.PristineTar().commit(src.tgz, 'refs/heads/%s' % options.upstream_branch) + repo.pristine_tar.commit(src.tgz, options.upstream_branch) parents = [ options.upstream_branch ] if not src.native: if is_empty and not repo.has_branch(options.debian_branch): diff --git a/gbp/scripts/import_orig.py b/gbp/scripts/import_orig.py index 55b2c2e6..98a43d2b 100644 --- a/gbp/scripts/import_orig.py +++ b/gbp/scripts/import_orig.py @@ -396,7 +396,7 @@ def main(argv): if options.pristine_tar: if pristine_orig: - gbpc.PristineTar().commit(pristine_orig, 'refs/heads/%s' % upstream_branch) + repo.pristine_tar.commit(pristine_orig, upstream_branch) else: gbp.log.warn("'%s' not an archive, skipping pristine-tar" % source.path) diff --git a/gbp/scripts/pull.py b/gbp/scripts/pull.py index face2cc1..5dc1b607 100755 --- a/gbp/scripts/pull.py +++ b/gbp/scripts/pull.py @@ -21,8 +21,7 @@ import sys import os, os.path -from gbp.command_wrappers import (Command, - CommandExecFailed, PristineTar) +from gbp.command_wrappers import (Command, CommandExecFailed) from gbp.config import (GbpOptionParser, GbpOptionGroup) from gbp.errors import GbpError from gbp.git import (GitRepositoryError, GitRepository) @@ -105,8 +104,8 @@ def main(argv): if repo.has_branch(branch): branches += [ branch ] - if repo.has_branch(PristineTar.branch) and options.pristine_tar: - branches += [ PristineTar.branch ] + if repo.has_pristine_tar_branch() and options.pristine_tar: + branches += [ repo.pristine_tar_branch ] (ret, out) = repo.is_clean() if not ret: diff --git a/tests/05_test_detection.py b/tests/05_test_detection.py index c9cd16cd..913a7b9d 100644 --- a/tests/05_test_detection.py +++ b/tests/05_test_detection.py @@ -16,9 +16,12 @@ class MockGitRepository: self.with_branch = with_branch self.subject = subject - def has_branch(self, branch): + def has_pristine_tar_branch(self): return self.with_branch + def pristine_tar_branch(self): + 'pristine-tar' + def grep_log(self, regex, branch): return None diff --git a/tests/test_Changelog.py b/tests/test_Changelog.py index 97414abb..be22b8a2 100644 --- a/tests/test_Changelog.py +++ b/tests/test_Changelog.py @@ -158,6 +158,7 @@ def test_parse_eopch(): """ def test_parse_name(): + """ Methods tested: - L{gbp.deb.changelog.ChangeLog.__init__} @@ -168,3 +169,4 @@ def test_parse_name(): >>> cl = gbp.deb.changelog.ChangeLog(cl_debian) >>> cl.name 'git-buildpackage' + """ |