2019-01-22 10:15:47 +00:00
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
|
|
|
|
from adaptor.ctpadaptor import CtpAdaptor
|
|
|
|
from autocxxpy.generator import GeneratorOptions, Generator
|
|
|
|
|
|
|
|
logger = logging.getLogger(__file__)
|
|
|
|
|
|
|
|
|
|
|
|
def clear_dir(path: str):
|
|
|
|
for file in os.listdir(path):
|
|
|
|
os.unlink(os.path.join(path, file))
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2019-01-24 09:43:22 +00:00
|
|
|
options: GeneratorOptions = CtpAdaptor(
|
|
|
|
"../source/ctp/api/ThostFtdcMdApi.h",
|
|
|
|
"../source/ctp/api/ThostFtdcTraderApi.h",
|
|
|
|
).parse()
|
2019-01-22 10:15:47 +00:00
|
|
|
|
2019-01-24 09:43:22 +00:00
|
|
|
options.includes.append("api/ThostFtdcTraderApi.h")
|
|
|
|
options.includes.append("api/ThostFtdcMdApi.h")
|
2019-01-22 10:15:47 +00:00
|
|
|
options.split_in_files = True
|
2019-01-24 09:43:22 +00:00
|
|
|
options.module_name = "vnctp"
|
2019-01-22 10:15:47 +00:00
|
|
|
options.max_classes_in_one_file = 100
|
|
|
|
|
|
|
|
saved_files = Generator(options=options).generate()
|
|
|
|
output_dir = "./generated_files"
|
|
|
|
# clear output dir
|
|
|
|
if not os.path.exists(output_dir):
|
|
|
|
os.mkdir(output_dir)
|
|
|
|
clear_dir(output_dir)
|
|
|
|
|
|
|
|
for name, data in saved_files.items():
|
|
|
|
with open(f"{output_dir}/{name}", "wt") as f:
|
|
|
|
f.write(data)
|
|
|
|
|
|
|
|
|
2019-01-24 09:43:22 +00:00
|
|
|
if __name__ == "__main__":
|
2019-01-22 10:15:47 +00:00
|
|
|
main()
|