From 02a23c85826b93bcf21334bd9b01cee6cd4eab39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Metin?= Date: Fri, 1 Jul 2005 12:05:40 +0000 Subject: [PATCH] implement build.py:applyPatches() --- pisi/build.py | 14 ++++++++++++-- pisi/util.py | 37 ++++++++++++++++++++++++++++++++----- 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/pisi/build.py b/pisi/build.py index afcaa215..71c9fd11 100644 --- a/pisi/build.py +++ b/pisi/build.py @@ -58,7 +58,7 @@ class PisiBuild: """PisiBuild class, provides the package build and creation routines""" def __init__(self, buildcontext): self.ctx = buildcontext - self.work_dir = self.ctx.pkg_work_dir() + self.pspecDir = os.path.dirname(self.ctx.pspecfile) self.spec = self.ctx.spec self.sourceArchive = SourceArchive(self.ctx) @@ -115,7 +115,17 @@ class PisiBuild: pass def applyPatches(self): - pass + files_dir = os.path.abspath(os.path.join(self.pspecDir, + const.files_dir)) + + for patch in self.spec.source.patches: + patchFile = os.path.join(files_dir, patch.filename) + if patch.compressionType: + patchFile = util.uncompress(patchFile, + targetDir=self.ctx.tmp_dir()) + + ui.info("Applying patch: %s\n" % patch.filename) + util.do_patch(self.ctx.pkg_work_dir(), patchFile) def setEnvorinment(self): # put the evironment variables for actions API to use. diff --git a/pisi/util.py b/pisi/util.py index 6bf1e994..a371d980 100644 --- a/pisi/util.py +++ b/pisi/util.py @@ -31,7 +31,7 @@ def concat(l): def strlist(l): """concatenate string reps of l's elements""" - return string.join(map(lambda x: str(x) + ' ', l)) + return "".join(map(lambda x: str(x) + ' ', l)) def multisplit(str, chars): """ split str with any of chars""" @@ -196,15 +196,42 @@ def run_batch(cmd): ui.error('ERROR: executing command: ' + cmd + '\n' + strlist(lines)) return (successful,lines) -def do_patch(patch, p=0): +def uncompress(patchFile, compressType="gz", targetDir=None): + """uncompresses a file and returns the path of the uncompressed + file""" + if targetDir: + filePath = os.path.join(targetDir, + os.path.basename(patchFile)) + else: + filePath = os.path.basename(patchFile) + + fileObj = open(filePath, "w") + + if compressType == "gz": + from gzip import GzipFile + obj = GzipFile(patchFile) + + fileObj.write(obj.read()) + fileObj.close() + return filePath + + +def do_patch(sourceDir, patchFile, p=0): """simple function to apply patches..""" - check_file(patch) - cmd = "patch -p%d < %s" % (p, patch) + + cwd = os.getcwd() + os.chdir(sourceDir) + + check_file(patchFile) + cmd = "patch -p%d < %s" % (p, patchFile) p = os.popen(cmd) o = p.readlines() retval = p.close() if retval: - raise UtilError("ERROR: patch (%s) failed: %s" % (patch, strlist (o))) + raise UtilError("ERROR: patch (%s) failed: %s" % (patchFile, + strlist (o))) + + os.chdir(cwd) def partition_freespace(directory): """ returns free space of given directory's partition """