implement build.py:applyPatches()

This commit is contained in:
Barış Metin
2005-07-01 12:05:40 +00:00
parent 12e457ec3a
commit 02a23c8582
2 changed files with 44 additions and 7 deletions
+12 -2
View File
@@ -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.
+32 -5
View File
@@ -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 """