[yocto] [yocto-autobuilder][PATCH] ScrapeTargets: use translate instead of regex

Stephano Cetola stephano.cetola at linux.intel.com
Sat Jul 15 12:33:59 PDT 2017


>From some quick tests the string translate function is comparable in
efficiency and certainly more legible than regex. We should note that
if we ever move this functionality to an environment running python3,
the translate function takes one dictionary argument, but functions
in much the same way.

Signed-off-by: Stephano Cetola <stephano.cetola at linux.intel.com>
---
 .../site-packages/autobuilder/buildsteps/ScrapeTargets.py          | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/python2.7/site-packages/autobuilder/buildsteps/ScrapeTargets.py b/lib/python2.7/site-packages/autobuilder/buildsteps/ScrapeTargets.py
index ceed0c709..0480f3de3 100644
--- a/lib/python2.7/site-packages/autobuilder/buildsteps/ScrapeTargets.py
+++ b/lib/python2.7/site-packages/autobuilder/buildsteps/ScrapeTargets.py
@@ -57,9 +57,10 @@ class ScrapeTargets(ShellCommand):
             targets = res.group()
             # Try and ensure we scrape the target regardless of which
             # assignment operator is used and surrounding whitespace
-            targets = re.sub('%s *\??\??:?.?\+?=\+?\.? *\"' % self.targetsvar, '', targets, 1)
-            targets = targets.replace('\\', '')
-            targets = targets.replace('\n', '')
+            targets = targets.replace(self.targetsvar, '')
+            targets = targets.translate(None, ':+?="')
+            targets = targets.replace("\\", "")
+            targets = targets.replace ("\n", "")
         self.setProperty("scraped_targets",
                          targets,
                          'Targets "%s" scraped from %s' % (targets,
-- 
2.13.2




More information about the yocto mailing list