blob: 865436388223578155ec41dc14e0ac7d93e2d67a [file] [log] [blame]
Matteo Scandolo9c675d02019-02-12 10:05:35 -08001#!/usr/bin/python
2
Andy Baviere4432142019-02-07 15:11:25 -07003# Copyright 2019-present Open Networking Foundation
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
Andy Baviere4432142019-02-07 15:11:25 -070017from pyparsing import Combine, Group, Optional, ParseException, Regex, Word, ZeroOrMore, alphas, nums
18import fileinput
19import pprint
20
21Written = {}
22
23Date = Combine(Word(nums)+"-"+Word(nums)+"-"+Word(nums))
24Time = Combine(Word(nums)+":"+Word(nums)+":"+Word(nums)+"."+Word(nums))
25Msg = Regex("is new|no changes|updated")
26QuotedWord = "'"+Word(alphas+"_")+"'"+Optional(", ")
27Array = "["+ZeroOrMore(QuotedWord)+"]"
28Key = Word(alphas+"_")
29Value = Array | Word(alphas+"_-/.")
30KeyValue = Combine(Key("key")+"="+Value("value"))
31Logmsg = Date+"T"+Time+"Z [debug ] save(): "+Msg+KeyValue*(2,3)
32
33entries = {}
34
35def add_syncstep(model, field, syncstep):
36 if model not in entries:
37 entries[model] = {}
38 if field in entries[model]:
39 if syncstep not in entries[model][field]:
40 entries[model][field].append(syncstep)
41 else:
42 entries[model][field] = [syncstep]
43
44
45for line in fileinput.input():
46 entry = {}
47 try:
48 logline = Logmsg.parseString(line)
49 #print logline
50 entry["status"] = logline[4]
51 for field in range(5, len(logline)):
52 key, value = logline[field].split("=")
53 if key == "changed_fields":
54 entry[key] = eval(value)
55 else:
56 entry[key] = value
57
58 if entry["syncstep"] == "None":
59 continue
60
61 if "changed_fields" in entry:
62 for field in entry["changed_fields"]:
63 add_syncstep(entry["classname"], field, entry["syncstep"])
64 else:
65 if entry["status"] == "no changes":
66 add_syncstep(entry["classname"], "all", entry["syncstep"])
67
68
69 except ParseException, err:
70 print err.line
71 print " "*(err.column-1) + "^"
72 print err
73
74pp = pprint.PrettyPrinter()
75
76for obj in entries:
77 all_syncstep = []
78 print "\nInspecting model: ", obj
79 entry = entries[obj]
80 if "all" in entry:
81 print " [WARNING] Object being saved with no changes"
82 all_syncstep = entry["all"]
83 for path in all_syncstep:
84 print " ", path
85 for field in entry:
86 if field == "all":
87 continue
88 syncstep = list(set(entry[field] + all_syncstep))
89 if len(syncstep) > 1:
90 print " [WARNING] Field saved from multiple tasks: ", field
91 for path in syncstep:
92 print " ", path