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.

dump_namespace()   F
last analyzed

Complexity

Conditions 11

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 11
c 1
b 0
f 0
dl 0
loc 26
rs 3.1764

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