[yocto] [AB PATCH 13/22] yoctogit.py: DRYing up some code

Elizabeth Flanagan elizabeth.flanagan at intel.com
Wed Mar 19 13:51:11 PDT 2014


From: Beth Flanagan <elizabeth.flanagan at intel.com>

Remove duplicate code from movecopy and barecopy and add it to
a new callback _srccopy.

Signed-off-by: Beth Flanagan <elizabeth.flanagan at intel.com>
---
 .../buildbot/steps/source/yoctogit.py              | 73 +++++++++-------------
 1 file changed, 30 insertions(+), 43 deletions(-)

diff --git a/lib/python2.7/site-packages/buildbot-0.8.8-py2.7.egg/buildbot/steps/source/yoctogit.py b/lib/python2.7/site-packages/buildbot-0.8.8-py2.7.egg/buildbot/steps/source/yoctogit.py
index 66bfb51..c5dbf05 100644
--- a/lib/python2.7/site-packages/buildbot-0.8.8-py2.7.egg/buildbot/steps/source/yoctogit.py
+++ b/lib/python2.7/site-packages/buildbot-0.8.8-py2.7.egg/buildbot/steps/source/yoctogit.py
@@ -194,9 +194,11 @@ class YoctoGit(Source):
             return
         elif self.method == 'barecopy':
             yield self.barecopy()
+            yield self._srccopy()
             return
         elif self.method == 'movecopy':
             yield self.movecopy()
+            yield self._srccopy()
             return
 
         if not updatable:
@@ -267,32 +269,6 @@ class YoctoGit(Source):
             todir = "build/" + self.layername
             self.workdir = 'source/'+self.repourl
         d.addCallback(lambda _: self.incremental())
-        def copy(_):
-            cmd = buildstep.RemoteCommand('cpdir',
-                                          {'fromdir': self.srcdir,
-                                           'todir': todir,
-                                           'logEnviron': self.logEnviron,
-                                           'timeout': self.timeout,})
-            cmd.useLog(self.stdio_log, False)
-            d = self.runCommand(cmd)
-            def evaluateCommand(cmd):
-                if cmd.didFail():
-                    log.msg("Source step failed while running command %s" % cmd)
-                    raise buildstep.BuildStepFailed()
-            d.addCallback(lambda _: evaluateCommand(cmd))
-            return d
-        d.addCallback(copy)
-       
-        def resetWorkdir(_):
-            if "poky" in self.layername or \
-               "oecore" in self.layername or \
-               "eclipse" in self.layername:
-                self.workdir = 'build'
-            else:
-                self.workdir = "build/" + self.layername
-            return 0
-
-        d.addCallback(resetWorkdir)
         return d
 
     def movecopy(self):
@@ -325,22 +301,35 @@ class YoctoGit(Source):
         else:
             todir = "build/" + self.layername
         d.addCallback(lambda _: self.incremental())
+        return d
 
-        def copy(_):
-            cmd = buildstep.RemoteCommand('cpdir',
-                                          {'fromdir': self.srcdir,
-                                           'todir': todir,
-                                           'logEnviron': self.logEnviron,
-                                           'timeout': self.timeout,})
-            cmd.useLog(self.stdio_log, False)
-            d = self.runCommand(cmd)
-            def evaluateCommand(cmd):
-                if cmd.didFail():
-                    log.msg("Source step failed while running command %s" % cmd)
-                    raise buildstep.BuildStepFailed()
-            d.addCallback(lambda _: evaluateCommand(cmd))
-            return d
-        d.addCallback(copy)
+    # Buildbot's standard copy has been removed from yoctogit. 
+    # We use _srccopy from either movecopy or barecopy as a callback
+    # this uses self.srcdir to copy to the build dir.
+    
+    def _srccopy(self):
+        if "poky" in self.layername or \
+           "oecore" in self.layername or \
+           "eclipse" in self.layername:
+            todir = "build"
+        else:
+            todir = "build/" + self.layername
+
+        cmd = buildstep.RemoteCommand('cpdir',
+                                      {'fromdir': self.srcdir,
+                                       'todir': todir,
+                                       'logEnviron': self.logEnviron,
+                                       'timeout': self.timeout,})
+        cmd.useLog(self.stdio_log, False)
+        d = self.runCommand(cmd)
+
+        def evaluateCommand(cmd):
+            if cmd.didFail():
+                log.msg("Source step failed while running command %s" % cmd)
+                raise buildstep.BuildStepFailed()
+
+        d.addCallback(lambda _: evaluateCommand(cmd))
+        return d
 
         def resetWorkdir(_):
             if "poky" in self.layername or \
@@ -353,8 +342,6 @@ class YoctoGit(Source):
         d.addCallback(resetWorkdir)
         return d
 
-    # Buildbot's standard copy has been removed from yoctogit. 
-
     def finish(self, res):
         d = defer.succeed(res)
         def _gotResults(results):
-- 
1.8.1.2




More information about the yocto mailing list