ATLAS Offline Software
Loading...
Searching...
No Matches
diff-jobo-cfg Namespace Reference

Functions

 dump_seq (seq)
 cxx_sort (dpp)
 load_cfg_file (fname)
 dict_diff (ref, chk)
 cmp_component_db (ref, chk, verbose=True)

Variables

str __author__ = "Sebastien Binet, Adrien Renaud"
 parser
 _add = parser.add_option
 dest
 help
 action
 default
 options
 args
 ref_fname = os.path.expandvars(os.path.expanduser(options.ref_fname))
 chk_fname = os.path.expandvars(os.path.expanduser(options.chk_fname))
 ref_db = load_cfg_file(ref_fname)
 chk_db = load_cfg_file(chk_fname)
 sc = cmp_component_db(ref_db, chk_db, options.verbose)

Function Documentation

◆ cmp_component_db()

diff-jobo-cfg.cmp_component_db ( ref,
chk,
verbose = True )
 compare 2 dicts of components
dicts are of the form:
 { 'comp_type' : <name of component>,
   'cxx_type'  : <C++ type of the component>,
   'props' : { 'property-name' : 'property-value', }
   }

Definition at line 76 of file diff-jobo-cfg.py.

76def cmp_component_db(ref, chk, verbose=True):
77 """ compare 2 dicts of components
78 dicts are of the form:
79 { 'comp_type' : <name of component>,
80 'cxx_type' : <C++ type of the component>,
81 'props' : { 'property-name' : 'property-value', }
82 }
83 """
84 common_keys = []
85 ref_keys = set(ref.keys())
86 chk_keys = set(chk.keys())
87
88 common_keys = ref_keys & chk_keys
89 ref_only_keys = ref_keys - chk_keys
90 chk_only_keys = chk_keys - ref_keys
91
92 print ("::: components in both files: [%5s]" % (len(common_keys),))
93 print ("::: components in ref only: [%5s]" % (len(ref_only_keys),))
94 if len(ref_only_keys)>0:
95 dump_seq(ref_only_keys)
96 print ("="*80)
97 print ("::: components in chk only: [%5s]" % (len(chk_only_keys),))
98 if len(chk_only_keys)>0:
99 dump_seq(chk_only_keys)
100 print ("="*80)
101
102 diff = []
103 for comp_name in common_keys:
104 comp_ref = ref[comp_name]
105 comp_chk = chk[comp_name]
106
107 ref_props = sorted([(k,v) for k,v in comp_ref['props'].iteritems()])
108 chk_props = sorted([(k,v) for k,v in comp_chk['props'].iteritems()])
109 if ref_props != chk_props:
110 diff.append((comp_name, ref_props, chk_props,
111 dict_diff(ref=comp_ref['props'],
112 chk=comp_chk['props'])))
113 pass
114
115 print ("::: components with different properties: [%5s]" % (len(diff),))
116 for name, ref_props, chk_props, diff_props in diff:
117 print ("::: - component: [%s]" % (name,))
118 for prop_name, prop_value in diff_props.iteritems():
119 ref_value = prop_value[0]
120 chk_value = prop_value[1]
121 if isinstance(ref_value, list):
122 ref_value = sorted(ref_value)
123 if isinstance(chk_value, list):
124 chk_value = sorted(chk_value)
125
126 if isinstance(ref_value, list) and isinstance(chk_value, list):
127 dref_value = set(ref_value) - set(chk_value)
128 dchk_value = set(chk_value) - set(ref_value)
129 ref_value = sorted(list(dref_value))
130 chk_value = sorted(list(dchk_value))
131 print ("-%s: %r" %(prop_name, ref_value,))
132 print ("+%s: %r" %(prop_name, chk_value,))
133
134
135 if (len(ref_only_keys) > 0 or
136 len(chk_only_keys) > 0 or
137 len(diff) > 0):
138 return 1
139 return 0
140
STL class.

◆ cxx_sort()

diff-jobo-cfg.cxx_sort ( dpp)

Definition at line 29 of file diff-jobo-cfg.py.

29def cxx_sort(dpp):
30 from collections import defaultdict
31 cxx_dpp = defaultdict(list)
32
33 for k,v in dpp.iteritems():
34 #print (v['cxx_type'])
35 cxx_dpp[v['cxx_type']].append({k:v})
36
37 for k,v in cxx_dpp.iteritems():
38 print ('---',k)
39 for vv in v:
40 print ('------',vv.keys())
41 print ('---------',vv.values())#['comp_type']
42 return cxx_dpp
43

