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

Joshua Lock joshua.g.lock at linux.intel.com
Mon Jul 17 07:03:15 PDT 2017


On Sat, 2017-07-15 at 12:33 -0700, Stephano Cetola wrote:
> 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.

Oh, I didn't know about translate. Neat, thanks! Merged.

Joshua

> 
> 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