All of lore.kernel.org
 help / color / mirror / Atom feed
* [yocto-autobuilder][PATCH] ScrapeTargets.py: Use python instead of awk
@ 2017-07-10 21:05 Stephano Cetola
  2017-07-11 11:02 ` Joshua Lock
  0 siblings, 1 reply; 2+ messages in thread
From: Stephano Cetola @ 2017-07-10 21:05 UTC (permalink / raw)
  To: yocto

Using awk, sed, or grep to pull a shell variable out of stdio proved
complex. Instead, simply cat the entire "inc" file to stdio and use
python/regex to find the variable.

Signed-off-by: Stephano Cetola <stephano.cetola@linux.intel.com>
---
 .../autobuilder/buildsteps/ScrapeTargets.py             | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/lib/python2.7/site-packages/autobuilder/buildsteps/ScrapeTargets.py b/lib/python2.7/site-packages/autobuilder/buildsteps/ScrapeTargets.py
index 07e2fdcf4..8844c6366 100644
--- a/lib/python2.7/site-packages/autobuilder/buildsteps/ScrapeTargets.py
+++ b/lib/python2.7/site-packages/autobuilder/buildsteps/ScrapeTargets.py
@@ -15,6 +15,7 @@ from buildbot.steps.shell import ShellCommand
 from buildbot.status.results import SUCCESS, FAILURE
 from autobuilder.config import *
 import os
+import re
 
 class ScrapeTargets(ShellCommand):
     haltOnFailure = False
@@ -41,9 +42,7 @@ class ScrapeTargets(ShellCommand):
         workerdir = os.path.join(os.path.join(YOCTO_ABBASE, "yocto-worker"))
         buildername = self.getProperty("buildername")
         src = os.path.join(workerdir, buildername, "build", self.source)
-        # find targetsvar then return lines up to a quote
-        self.command = ["awk",
-                '/%s/{flag=1;print;next}/"/{flag=0}flag' % self.targetsvar, src]
+        self.command = ["cat", src]
         ShellCommand.start(self)
 
     def commandComplete(self, cmd):
@@ -51,10 +50,14 @@ class ScrapeTargets(ShellCommand):
             return
 
         result = cmd.logs['stdio'].getText()
-        targets = result.strip()
-        targets = targets.replace('%s="' % self.targetsvar, '')
-        targets = targets.replace('\\', '')
-        targets = targets.replace('\n', '')
+        start = result.find(self.targetsvar) + len(self.targetsvar)
+        res = re.search('"([^"]*)"', result[start:])
+        targets = ""
+        if res:
+            targets = res.group()
+            targets = targets.replace('%s="' % self.targetsvar, '')
+            targets = targets.replace('\\', '')
+            targets = targets.replace('\n', '')
         self.setProperty("scraped_targets",
                          targets,
                          'Targets "%s" scraped from %s' % (targets,
-- 
2.13.2



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [yocto-autobuilder][PATCH] ScrapeTargets.py: Use python instead of awk
  2017-07-10 21:05 [yocto-autobuilder][PATCH] ScrapeTargets.py: Use python instead of awk Stephano Cetola
@ 2017-07-11 11:02 ` Joshua Lock
  0 siblings, 0 replies; 2+ messages in thread
From: Joshua Lock @ 2017-07-11 11:02 UTC (permalink / raw)
  To: Stephano Cetola, yocto

On Mon, 2017-07-10 at 14:05 -0700, Stephano Cetola wrote:
> Using awk, sed, or grep to pull a shell variable out of stdio proved
> complex. Instead, simply cat the entire "inc" file to stdio and use
> python/regex to find the variable.

Merged, thanks!

> Signed-off-by: Stephano Cetola <stephano.cetola@linux.intel.com>
> ---
>  .../autobuilder/buildsteps/ScrapeTargets.py             | 17
> ++++++++++-------
>  1 file changed, 10 insertions(+), 7 deletions(-)
> 
> diff --git a/lib/python2.7/site-
> packages/autobuilder/buildsteps/ScrapeTargets.py
> b/lib/python2.7/site-packages/autobuilder/buildsteps/ScrapeTargets.py
> index 07e2fdcf4..8844c6366 100644
> --- a/lib/python2.7/site-
> packages/autobuilder/buildsteps/ScrapeTargets.py
> +++ b/lib/python2.7/site-
> packages/autobuilder/buildsteps/ScrapeTargets.py
> @@ -15,6 +15,7 @@ from buildbot.steps.shell import ShellCommand
>  from buildbot.status.results import SUCCESS, FAILURE
>  from autobuilder.config import *
>  import os
> +import re
>  
>  class ScrapeTargets(ShellCommand):
>      haltOnFailure = False
> @@ -41,9 +42,7 @@ class ScrapeTargets(ShellCommand):
>          workerdir = os.path.join(os.path.join(YOCTO_ABBASE, "yocto-
> worker"))
>          buildername = self.getProperty("buildername")
>          src = os.path.join(workerdir, buildername, "build",
> self.source)
> -        # find targetsvar then return lines up to a quote
> -        self.command = ["awk",
> -                '/%s/{flag=1;print;next}/"/{flag=0}flag' %
> self.targetsvar, src]
> +        self.command = ["cat", src]
>          ShellCommand.start(self)
>  
>      def commandComplete(self, cmd):
> @@ -51,10 +50,14 @@ class ScrapeTargets(ShellCommand):
>              return
>  
>          result = cmd.logs['stdio'].getText()
> -        targets = result.strip()
> -        targets = targets.replace('%s="' % self.targetsvar, '')
> -        targets = targets.replace('\\', '')
> -        targets = targets.replace('\n', '')
> +        start = result.find(self.targetsvar) + len(self.targetsvar)
> +        res = re.search('"([^"]*)"', result[start:])
> +        targets = ""
> +        if res:
> +            targets = res.group()
> +            targets = targets.replace('%s="' % self.targetsvar, '')
> +            targets = targets.replace('\\', '')
> +            targets = targets.replace('\n', '')
>          self.setProperty("scraped_targets",
>                           targets,
>                           'Targets "%s" scraped from %s' % (targets,
> -- 
> 2.13.2
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-07-11 11:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-10 21:05 [yocto-autobuilder][PATCH] ScrapeTargets.py: Use python instead of awk Stephano Cetola
2017-07-11 11:02 ` Joshua Lock

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.