ATLAS Offline Software
Loading...
Searching...
No Matches
python.TrigARTUtils Namespace Reference

Functions

 package_prefix (package)
 duplicate_filename (list, filename)
 find_scripts (patterns)
 remember_cwd ()
 first_existing_file (file_list)
 newest_file (pattern)

Detailed Description

Functions useful for dealing with Trigger ART test scripts

Function Documentation

◆ duplicate_filename()

python.TrigARTUtils.duplicate_filename ( list,
filename )

Definition at line 23 of file TrigARTUtils.py.

23def duplicate_filename(list, filename):
24 for path in list:
25 if os.path.basename(path) == filename:
26 return True
27 return False
28
29

◆ find_scripts()

python.TrigARTUtils.find_scripts ( patterns)

Definition at line 30 of file TrigARTUtils.py.

30def find_scripts(patterns):
31 scripts = []
32 for path in os.environ['PATH'].split(os.pathsep):
33 try:
34 files = os.listdir(path)
35 except OSError:
36 continue
37 for filename in files:
38 matched = True
39 for patt in patterns:
40 if re.search(patt, filename) is None:
41 matched = False
42 break
43 if matched and not duplicate_filename(scripts, filename):
44 scripts.append(os.path.join(path, filename))
45 scripts.sort()
46 return scripts
47
48
49@contextmanager
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177

◆ first_existing_file()

python.TrigARTUtils.first_existing_file ( file_list)
Returns the first file name from the list which corresponds to an existing file.
Returns None if none of the files in the list exist.

Definition at line 59 of file TrigARTUtils.py.

59def first_existing_file(file_list):
60 '''
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.
63 '''
64 for file_name in file_list:
65 if os.path.isfile(file_name):
66 return file_name
67 return None
68
69

◆ newest_file()

python.TrigARTUtils.newest_file ( pattern)
Returns the newest file (by modification date) in the current directory
with a name matching the pattern. Returns None if no file is matched.

Definition at line 70 of file TrigARTUtils.py.

70def newest_file(pattern):
71 '''
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.
74 '''
75 all_files = os.listdir('.')
76 rx = re.compile(pattern)
77 matched_files = [f for f in all_files if re.search(rx, f)]
78 if not matched_files:
79 return None
80 matched_files.sort(key=lambda f: os.stat(f).st_mtime)
81 return matched_files[-1]

◆ package_prefix()

python.TrigARTUtils.package_prefix ( package)
Returns a prefix included in names of all tests from the given package

Definition at line 12 of file TrigARTUtils.py.

12def package_prefix(package):
13 '''Returns a prefix included in names of all tests from the given package'''
14 from TrigValTools.TrigValSteering.Common import package_prefix_dict
15 if package == 'ALL':
16 return '({})'.format('|'.join(package_prefix_dict.values()))
17 elif package in package_prefix_dict.keys():
18 return package_prefix_dict[package]
19 else:
20 return None
21
22

◆ remember_cwd()

python.TrigARTUtils.remember_cwd ( )
Simple pushd/popd replacement from https://stackoverflow.com/a/169112

Definition at line 50 of file TrigARTUtils.py.

50def remember_cwd():
51 '''Simple pushd/popd replacement from https://stackoverflow.com/a/169112'''
52 curdir = os.getcwd()
53 try:
54 yield
55 finally:
56 os.chdir(curdir)
57
58