
import sys
import json

def read_cells(json_file):
    with open(json_file) as f:
        data = json.load(f)
    f.close()
    cells = data['modules']['top']['cells']
    cells_parameters = dict()
    for cell, opts in cells.items():
        cells_parameters[cell] = opts['parameters']
    return cells_parameters


def main():
    if len(sys.argv) < 3:
        print("Incorrect number of arguments")
        exit(1)
    cells1 = read_cells(sys.argv[1])
    cells2 = read_cells(sys.argv[2])
    if cells1 == cells2:
        exit(0)
    else:
        exit(1)

if __name__ == "__main__":
    main()


import sys
import json

parameters = ["IOSTANDARD", "DRIVE", "SLEW", "IN_TERM"]

def read_cells(json_file):
    with open(json_file) as f:
        data = json.load(f)
    f.close()
    cells = data['modules']['top']['cells']
    cells_parameters = dict()
    for cell, opts in cells.items():
        attributes = opts['parameters']
        if len(attributes.keys()):
            if any([x in parameters for x in attributes.keys()]):
                cells_parameters[cell] = attributes
    return cells_parameters


def main():
    if len(sys.argv) < 3:
        print("Incorrect number of arguments")
        exit(1)
    cells1 = read_cells(sys.argv[1])
    cells2 = read_cells(sys.argv[2])
    if cells1 == cells2:
        exit(0)
    else:
        print(json.dumps(cells1, indent=4))
        print("VS")
        print(json.dumps(cells2, indent=4))
        exit(1)

if __name__ == "__main__":
    main()

Add verbosity on JSON compare fail
XDC: Add verbosity on JSON compare fail

Signed-off-by: Tomasz Michalak <a2fdaa543b4cc5e3d6cd8672ec412c0eb393b86e@antmicro.com>

  
  import sys
  import json
+ 
+ parameters = ["IOSTANDARD", "DRIVE", "SLEW", "IN_TERM"]
  
  def read_cells(json_file):
      with open(json_file) as f:
          data = json.load(f)
      f.close()
      cells = data['modules']['top']['cells']
      cells_parameters = dict()
      for cell, opts in cells.items():
-         cells_parameters[cell] = opts['parameters']
+         attributes = opts['parameters']
+         if len(attributes.keys()):
+             if any([x in parameters for x in attributes.keys()]):
+                 cells_parameters[cell] = attributes
      return cells_parameters
  
  
  def main():
      if len(sys.argv) < 3:
          print("Incorrect number of arguments")
          exit(1)
      cells1 = read_cells(sys.argv[1])
      cells2 = read_cells(sys.argv[2])
      if cells1 == cells2:
          exit(0)
      else:
+         print(json.dumps(cells1, indent=4))
+         print("VS")
+         print(json.dumps(cells2, indent=4))
          exit(1)
  
  if __name__ == "__main__":
      main()
  
Add verbosity on JSON compare fail
## Code Before:

import sys
import json

def read_cells(json_file):
    with open(json_file) as f:
        data = json.load(f)
    f.close()
    cells = data['modules']['top']['cells']
    cells_parameters = dict()
    for cell, opts in cells.items():
        cells_parameters[cell] = opts['parameters']
    return cells_parameters


def main():
    if len(sys.argv) < 3:
        print("Incorrect number of arguments")
        exit(1)
    cells1 = read_cells(sys.argv[1])
    cells2 = read_cells(sys.argv[2])
    if cells1 == cells2:
        exit(0)
    else:
        exit(1)

if __name__ == "__main__":
    main()

## Instruction:
Add verbosity on JSON compare fail
## Code After:

import sys
import json

parameters = ["IOSTANDARD", "DRIVE", "SLEW", "IN_TERM"]

def read_cells(json_file):
    with open(json_file) as f:
        data = json.load(f)
    f.close()
    cells = data['modules']['top']['cells']
    cells_parameters = dict()
    for cell, opts in cells.items():
        attributes = opts['parameters']
        if len(attributes.keys()):
            if any([x in parameters for x in attributes.keys()]):
                cells_parameters[cell] = attributes
    return cells_parameters


def main():
    if len(sys.argv) < 3:
        print("Incorrect number of arguments")
        exit(1)
    cells1 = read_cells(sys.argv[1])
    cells2 = read_cells(sys.argv[2])
    if cells1 == cells2:
        exit(0)
    else:
        print(json.dumps(cells1, indent=4))
        print("VS")
        print(json.dumps(cells2, indent=4))
        exit(1)

if __name__ == "__main__":
    main()
