From 6ee8bfcf1dc31895e32f980a2745e86d2c6c8b7b Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Wed, 16 Dec 2015 14:20:36 +1100 Subject: [PATCH] Run regex match over jobs in memory The jobs file isn't that big, so it makes sense to read it in once and use it, rather than re-read. Saves a very small amount of time in the test. Change-Id: Id20a2d6926a250f9117108fe32b04fc70b7bfe28 --- tools/layout-checks.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/layout-checks.py b/tools/layout-checks.py index 9747730b80..fe13b59a4b 100755 --- a/tools/layout-checks.py +++ b/tools/layout-checks.py @@ -92,9 +92,11 @@ def check_formatting(): return errors def grep(source, pattern): + """Run regex PATTERN over each line in SOURCE and return + True if any match found""" found = False p = re.compile(pattern) - for line in open(source, "r").readlines(): + for line in source: if p.match(line): found = True break @@ -111,11 +113,15 @@ def check_jobs(): # The job-list.txt file is created by tools/run-layout.sh and # thus should exist if this is run from tox. If this is manually invoked # the file might not exist, in that case pass the test. - job_list = ".test/job-list.txt" - if not os.path.isfile(job_list): + job_list_file = ".test/job-list.txt" + if not os.path.isfile(job_list_file): print("Job list file %s does not exist, not checking jobs section" - % job_list) + % job_list_file) return False + + with open(job_list_file, 'r') as f: + job_list = [line.rstrip() for line in f] + for jobs in layout['jobs']: found = grep(job_list, jobs['name']) if not found: