ATLAS Offline Software
Loading...
Searching...
No Matches
MergeConfigs Namespace Reference

Functions

 list_directories (parent_dir, recurse=True)
 _is_ok (dir, options)
 merge_han_configs (template, parent_dir, out, options)

Variables

tuple _usage
 parser = optparse.OptionParser(usage=_usage)
 action
 metavar
 default
 help
 options
 args

Detailed Description

MergeConfigs: merges han text configuration files, warning on name conflicts
@author Peter Onyisi <ponyisi@hep.uchicago.edu>

Function Documentation

◆ _is_ok()

MergeConfigs._is_ok ( dir,
options )
protected

Definition at line 41 of file MergeConfigs.py.

41def _is_ok(dir, options):
42 return not dir.startswith(tuple(options.exclude), 2)
43

◆ list_directories()

MergeConfigs.list_directories ( parent_dir,
recurse = True )
returns a list of directories in parent_dir
Directory 'common' will appear first if present
if recurse = True, also includes all subdirectories in the tree
If user has defined DQCONFIG_DIR_WHITELIST env var, will filter based on that list
Example values would be: DQCONFIG_DIR_WHITELIST=L1Calo:HLT

Definition at line 11 of file MergeConfigs.py.

11def list_directories(parent_dir, recurse=True):
12 """
13 returns a list of directories in parent_dir
14 Directory 'common' will appear first if present
15 if recurse = True, also includes all subdirectories in the tree
16 If user has defined DQCONFIG_DIR_WHITELIST env var, will filter based on that list
17 Example values would be: DQCONFIG_DIR_WHITELIST=L1Calo:HLT
18 """
19 import os
20 whitelist = os.getenv('DQCONFIG_DIR_WHITELIST','').split(":")
21 rv = []
22 if recurse:
23 for root, dum1, dum2 in os.walk(parent_dir):
24 if root == parent_dir:
25 continue
26 rv.append(root)
27 else:
28 import stat
29 subobjs = os.listdir(parent_dir)
30 rv = [os.join(parent_dir, x) for x in subobjs]
31 rv = [x for x in rv if stat.S_ISDIR(os.stat(x))]
32 rv.sort()
33 truerv = []
34 for x in rv:
35 if 'common' in x:
36 truerv = [x] + truerv
37 elif x.split("/")[-1] in whitelist or whitelist==['']:
38 truerv.append(x)
39 return truerv
40
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177

◆ merge_han_configs()

MergeConfigs.merge_han_configs ( template,
parent_dir,
out,
options )

Definition at line 44 of file MergeConfigs.py.

44def merge_han_configs(template, parent_dir, out, options):
45 import sys, os
46 """
47 Merge the files in the input list to the output file.
48 @param inlist: list of filenames of input files
49 @param out: output filename
50 """
51 import re
52 from PyUtils.Helpers import release_metadata
53
54 rematch = re.compile(r'(\S*)\s+(\S*)\s+{')
55 # keywords we should worry about for name conflicts
56 kwlist = set(['algorithm', 'compositeAlgorithm', 'reference', 'thresholds'])
57 kwhash = {}
58 for kw in kwlist:
59 kwhash[kw] = {}
60
61 files = []
62
63 # First pass; find if there are name conflicts
64 for dir in list_directories(parent_dir):
65 f = os.path.join(dir, template)
66 if not os.access(f, os.R_OK):
67 continue
68 if not _is_ok(dir, options):
69 print (dir, 'excluded from merge')
70 continue
71 print ('Processing', f)
72 files.append(f)
73 fobj = open(f, 'r')
74 # reclevel = how nested we are; reclist = directories above us; kws = previous keywords
75 reclevel = 0; reclist = []; kws = []
76
77 for line in fobj:
78 stripline = line.strip()
79 if len(stripline) == 0:
80 continue
81 if stripline[0] == '#':
82 continue
83 if stripline[0] == '}' and reclevel > 0:
84 # in principle a properly parsing file should only close objects it has opened. Dangerous.
85 reclevel -= 1; reclist.pop(); kws.pop()
86 continue
87 match = rematch.search(line)
88 if match is None:
89 continue
90 kws.append(match.group(1)); reclevel += 1; reclist.append(match.group(2))
91 if kws[-1] in kwlist:
92 # print (line)
93 # print (match.group(1), match.group(2),)
94 fullname = '/'.join(reclist)
95 # print (fullname)
96 if fullname in kwhash[match.group(1)]:
97 # print (reclist)
98 print ('ERROR: repeated definition of %s %s' % (match.group(1), fullname))
99 print (' Current file is %s' % f)
100 print (' Earlier definition was in %s' % kwhash[match.group(1)][fullname])
101 print (' Please fix this. Merging will now stop. Output file has not been created.')
102 sys.exit(1)
103 else:
104 kwhash[match.group(1)][fullname] = f
105 fobj.close()
106
107 # if we got here, we should be ok on the unique names: pass 2
108 outobj = open(out, 'w')
109 outobj.write('# ****************************\n')
110 outobj.write('metadata GitInfo {\n')
111 outobj.write(' Hash = %s\n' % (release_metadata()['nightly release'] or "unknown"))
112 outobj.write('}\n')
113 outobj.write('# ****************************\n\n')
114 for f in files:
115 fobj = open(f, 'r')
116 for line in fobj:
117 if '$Id:' in line:
118 line += '# ' + f + '\n'
119 line = line.replace('$', '')
120 outobj.write(line)
121 outobj.write('\n')
122
STL class.

Variable Documentation

◆ _usage

tuple MergeConfigs._usage
protected
Initial value:
1= ('%prog [options] templatename parent_dir outfile\n\n'
2 'example: %prog cosmics_run.config . cosmics_run_merged.config')

Definition at line 123 of file MergeConfigs.py.

◆ action

MergeConfigs.action

Definition at line 130 of file MergeConfigs.py.

◆ args

MergeConfigs.args

Definition at line 133 of file MergeConfigs.py.

◆ default

MergeConfigs.default

Definition at line 131 of file MergeConfigs.py.

◆ help

MergeConfigs.help

Definition at line 132 of file MergeConfigs.py.

◆ metavar

MergeConfigs.metavar

Definition at line 130 of file MergeConfigs.py.

◆ options

MergeConfigs.options

Definition at line 133 of file MergeConfigs.py.

◆ parser

MergeConfigs.parser = optparse.OptionParser(usage=_usage)

Definition at line 129 of file MergeConfigs.py.