17 from __future__
import print_function
19 __author__ =
"Sebastien Binet, Adrien Renaud"
24 from optparse
import OptionParser
32 from collections
import defaultdict
33 cxx_dpp = defaultdict(list)
35 for k,v
in dpp.iteritems():
37 cxx_dpp[v[
'cxx_type']].
append({k:v})
39 for k,v
in cxx_dpp.iteritems():
42 print (
'------',vv.keys())
43 print (
'---------',vv.values())
47 """return the dictionary of components and their properties
52 comps_db = shelve.open(fname,
'r')
53 return comps_db[
'all-cfgs']
55 from past.builtins
import execfile
56 execfile(fname, comps_db)
60 """ Return a dict of keys that differ with another config object. If a value is
61 not found in one fo the configs, it will be represented by KEYNOTFOUND.
62 @param ref: First dictionary to diff.
63 @param chk: Second dicationary to diff.
64 @return diff: Dict of Key => (ref.val, chk.val)
68 for k
in ref.iterkeys():
70 diff[k] = (ref[k],
'<KEYNOTFOUND>')
71 elif (ref[k] != chk[k]):
72 diff[k] = (ref[k], chk[k])
74 for k
in chk.iterkeys():
76 diff[k] = (
'<KEYNOTFOUND>', chk[k])
80 """ compare 2 dicts of components
81 dicts are of the form:
82 { 'comp_type' : <name of component>,
83 'cxx_type' : <C++ type of the component>,
84 'props' : { 'property-name' : 'property-value', }
88 ref_keys =
set(ref.keys())
89 chk_keys =
set(chk.keys())
91 common_keys = ref_keys & chk_keys
92 ref_only_keys = ref_keys - chk_keys
93 chk_only_keys = chk_keys - ref_keys
95 print (
"::: components in both files: [%5s]" % (len(common_keys),))
96 print (
"::: components in ref only: [%5s]" % (len(ref_only_keys),))
97 if len(ref_only_keys)>0:
100 print (
"::: components in chk only: [%5s]" % (len(chk_only_keys),))
101 if len(chk_only_keys)>0:
106 for comp_name
in common_keys:
107 comp_ref = ref[comp_name]
108 comp_chk = chk[comp_name]
112 if ref_props != chk_props:
113 diff.append((comp_name, ref_props, chk_props,
115 chk=comp_chk[
'props'])))
118 print (
"::: components with different properties: [%5s]" % (len(diff),))
119 for name, ref_props, chk_props, diff_props
in diff:
120 print (
"::: - component: [%s]" % (name,))
121 for prop_name, prop_value
in diff_props.iteritems():
122 ref_value = prop_value[0]
123 chk_value = prop_value[1]
124 if isinstance(ref_value, list):
125 ref_value =
sorted(ref_value)
126 if isinstance(chk_value, list):
127 chk_value =
sorted(chk_value)
129 if isinstance(ref_value, list)
and isinstance(chk_value, list):
130 dref_value =
set(ref_value) -
set(chk_value)
131 dchk_value =
set(chk_value) -
set(ref_value)
134 print (
"-%s: %r" %(prop_name, ref_value,))
135 print (
"+%s: %r" %(prop_name, chk_value,))
138 if (len(ref_only_keys) > 0
or
139 len(chk_only_keys) > 0
or
144 if __name__ ==
"__main__":
146 parser = OptionParser(
147 usage=
"usage: %prog [options] [-r] ref.josvc.ascii [-f] chk.josvc.ascii"
149 _add = parser.add_option
154 help =
"The path to the first josvc.ascii file to analyze" )
159 help =
"The path to the second josvc.ascii file to analyze" )
168 action =
"store_true",
171 help =
"Switch to activate verbose printout" )
174 (options, args) = parser.parse_args()
176 if len(args) > 0
and args[0][0] !=
"-":
177 options.ref_fname = args[0]
179 if len(args) > 1
and args[1][0] !=
"-":
180 options.chk_fname = args[1]
183 if (options.chk_fname
is None or options.ref_fname
is None) :
184 str(parser.print_help()
or "")
188 chk_fname = os.path.expandvars(os.path.expanduser(options.chk_fname))
189 ref_fname = os.path.expandvars(os.path.expanduser(options.ref_fname))
192 print (
"::: comparing configurations")
193 print (
"::: ref: %s" % ref_fname)
195 print (
"::: -> [%d] components" % (len(ref_db.keys()),))
196 print (
"::: chk: %s" % chk_fname)
198 print (
"::: -> [%d] components" % (len(chk_db.keys()),))
203 print (
"::: all good")
205 print (
"::: configurations differ !")