-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_dash.py
More file actions
126 lines (110 loc) · 3.81 KB
/
generate_dash.py
File metadata and controls
126 lines (110 loc) · 3.81 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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#
# generate model observer
#
import argparse
import tornado.template as template
import os
from redmonty.config import templates
from redmonty.powlib import pluralize
from pydoc import locate
import shutil
def camel_case(name):
"""
converts this_is_new to ThisIsNew
and this in This
"""
return "".join([x.capitalize() for x in name.split("_")])
def generate_dash():
"""
generates a basic dash environment in PythonOnWheels
handler: handler/dash.py
base view: view/dash_index.tmpl
dash layout: pow_dash.py
componentes: dash_components.py
"""
#
# set some attributes
#
print(40*"-")
print(" generating dash environment: ")
print(40*"-")
appname="redmonty"
try:
loader = template.Loader(templates["stubs_path"])
#
# render the dash index view
#
try:
shutil.copy( os.path.join(templates["stubs_path"],"dash_index.tmpl"),
os.path.join(templates["views_path"],"dash_index.tmpl"))
print(" {:15}: {:30}".format("Copied", "the view: dash_index.tmpl"))
except Exception as e:
print(str(e))
#
# render the dash server
#
ofile = open( os.path.join("./","dash_server.py") , "wb")
try:
res = loader.load("dash_server.py").generate( appname=appname )
ofile.write(res)
ofile.close()
print(" {:15}: {:30}".format("rendered", "dash_server.py"))
except Exception as e:
print(str(e))
#
# render the dash handler
#
ofile = open( os.path.join(templates["handler_path"],"dash_handler.py") , "wb")
try:
res = loader.load("dash_handler_template.py").generate( appname=appname )
ofile.write(res)
ofile.close()
print(" {:15}: {:30}".format("rendered", "handler/dash.py"))
except Exception as e:
print(str(e))
#
# render the Dash app and layout file; pow_dash.py
#
ofile = open( os.path.join(".", "pow_dash.py") , "wb")
try:
res = loader.load("pow_dash.py").generate( appname=appname )
ofile.write(res)
ofile.close()
print(" {:15}: {:30}".format("rendered", "pow_dash.py [This is the actual Dash layout and Dash app file]"))
except Exception as e:
print(str(e))
#
# copy the dash_components.py
#
try:
shutil.copy( os.path.join(templates["stubs_path"],"dash_components.py"), os.path.join(".", "dash_components.py" ))
print(" {:15}: {:30}".format("Copied", "the components file: dash_components.py"))
except Exception as e:
print(str(e))
#
# copy the dash_requirements.txt
#
try:
shutil.copy( os.path.join(templates["stubs_path"],"dash_requirements.txt"), os.path.join(".", "dash_requirements.txt" ))
print(" {:15}: {:30}".format("Requirements", "dash_requirements.txt"))
except Exception as e:
print(str(e))
except:
return False
return True
def main():
#parser = argparse.ArgumentParser()
#parser.add_argument('-n', "--name", action="store",
# dest="name", help='-n modelname',
# required=True)
#args = parser.parse_args()
generate_dash()
if __name__ == "__main__":
main()
print(40*"-")
print(" Next Steps:")
print(40*"-")
print(" {:15}: {:30}".format("commandline", "pip install -r dash_requirements.txt"))
print(" {:15}: {:30}".format("commandline", "python server.py"))
print(" {:15}: {:30}".format("go to", "http://localhost:8080/dash"))
print()