-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgenerate.py
87 lines (68 loc) · 2.57 KB
/
generate.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
import os
import json
from jinja2 import Environment, FileSystemLoader
PATH = os.path.dirname(os.path.abspath(__file__))
TEMPLATE_ENVIRONMENT = Environment(
autoescape=False,
loader=FileSystemLoader(os.path.join(PATH, 'templates')),
trim_blocks=False)
TEMPLATE_ENVIRONMENT.trim_blocks = True
TEMPLATE_ENVIRONMENT.lstrip_blocks = True
def render_template(template_filename, data):
return TEMPLATE_ENVIRONMENT.get_template(template_filename).render(data=data)
def create_csharp_code(context):
fname = "out/MQL.cs"
with open(fname, 'w') as f:
code = render_template('csharp.template', context)
f.write(code)
fname = "out/MQLCommand.cs"
with open(fname, 'w') as f:
code = render_template('command_enum.template', context)
f.write(code)
fname = "out/MQLRESTResource.cs"
with open(fname, 'w') as f:
code = render_template('csharp-rest.template', context)
f.write(code)
def create_csharp_errors(context):
fname = "out/MQLExceptions.cs"
with open(fname, 'w') as f:
code = render_template('csharp.errors.template', context)
f.write(code)
fname = "out/MQLCommand.cs"
with open(fname, 'w') as f:
code = render_template('command_enum.template', context)
f.write(code)
def create_mql_code(context):
fname = "out/mc_funcs.mqh"
with open(fname, 'w') as f:
code = render_template('mql.funcs.template', context)
f.write(code)
fname = "out/mc_returns.mqh"
with open(fname, 'w') as f:
code = render_template('mql.returns.template', context)
f.write(code)
def create_mql_helpers(context):
fname = "out/mc_helpers.mqh"
tplfile = 'mql.helpers.template'
enumData = []
for i in ['ALIGN_MODE', 'COLOR', 'OBJECT', 'SIGNAL_BASE_DOUBLE', 'SIGNAL_BASE_INTEGER', 'SIGNAL_BASE_STRING', 'SIGNAL_INFO_DOUBLE', 'SIGNAL_INFO_INTEGER', 'SIGNAL_INFO_STRING', 'TIMEFRAMES']:
with open('enumlists/' + i) as enums:
lines = enums.readlines()
inputs = []
for line in lines:
inputs.append(line.rstrip("\n"))
enumData.append({'type': i, 'inputs': inputs})
with open(fname, 'w') as f:
code = render_template(tplfile, enumData)
f.write(code)
def main():
with open('function.dump.json') as json_data:
data = json.load(json_data)
create_csharp_code(data)
create_mql_code(data)
create_mql_helpers(data)
with open('errors.json') as json_data:
data = json.load(json_data)
create_csharp_errors(data)
if __name__ == "__main__":
main()