-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.py
104 lines (83 loc) · 2.61 KB
/
api.py
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import iris
from flask import Flask
from flask import send_from_directory
app = Flask(__name__, static_folder="build", static_url_path="")
app.debug = True
# put this sippet ahead of all your bluprints
# blueprint can also be app~~
@app.after_request
def after_request(response):
header = response.headers
header["Access-Control-Allow-Origin"] = "*"
return response
@app.route("/api/<ns>/ss")
def get_ss(ns):
return [
row
for row in iris.sql.exec(
'select Process, JobType, Device, Namespace, Routine, CPU, Glob, Pr, "User", Location from %SYS.ProcessQuery_SS()'
)
]
@app.route("/api/<ns>/schemas")
def get_schemas(ns):
return [
row
for row in iris.sql.exec(
"select SCHEMA_NAME from %SQL_MANAGER.SCHEMAS(0) where TABLE_EXISTS=1"
)
]
@app.route("/api/<ns>/tables/", defaults={"schema": ""})
@app.route("/api/<ns>/tables/<schema>")
def get_tables(ns, schema):
return [
row
for row in iris.sql.exec(f"select NAME from %SQL_MANAGER.TABLES('{schema}')")
]
@app.route("/api/<ns>/classes/", defaults={"package": ""})
@app.route("/api/<ns>/classes/<path:package>")
def get_classes(ns, package):
# spec, direction, orderBy, systemFiles, flat ? "1" : "0", notStudio, generated
spec = (package.replace("/", ".") + "/" if package else "") + "*.cls"
direction = 1
orderBy = 1
systemFiles = 0
flat = 0
notStudio = 0
generated = 0
rows = iris.sql.exec(
"SELECT Name, Type FROM %Library.RoutineMgr_StudioOpenDialog(?,?,?,?,?,?,?)",
spec,
direction,
orderBy,
systemFiles,
flat,
notStudio,
generated,
)
return [row for row in rows]
@app.route("/api/<ns>/doc/<path:doc>")
def get_doc(ns, doc):
docname = doc.replace("/", ".")
linesArray = iris.arrayref()
iris.cls("%Atelier.v1.Utils.TextServices").GetTextAsArray(docname, 0, linesArray, 0)
lines = int(linesArray["0"])
return list(linesArray.value.values())[1:lines]
@app.route("/api")
def get_root_info(ns=None):
nsArr = iris.arrayref()
iris.cls("%Atelier.v1.Utils.General").AccessibleNamespaces(nsArr)
return {
"version": iris.system.Version.GetVersion(),
"username": iris.system.Process.UserName(),
"namespaces": list(nsArr.value.keys()),
}
@app.route("/api/<ns>")
def get_ns_info(ns=None):
return {
"namespace": iris.system.Process.NameSpace(),
}
@app.route("/")
def catch_all():
return send_from_directory("build", "index.html")
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0", port=5001)