5 '''Functions useful for dealing with Trigger ART test scripts'''
9 from contextlib
import contextmanager
13 '''Returns a prefix included in names of all tests from the given package'''
14 from TrigValTools.TrigValSteering.Common
import package_prefix_dict
16 return '({})'.
format(
'|'.
join(package_prefix_dict.values()))
17 elif package
in package_prefix_dict.keys():
18 return package_prefix_dict[package]
25 if os.path.basename(path) == filename:
32 for path
in os.environ[
'PATH'].
split(os.pathsep):
34 files = os.listdir(path)
37 for filename
in files:
40 if re.search(patt, filename)
is None:
44 scripts.append(os.path.join(path, filename))
51 '''Simple pushd/popd replacement from https://stackoverflow.com/a/169112'''
61 Returns the first file name from the list which corresponds to an existing file.
62 Returns None if none of the files in the list exist.
64 for file_name
in file_list:
65 if os.path.isfile(file_name):
72 Returns the newest file (by modification date) in the current directory
73 with a name matching the pattern. Returns None if no file is matched.
75 all_files = os.listdir(
'.')
76 rx = re.compile(pattern)
77 matched_files = [f
for f
in all_files
if re.search(rx, f)]
80 matched_files.sort(key=
lambda f: os.stat(f).st_mtime)
81 return matched_files[-1]