Exemplo n.º 1
0
def main():
    if os.name == 'posix':
        path = "../../hist_1/hist1/resources"
    else:
        path = "../../hist_1/hist1/resources"

    files = []
    dict = {}
    dict_with_relationships = {}
    for r, d, f in os.walk(path):
        for file in f:
            if '.py' in file:
                files.append(os.path.join(r, file))

    code_readers = []
    for f in files:
        code_readers.append(CodeReader(f, path))

    reload_counters()
    for cs in code_readers:
        cs.check_references()

    for m in CodeReader.Methods.values():
        comp = 0
        print(str(CodeReader.CodeReaders.get(m.file_index).filename))
        comp = CodeAnalyzer.CodeAnalysis(
            str(CodeReader.CodeReaders.get(m.file_index).filename), m.name)
        if not m.is_class_method:
            print_str = "Name: " + str(m.index) + ' - ' + m.name + "\n[file, called] - [" \
                        + str(CodeReader.CodeReaders.get(m.file_index).filename) + ', ' + str(m.call_count) + "]\n"
            elements = []
            dict_with_relationships[m.name + " - " + str(comp)] = str(
                CodeReader.CodeReaders.get(m.file_index).filename)
            for k, v in m.call_reference.items():
                print_str += "\tMethod: " + str(k) + " - " + str(
                    CodeReader.Methods[k].name) + " was called - " + str(
                        v.call_count) + "Complexity: " + str(comp) + "\n"
                elements.append([CodeReader.Methods[k].name, v.call_count])
                dict_with_relationships[CodeReader.Methods[k].name] = str(
                    CodeReader.CodeReaders.get(m.file_index).filename)
            dict[m.name] = elements
            print(print_str)
        else:
            dict_with_relationships[m.name + " - " + str(comp)] = str(
                CodeReader.CodeReaders.get(m.file_index).filename)

    del dict_with_relationships['GLOBAL - 0']

    dot = graphviz.Digraph(
        comment=
        'Relationships between methods and files(in Python files are modules)')
    for item in dict_with_relationships:
        dot.node(item, color='blue')
        dot.node(dict_with_relationships.get(item, ""),
                 shape='square',
                 color='red')
        dot.edge(item, dict_with_relationships.get(item), color='blue')
    dot.render('test-output/round-table.gv', view=True)
Exemplo n.º 2
0
def main():
    path = ".\\resources"
    files = []
    dict = {}

    for r, d, f in os.walk(path):
        for file in f:
            if '.py' in file:
                files.append(os.path.join(r, file))

    code_readers = []
    for f in files:
        code_readers.append(CodeReader(f, path))

    reload_counters()
    for cs in code_readers:
        cs.check_references()

        print("========= File: " + cs.get_name() + " ================")
        elements = []
        if len(cs.get_imports()) == 0:
            print("No imports\n\n")

        for im in cs.get_imports():
            print_str = "Import: " + im.get_source_name() + "\n"
            i = 1
            total = 0
            for f_r in im.files_ref:
                print_str += str(i) + ". " + f_r.reference_name \
                             + " calls: " + str(f_r.call_count) + '\n'
                total += f_r.call_count
                i += 1
            if im.is_local:
                elements.append([im.get_source_name(), total])
            print(print_str)

        dict[cs.get_name()] = elements

    dot = graphviz.Digraph(comment='References graph')
    for item in dict:
        dot.node(item, item)
        for child in dict[item]:
            dot.edge(item, child[0], str(child[1]))
    dot.render('test-output/round-table.gv', view=True)
Exemplo n.º 3
0
def main():
    path = "..\\..\\hist_1\\hist1\\resources"
    files = []
    dict = {}

    for r, d, f in os.walk(path):
        for file in f:
            if '.py' in file:
                files.append(os.path.join(r, file))

    code_readers = []
    for f in files:
        code_readers.append(CodeReader(f, path))

    reload_counters()
    for cs in code_readers:
        cs.check_references()

    for m in CodeReader.Methods.values():
        if not m.is_class_method:
            print_str = "Name: " + str(m.index) + ' - ' + m.name + "\n[file, called] - [" \
                        + str(CodeReader.CodeReaders.get(m.file_index).filename) + ', ' + str(m.call_count) + "]\n"
            elements = []
            for k, v in m.call_reference.items():
                print_str += "\tMethod: " + str(k) + " - " + str(
                    CodeReader.Methods[k].name) + " was called - " + str(
                        v.call_count) + "\n"
                elements.append([CodeReader.Methods[k].name, v.call_count])
            dict[m.name] = elements
            print(print_str)

    dot = graphviz.Digraph(comment='References graph')
    for item in dict:
        dot.node(item, item)
        for child in dict[item]:
            dot.edge(item, child[0], str(child[1]))
    dot.render('test-output/round-table.gv', view=True)
Exemplo n.º 4
0
def main():
    path = "..\\..\\hist_1\\hist1\\resources"
    files = []
    dict = {}
    method_ref_dict = {}
    for r, d, f in os.walk(path):
        for file in f:
            if '.py' in file:
                files.append(os.path.join(r, file))

    code_readers = []
    for f in files:
        code_readers.append(CodeReader(f, path))

    reload_counters()
    for cs in code_readers:
        cs.check_references()

    for m in CodeReader.Methods.values():
        if not m.is_class_method:
            print_str = print_method(m)
            print(print_str)

    print("======================= Classes=================\n")
    for c in CodeReader.Classes.values():
        print_str = "Name: " + str(c.index) + ' - ' + c.name + "  ============================"\
                    + "\n[file, init] - [" \
                    + CodeReader.CodeReaders.get(c.file_index).filename\
                    + ", " + str(c.init_count) + "]\n"\
                    + "GLOBAL CALLS:\n"

        for k, v in c.call_reference.items():
            if type(k) is not int:
                key = get_method_from_class_key(k)
            else:
                key = k
            if key > -1:
                print_str += "\tMethod: " + str(key) + " - " + str(
                    CodeReader.Methods[key].name)
            else:
                print_str += "\tMethod: GLOBAL"
            print_str += " was called - " + str(v.call_count) + "\n"

        print_str += "\nLOCAL METHODS:\n"

        class_content = []
        for m in c.methods.values():
            class_content.append([m.name, m.call_count])
            references = []
            for k in m.call_reference.keys():
                """Check key type"""
                if type(k) is not int:
                    """Check global / local"""
                    if k.find("-") > -1:
                        k = get_method_from_class_key(k)
                references.append([
                    CodeReader.Methods[k].name,
                    CodeReader.Methods[k].call_count
                ])

            method_ref_dict[m.name] = references
            print_str += print_method(m)
        print(print_str)

        dict[c.name] = class_content

    dot = graphviz.Digraph(comment='References graph')
    for item in dict:
        dot.node(item, item)
        for child in dict[item]:
            dot.edge(item, child[0], str(child[1]))

    for item_ in method_ref_dict:
        dot.node(item_, item_)
        for child_ in method_ref_dict[item_]:
            dot.edge(item_, child_[0], str(child_[1]))
    dot.render('test-output/round-table.gv', view=True)