GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( a925ee...41437d )
by Kaloyan
01:33
created

dump_namespace()   D

Complexity

Conditions 11

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 11
dl 0
loc 21
rs 4.7532
c 0
b 0
f 0

How to fix   Complexity   

Complexity

Complex classes like dump_namespace() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
#!/usr/bin/env python
2
3
import argparse
4
from pyfranca import Processor, LexerException, ParserException, \
5
    ProcessorException
6
7
8
def dump_namespace(namespace):
9
    if namespace.typedefs:
10
        print("\t\tTypedefs:")
11
        for item in namespace.typedefs.values():
12
            print("\t\t- {} is {}".format(item.name, item.type.name))
13
    if namespace.enumerations:
14
        print("\t\tEnumerations:")
15
        for item in namespace.enumerations.values():
16
            print("\t\t- {}".format(item.name))
17
    if namespace.structs:
18
        print("\t\tStructs:")
19
        for item in namespace.structs.values():
20
            print("\t\t- {}".format(item.name))
21
    if namespace.arrays:
22
        print("\t\tArrays:")
23
        for item in namespace.arrays.values():
24
            print("\t\t- {}".format(item.name))
25
    if namespace.maps:
26
        print("\t\tMaps:")
27
        for item in namespace.maps.values():
28
            print("\t\t- {}".format(item.name))
29
30
31
def dump_interface(interface):
32
    if interface.attributes:
33
        print("\t\tAttributes:")
34
        for item in interface.attributes.values():
35
            print("\t\t- {}".format(item.name))
36
    if interface.methods:
37
        print("\t\tMethods:")
38
        for item in interface.methods.values():
39
            print("\t\t- {}()".format(item.name))
40
    if interface.broadcasts:
41
        print("\t\tBroadcasts:")
42
        for item in interface.broadcasts.values():
43
            print("\t\t- {}".format(item.name))
44
    dump_namespace(interface)
45
46
47
def dump_package(package):
48
    print("- {} ({})".format(package.name, package.file))
49
    if package.imports:
50
        print("\tImports:")
51
        for imp in package.imports:
52
            print("\t- {} from {}".format(imp.namespace, imp.file))
53
    if package.interfaces:
54
        print("\tInterfaces:")
55
        for interface in package.interfaces.values():
56
            if interface.version:
57
                version_str = " (v{})".format(interface.version)
58
            else:
59
                version_str = ""
60
            print("\t- {}{}".format(interface.name, version_str))
61
            dump_interface(interface)
62
    if package.typecollections:
63
        print("\tType collections:")
64
        for typecollection in package.typecollections.values():
65
            if typecollection.version:
66
                version_str = " (v{})".format(typecollection.version)
67
            else:
68
                version_str = ""
69
            print("\t- {}{}".format(typecollection.name, version_str))
70
            dump_namespace(typecollection)
71
72
73
def dump_packages(packages):
74
    print("Packages:")
75
    for package in packages.values():
76
        dump_package(package)
77
78
79
def parse_command_line():
80
    parser = argparse.ArgumentParser(
81
        description="Behavioral cloning model trainer.")
82
    parser.add_argument(
83
        "fidl", nargs="+",
84
        help="Input FIDL file.")
85
    parser.add_argument(
86
        "-I", "--import", dest="import_dirs", metavar="import_dir",
87
        action="append", help="Model import directories.")
88
    args = parser.parse_args()
89
    return args
90
91
92
def main():
93
    args = parse_command_line()
94
95
    processor = Processor()
96
    if args.import_dirs:
97
        processor.package_paths.extend(args.import_dirs)
98
99
    try:
100
        for fidl in args.fidl:
101
            processor.import_file(fidl)
102
    except (LexerException, ParserException, ProcessorException) as e:
103
        print("ERROR: {}".format(e))
104
        exit(1)
105
106
    dump_packages(processor.packages)
107
108
109
if __name__ == "__main__":
110
    main()
111