0

I am trying to get each entity to draw a certain type of graph using the Understand Python API. All the inputs are good and the database is opened but the the single item is not drawn. There is no error and no output file. The code is listed below. The Python code is called from a C# application which calls upython.exe with the associated arguments.

The Python file receives the Scitools directory and opens the understand database. The entities are also an argument which is loaded into a temp file. The outputPath references the directory where the SVG file will be placed. I can't seem to figure out why the item.draw method isn't working.

import os
import sys
import argparse
import re
import json

#parse arguments
parser = argparse.ArgumentParser(description = 'Creates butterfly or call by graphs from and Understand DB')
parser.add_argument('PathToSci', type = str, help = "Path to Sci Understand libraries")
parser.add_argument('PathToDB', type = str, help = "Path to the Database you want to create graphs from")
parser.add_argument('PathToOutput', type = str, help='Path to where the graphs should be outputted')
parser.add_argument('TypeOfGraph', type = str, 
                    help="The type of graph you want to generate. Same names as in Understand GUI. IE 'Butterfly' 'Called By' 'Control Flow' ")
parser.add_argument("entities",  help='Path to json list file of Entity long names you wish to create graphs for')

args, unknown = parser.parse_known_args()

# they may have entered a path with a space broken into multiple strings
if len(unknown) > 0:
    print("Unkown argument entered.\n Note: Individual arguments must be passed as a single string.")
    quit()

pathToSci = args.PathToSci
pathToDB = args.PathToDB
graphType = args.TypeOfGraph
entities = json.load(open(args.entities,))
pathToOutput = args.PathToOutput

pathToSci = os.path.join(pathToSci, "Python")
sys.path.append(pathToSci)
import understand

db = understand.open(pathToDB)

count = 0
for name in entities:
    count += 1
    print("Completed: " + str(count) + "/" + str(len(entities)))

    #if it is an empty name don't make a graph
    if len(name) == 0:
        break

    pattern = re.compile((name + '$').replace("\\", "/"))
    print("pattern: " + str(pattern))
    sys.stdout.flush()
    ent = db.lookup(pattern)
    print("ent: " + str(ent))
    sys.stdout.flush()
    print("Type: " + str(type(ent[0])))
    sys.stdout.flush()
    for item in ent:
        try:
            filename = os.path.join(pathToOutput, item.longname() + ".svg")
            print("Graph Type: " + graphType)
            sys.stdout.flush()
            print("filename: " + filename)
            sys.stdout.flush()
            print("Item Kind: " + str(ent[0].kind()))
            sys.stdout.flush()
            item.draw(graphType, filename)
        except understand.UnderstandError:
            print("error creating graph")
            sys.stdout.flush()
        except Exception as e:
            print("Could not create graph for " + item.kind().longname() + ": " + item.longname())
            sys.stdout.flush()
            print(e)
            sys.stdout.flush()
    
db.close()

The output is below:

Completed: 1/1
pattern: re.compile('CSC03.SIN_COS$')
ent: [@lCSC03.SIN_COS@kacsc03.sin_cos(long_float,csc03.sctype)long_float@f./../../../IOSSP/Source_Files/OGP/OGP_71/csc03/csc03.ada]
Type: <class 'understand.Ent'>
Graph Type: Butterfly
filename: C:\Users\M73720\Documents\DFS\DFS-OGP-25-Aug-2022-11-24\SVGs\Entities\CSC03.SIN_COS.svg
Item Kind: Function
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245

1 Answers1

1

It turns out that it was a problem in the Understand API. The latest build corrected the problem. This was found by talking with SciTools Support group.