aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorChris Larson <chris_larson@mentor.com>2010-10-21 17:23:40 -0700
committerChris Larson <chris_larson@mentor.com>2010-10-21 20:09:42 -0700
commitc7a68fe6ff738b86d6da5e55ce4927f8fb06b38c (patch)
tree25873227f4fc5d2cf7d8ce550c08d9e32505336f /lib
parent1c164de88d35a46eaa6a9414de58384493c1196a (diff)
downloadopenembedded-c7a68fe6ff738b86d6da5e55ce4927f8fb06b38c.tar.gz
oe.patch: use oe.process
Signed-off-by: Chris Larson <chris_larson@mentor.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/oe/patch.py83
1 files changed, 21 insertions, 62 deletions
diff --git a/lib/oe/patch.py b/lib/oe/patch.py
index 8be8c892ea..ea5309f321 100644
--- a/lib/oe/patch.py
+++ b/lib/oe/patch.py
@@ -1,43 +1,7 @@
+import subprocess
+import os
import oe.path
-
-class NotFoundError(Exception):
- def __init__(self, path):
- self.path = path
-
- def __str__(self):
- return "Error: %s not found." % self.path
-
-class CmdError(Exception):
- def __init__(self, exitstatus, output):
- self.status = exitstatus
- self.output = output
-
- def __str__(self):
- return "Command Error: exit status: %d Output:\n%s" % (self.status, self.output)
-
-
-def runcmd(args, dir = None):
- import commands
-
- if dir:
- olddir = os.path.abspath(os.curdir)
- if not os.path.exists(dir):
- raise NotFoundError(dir)
- os.chdir(dir)
- # print("cwd: %s -> %s" % (olddir, dir))
-
- try:
- args = [ commands.mkarg(str(arg)) for arg in args ]
- cmd = " ".join(args)
- # print("cmd: %s" % cmd)
- (exitstatus, output) = commands.getstatusoutput(cmd)
- if exitstatus != 0:
- raise CmdError(exitstatus >> 8, output)
- return output
-
- finally:
- if dir:
- os.chdir(olddir)
+import oe.process
class PatchError(Exception):
def __init__(self, msg):
@@ -56,6 +20,7 @@ class PatchSet(object):
self.d = d
self.patches = []
self._current = None
+ self.env = {"PATH": d.getVar("PATH", True)}
def current(self):
return self._current
@@ -108,24 +73,19 @@ class PatchTree(PatchSet):
self.patches.insert(i, patch)
def _applypatch(self, patch, force = False, reverse = False, run = True):
- shellcmd = ["cat", patch['file'], "|", "patch", "-p", patch['strippath']]
+ shellcmd = ["patch", "-p%s" % patch['strippath']]
if reverse:
shellcmd.append('-R')
if not run:
- return "sh" + "-c" + " ".join(shellcmd)
+ return subprocess.list2cmdline(shellcmd)
+ patch = open(patch['file'], "r")
if not force:
- shellcmd.append('--dry-run')
+ oe.process.run(shellcmd + ["--dry-run"], cwd=self.dir, stdin=patch)
+ patch.seek(0)
- output = runcmd(["sh", "-c", " ".join(shellcmd)], self.dir)
-
- if force:
- return
-
- shellcmd.pop(len(shellcmd) - 1)
- output = runcmd(["sh", "-c", " ".join(shellcmd)], self.dir)
- return output
+ return oe.process.run(shellcmd, cwd=self.dir, env=self.env, stdin=patch)
def Push(self, force = False, all = False, run = True):
if all:
@@ -166,17 +126,18 @@ class GitApplyTree(PatchTree):
shellcmd.append(patch['file'])
if not run:
- return "sh" + "-c" + " ".join(shellcmd)
+ return subprocess.list2cmdline(shellcmd)
- return runcmd(["sh", "-c", " ".join(shellcmd)], self.dir)
+ return oe.process.run(shellcmd, cwd=self.dir, env=self.env)
class QuiltTree(PatchSet):
def _runcmd(self, args, run = True):
quiltrc = bb.data.getVar('QUILTRCFILE', self.d, 1)
+ cmdline = ["quilt", "--quiltrc", quiltrc] + args
if not run:
- return ["quilt"] + ["--quiltrc"] + [quiltrc] + args
- runcmd(["quilt"] + ["--quiltrc"] + [quiltrc] + args, self.dir)
+ return subprocess.list2cmdline(cmdline)
+ oe.process.run(cmdline, cwd=self.dir, env=self.env)
def _quiltpatchpath(self, file):
return os.path.join(self.dir, "patches", os.path.basename(file))
@@ -216,13 +177,11 @@ class QuiltTree(PatchSet):
# determine which patches are applied -> self._current
try:
- output = runcmd(["quilt", "applied"], self.dir)
- except CmdError:
- import sys
- if sys.exc_value.output.strip() == "No patches applied":
- return
- else:
- raise sys.exc_value
+ output = oe.process.run(["quilt", "applied"], cwd=self.dir, \
+ env=self.env)
+ except oe.process.ExecutionError, exc:
+ if exc.stdout.strip() != "No patches applied":
+ raise
output = [val for val in output.split('\n') if not val.startswith('#')]
for patch in self.patches:
if os.path.basename(patch["quiltfile"]) == output[-1]:
@@ -346,7 +305,7 @@ class UserResolver(Resolver):
os.chdir(self.patchset.dir)
try:
self.patchset.Push(False)
- except CmdError, v:
+ except oe.process.CmdError:
# Patch application failed
patchcmd = self.patchset.Push(True, False, False)