[oe-commits] Chris Larson : oe.patch: use oe.process

git version control git at git.openembedded.org
Fri Oct 22 02:41:02 UTC 2010


Module: openembedded.git
Branch: darwin
Commit: 284b957584c7377a19cea487a1a42226c89044a0
URL:    http://gitweb.openembedded.net/?p=openembedded.git&a=commit;h=284b957584c7377a19cea487a1a42226c89044a0

Author: Chris Larson <chris_larson at mentor.com>
Date:   Thu Oct 21 17:23:40 2010 -0700

oe.patch: use oe.process

Signed-off-by: Chris Larson <chris_larson at mentor.com>

---

 lib/oe/patch.py |   81 +++++++++++++------------------------------------------
 1 files changed, 19 insertions(+), 62 deletions(-)

diff --git a/lib/oe/patch.py b/lib/oe/patch.py
index 8be8c89..7de0ba6 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):
@@ -108,24 +72,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, stdin=patch)
 
     def Push(self, force = False, all = False, run = True):
         if all:
@@ -166,17 +125,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)
 
 
 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)
 
     def _quiltpatchpath(self, file):
         return os.path.join(self.dir, "patches", os.path.basename(file))
@@ -216,13 +176,10 @@ 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)
+            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 +303,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)
 





More information about the Openembedded-commits mailing list