◆ dict_diff()

diff-jobo-cfg.dict_diff ( ref,
chk )
 Return a dict of keys that differ with another config object.  If a value is
    not found in one fo the configs, it will be represented by KEYNOTFOUND.
    @param ref:   First dictionary to diff.
    @param chk:   Second dicationary to diff.
    @return diff:   Dict of Key => (ref.val, chk.val)

Definition at line 56 of file diff-jobo-cfg.py.

56def dict_diff(ref, chk):
57 """ Return a dict of keys that differ with another config object. If a value is
58 not found in one fo the configs, it will be represented by KEYNOTFOUND.
59 @param ref: First dictionary to diff.
60 @param chk: Second dicationary to diff.
61 @return diff: Dict of Key => (ref.val, chk.val)
62 """
63 diff = {}
64 # Check all keys in ref dict
65 for k in ref.iterkeys():
66 if not (k in chk):
67 diff[k] = (ref[k], '<KEYNOTFOUND>')
68 elif (ref[k] != chk[k]):
69 diff[k] = (ref[k], chk[k])
70 # Check all keys in chk dict to find missing
71 for k in chk.iterkeys():
72 if not (k in ref):
73 diff[k] = ('<KEYNOTFOUND>', chk[k])
74 return diff
75

◆ dump_seq()

diff-jobo-cfg.dump_seq ( seq)

Definition at line 24 of file diff-jobo-cfg.py.

24def dump_seq(seq):
25 for i in seq:
26 print (i)
27 pass
28

◆ load_cfg_file()

diff-jobo-cfg.load_cfg_file ( fname)
return the dictionary of components and their properties

Definition at line 44 of file diff-jobo-cfg.py.

44def load_cfg_file(fname):
45 """return the dictionary of components and their properties
46 """
47 comps_db = {}
48 try:
49 import shelve
50 comps_db = shelve.open(fname, 'r')
51 return comps_db['all-cfgs']
52 except Exception:
53 exec (open(fname).read(), comps_db)
54 return comps_db['d']
55
IovVectorMap_t read(const Folder &theFolder, const SelectionCriterion &choice, const unsigned int limit=10)

Variable Documentation

◆ __author__

str diff-jobo-cfg.__author__ = "Sebastien Binet, Adrien Renaud"
private

Definition at line 17 of file diff-jobo-cfg.py.

◆ _add

diff-jobo-cfg._add = parser.add_option
protected

Definition at line 146 of file diff-jobo-cfg.py.

◆ action

diff-jobo-cfg.action

Definition at line 165 of file diff-jobo-cfg.py.

◆ args

diff-jobo-cfg.args

Definition at line 171 of file diff-jobo-cfg.py.

◆ chk_db

diff-jobo-cfg.chk_db = load_cfg_file(chk_fname)

Definition at line 194 of file diff-jobo-cfg.py.

◆ chk_fname

diff-jobo-cfg.chk_fname = os.path.expandvars(os.path.expanduser(options.chk_fname))

Definition at line 177 of file diff-jobo-cfg.py.

◆ default

diff-jobo-cfg.default

Definition at line 167 of file diff-jobo-cfg.py.

◆ dest

diff-jobo-cfg.dest

Definition at line 150 of file diff-jobo-cfg.py.

◆ help

diff-jobo-cfg.help

Definition at line 151 of file diff-jobo-cfg.py.

◆ options

diff-jobo-cfg.options

Definition at line 171 of file diff-jobo-cfg.py.

◆ parser

diff-jobo-cfg.parser
Initial value:
1= OptionParser(
2 usage="usage: %prog [options] [-r] ref.josvc.ascii [-f] chk.josvc.ascii"
3 )

Definition at line 143 of file diff-jobo-cfg.py.

◆ ref_db

diff-jobo-cfg.ref_db = load_cfg_file(ref_fname)

Definition at line 191 of file diff-jobo-cfg.py.

◆ ref_fname

diff-jobo-cfg.ref_fname = os.path.expandvars(os.path.expanduser(options.ref_fname))

Definition at line 174 of file diff-jobo-cfg.py.

◆ sc

diff-jobo-cfg.sc = cmp_component_db(ref_db, chk_db, options.verbose)

Definition at line 197 of file diff-jobo-cfg.py.