diff options
Diffstat (limited to 'gbp')
-rw-r--r-- | gbp/command_wrappers.py | 39 | ||||
-rw-r--r-- | gbp/config.py | 1 | ||||
-rw-r--r-- | gbp/git_utils.py | 7 |
3 files changed, 44 insertions, 3 deletions
diff --git a/gbp/command_wrappers.py b/gbp/command_wrappers.py index a08470a..8853f18 100644 --- a/gbp/command_wrappers.py +++ b/gbp/command_wrappers.py @@ -8,6 +8,7 @@ git-buildpackage and friends import subprocess import sys +import os.path class CommandExecFailed(Exception): """Exception raised by the Command class""" @@ -54,14 +55,17 @@ class Command(object): class UnpackTarArchive(Command): """Wrap tar to Unpack a gzipped tar archive""" - def __init__(self, archive, dir): + def __init__(self, archive, dir, filter=""): self.archive = archive self.dir = dir + exclude = [ "", "--exclude=%s" % filter ][len(filter) > 0] + if archive.lower().endswith(".bz2"): decompress = "--bzip2" else: decompress = "--gzip" - Command.__init__(self, 'tar', [ '-C', dir, decompress, '-xf', archive ]) + + Command.__init__(self, 'tar', [ exclude, '-C', dir, decompress, '-xf', archive ]) self.run_error = "Couldn't unpack %s" % self.archive @@ -178,10 +182,17 @@ class GitTag(GitCommand): class GitAdd(GitCommand): """Wrap git-add to add new files""" def __init__(self): - GitCommand.__init__(self,'add') + GitCommand.__init__(self, 'add') self.run_error = "Couldn't add files" +class GitRm(GitCommand): + """Wrap git-rm to remove files""" + def __init__(self): + GitCommand.__init__(self, 'rm') + self.run_error = "Couldn't remove files" + + class GitCommitAll(GitCommand): """Wrap git-commit to commit all changes""" def __init__(self): @@ -193,4 +204,26 @@ class GitCommitAll(GitCommand): GitCommand.__call__(self, args) +def copy_from(orig_dir, filter=""): + """ + copy a source tree over via tar + @param orig_dir: where to copy from + @param exclude: tar exclude pattern + @return: list of copied files + @rtype: list + """ + exclude = [ "", "--exclude=%s" % filter ][len(filter) > 0] + + try: + p1 = subprocess.Popen(["tar", exclude, "-cSpf", "-", "." ], stdout=subprocess.PIPE, cwd=orig_dir) + p2 = subprocess.Popen(["tar", "-xvSpf", "-" ], stdin=p1.stdout, stdout=subprocess.PIPE) + files = p2.communicate()[0].split('\n') + except OSError, err: + raise GbpError, "Cannot copy files: %s" % err + except ValueError, err: + raise GbpError, "Cannot copy files: %s" % err + if p1.wait() or p2.wait(): + raise GbpError, "Cannot copy files, pipe failed." + return [ os.path.normpath(f) for f in files if files ] + # vim:et:ts=4:sw=4: diff --git a/gbp/config.py b/gbp/config.py index 09297c6..bc19dcd 100644 --- a/gbp/config.py +++ b/gbp/config.py @@ -31,6 +31,7 @@ class GbpOptionParser(OptionParser): 'posttag' : '', 'debian-tag' : 'debian/%(version)s', 'upstream-tag' : 'upstream/%(version)s', + 'filter' : '', } config_files=['/etc/git-buildpackage/gbp.conf', os.path.expanduser('~/.gbp.conf'), diff --git a/gbp/git_utils.py b/gbp/git_utils.py index 54b70d2..0ea85f3 100644 --- a/gbp/git_utils.py +++ b/gbp/git_utils.py @@ -65,6 +65,13 @@ class GitRepository(object): return (ret, "".join(out)) + def index_files(self): + """List files in the index""" + out = self.__git_getoutput('ls-files') + files = [ line.strip() for line in out ] + return files + + def build_tag(format, version): """Generate a tag from a given format and a version""" return format % dict(version=sanitize_version(version)) |