|
27 | 27 | import os
|
28 | 28 | import argparse
|
29 | 29 | import re
|
| 30 | +from jinja2 import Template |
| 31 | + |
30 | 32 | EXCLUDE_CONTROLLERS = ['Core/Api/FirmwareController.php']
|
31 | 33 |
|
32 | 34 |
|
@@ -103,17 +105,25 @@ def parse_api_php(src_filename):
|
103 | 105 | os.path.dirname(__file__), cmd_args.repo, module_name
|
104 | 106 | )
|
105 | 107 | print("update %s" % target_filename)
|
| 108 | + template_data = { |
| 109 | + 'title': "%s" % module_name.title(), |
| 110 | + 'title_underline': "".join('~' for x in range(len(module_name))), |
| 111 | + 'controllers': [] |
| 112 | + } |
| 113 | + for controller in all_modules[module_name]: |
| 114 | + payload = { |
| 115 | + 'type': controller[0]['type'], |
| 116 | + 'filename': controller[0]['filename'], |
| 117 | + 'endpoints': [] |
| 118 | + } |
| 119 | + for endpoint in controller: |
| 120 | + payload['endpoints'].append(endpoint) |
| 121 | + template_data['controllers'].append(payload) |
| 122 | + |
106 | 123 | with open(target_filename, 'w') as f_out:
|
107 |
| - f_out.write("%s\n" % module_name.title()) |
108 |
| - f_out.write("".join('~' for x in range(len(module_name)))) |
109 |
| - f_out.write("\n\n") |
110 |
| - for controller in all_modules[module_name]: |
111 |
| - f_out.write(".. csv-table:: %s (%s)\n" % (controller[0]['type'], controller[0]['filename'])) |
112 |
| - f_out.write(" :header: \"Method\", \"Module\", \"Controller\", \"Command\", \"Parameters\"\n") |
113 |
| - f_out.write(" :widths: 4, 15, 15, 30, 40\n\n") |
114 |
| - for endpoint in controller: |
115 |
| - f_out.write( |
116 |
| - " \"``%(method)s``\",\"%(module)s\",\"%(controller)s\",\"%(command)s\",\"%(parameters)s\"\n" |
117 |
| - % endpoint |
118 |
| - ) |
119 |
| - f_out.write("\n") |
| 124 | + if os.path.isfile("%s.in" % target_filename): |
| 125 | + template_filename = "%s.in" % target_filename |
| 126 | + else: |
| 127 | + template_filename = "collect_api_endpoints.in" |
| 128 | + template = Template(open(template_filename, "r").read()) |
| 129 | + f_out.write(template.render(template_data)) |
0 commit comments