forked from openmsa/python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsdk_to_json.py
More file actions
79 lines (67 loc) · 2.22 KB
/
sdk_to_json.py
File metadata and controls
79 lines (67 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""SDK to Json."""
import collections
import inspect
import json
from inspect import signature
from msa_sdk import util
from msa_sdk.conf_profile import ConfProfile
from msa_sdk.customer import Customer
from msa_sdk.device import Device
from msa_sdk.lookup import Lookup
from msa_sdk.orchestration import Orchestration
from msa_sdk.order import Order
from msa_sdk.repository import Repository
from msa_sdk.variables import Variables
device = Device()
lookup = Lookup()
order = Order(1)
orchestration = Orchestration(1)
repository = Repository()
customer = Customer()
conf_profile = ConfProfile()
variable = Variables()
output_doc = collections.defaultdict(dict) # type: dict
def get_members(cls_name, obj):
"""Extract members."""
output_doc[cls_name] = {"methods": list()}
for i in inspect.getmembers(obj, predicate=inspect.ismethod):
if i[0].startswith('__init__'):
output_doc[cls_name]["methods"].append(
{
i[0]: {
"description": inspect.getdoc(i[1]),
"parameters": str(signature(i[1]))
}
}
)
if not i[0].startswith('_'):
output_doc[cls_name]["methods"].append(
{
i[0]: {
"description": inspect.getdoc(i[1]),
"parameters": str(signature(i[1]))
}
}
)
def get_members_function():
"""Exctract members of a function."""
output_doc["util"] = {"methods": list()}
for func_name, funcobj in inspect.getmembers(util,
predicate=inspect.isfunction):
output_doc["util"]["methods"].append(
{
func_name: {
"description": inspect.getdoc(funcobj),
"parameters": str(signature(funcobj))
}
}
)
get_members('Device', device)
get_members('Lookup', lookup)
get_members('Order', order)
get_members('Repository', repository)
get_members('Customer', customer)
get_members('ConfProfile', conf_profile)
get_members('Variables', variable)
get_members_function()
print(json.dumps(output_doc))