17 __author__ =
"Sebastien Binet, Adrien Renaud"
22 from optparse
import OptionParser
30 from collections
import defaultdict
31 cxx_dpp = defaultdict(list)
33 for k,v
in dpp.iteritems():
35 cxx_dpp[v[
'cxx_type']].
append({k:v})
37 for k,v
in cxx_dpp.iteritems():
40 print (
'------',vv.keys())
41 print (
'---------',vv.values())
45 """return the dictionary of components and their properties
50 comps_db = shelve.open(fname,
'r')
51 return comps_db[
'all-cfgs']
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)
65 for k
in ref.iterkeys():
67 diff[k] = (ref[k],
'<KEYNOTFOUND>')
68 elif (ref[k] != chk[k]):
69 diff[k] = (ref[k], chk[k])
71 for k
in chk.iterkeys():
73 diff[k] = (
'<KEYNOTFOUND>', chk[k])
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', }
85 ref_keys =
set(ref.keys())
86 chk_keys =
set(chk.keys())
88 common_keys = ref_keys & chk_keys
89 ref_only_keys = ref_keys - chk_keys
90 chk_only_keys = chk_keys - ref_keys
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:
97 print (
"::: components in chk only: [%5s]" % (len(chk_only_keys),))
98 if len(chk_only_keys)>0:
103 for comp_name
in common_keys:
104 comp_ref = ref[comp_name]
105 comp_chk = chk[comp_name]
109 if ref_props != chk_props:
110 diff.append((comp_name, ref_props, chk_props,
112 chk=comp_chk[
'props'])))
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)
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)
131 print (
"-%s: %r" %(prop_name, ref_value,))
132 print (
"+%s: %r" %(prop_name, chk_value,))
135 if (len(ref_only_keys) > 0
or
136 len(chk_only_keys) > 0
or
141 if __name__ ==
"__main__":
143 parser = OptionParser(
144 usage=
"usage: %prog [options] [-r] ref.josvc.ascii [-f] chk.josvc.ascii"
146 _add = parser.add_option
151 help =
"The path to the first josvc.ascii file to analyze" )
156 help =
"The path to the second josvc.ascii file to analyze" )
165 action =
"store_true",
168 help =
"Switch to activate verbose printout" )
171 (options, args) = parser.parse_args()
173 if len(args) > 0
and args[0][0] !=
"-":
174 options.ref_fname = args[0]
176 if len(args) > 1
and args[1][0] !=
"-":
177 options.chk_fname = args[1]
180 if (options.chk_fname
is None or options.ref_fname
is None) :
181 str(parser.print_help()
or "")
185 chk_fname = os.path.expandvars(os.path.expanduser(options.chk_fname))
186 ref_fname = os.path.expandvars(os.path.expanduser(options.ref_fname))
189 print (
"::: comparing configurations")
190 print (
"::: ref: %s" % ref_fname)
192 print (
"::: -> [%d] components" % (len(ref_db.keys()),))
193 print (
"::: chk: %s" % chk_fname)
195 print (
"::: -> [%d] components" % (len(chk_db.keys()),))
200 print (
"::: all good")
202 print (
"::: configurations differ !")