forked from p53841790/wheat-cache
refactor(proto-structure): update shell
This commit is contained in:
parent
6eec180306
commit
e3acfcd0fe
2
makefile
2
makefile
|
@ -3,7 +3,9 @@ STORAGE_PATH = $(BASE_PATH)/storage
|
|||
BASE_OUT = $(BASE_PATH)/bin
|
||||
|
||||
dcgen:
|
||||
@make gen-protobuf
|
||||
@python3 ./shell/proto.py
|
||||
@make gen-struct
|
||||
|
||||
.PHONY : build
|
||||
build:
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import os
|
||||
from typing import Dict, List
|
||||
from jinja2 import Template
|
||||
|
||||
import yaml
|
||||
|
||||
sysPath = os.getcwd()
|
||||
|
@ -8,9 +7,11 @@ tempPath = f"{sysPath}/pkg/structure/generate"
|
|||
structurePath = f"{sysPath}/pkg/structure"
|
||||
protobufPath = f"{sysPath}/protobuf"
|
||||
|
||||
|
||||
def to_camel(val: str) -> str:
|
||||
return "".join([k.capitalize() for k in val.split('_')])
|
||||
|
||||
|
||||
def load_conf():
|
||||
conf_path = f"{tempPath}/tem.yaml"
|
||||
with open(conf_path, 'r', encoding='utf-8') as f:
|
||||
|
@ -28,6 +29,8 @@ def load_conf():
|
|||
|
||||
|
||||
'''生成对应的数据结构proto文件'''
|
||||
|
||||
|
||||
def mk_structure(cfg_camel):
|
||||
path = "protobuf"
|
||||
storagePath = f"{protobufPath}/storage.proto"
|
||||
|
@ -38,7 +41,7 @@ def mk_structure(cfg_camel):
|
|||
file = open(proto_path, 'w')
|
||||
file.write('syntax = "proto3";\nimport "base.proto";\noption go_package = "pkg/proto";\n')
|
||||
for v in value:
|
||||
file.write('\nmessage ' + v +'Request '+'{\n BaseKey key = 1;\n}')
|
||||
file.write('\nmessage ' + v + 'Request ' + '{\n BaseKey key = 1;\n}\n')
|
||||
file.close()
|
||||
|
||||
else: # 如果这个文件存在
|
||||
|
@ -55,7 +58,7 @@ def mk_structure(cfg_camel):
|
|||
break
|
||||
if flag == 0:
|
||||
file = open(proto_path, 'a')
|
||||
file.write('\nmessage ' + v +'Request '+'{\n BaseKey key = 1;\n}')
|
||||
file.write('\nmessage ' + v + 'Request ' + '{\n BaseKey key = 1;\n}\n')
|
||||
file.close()
|
||||
flag = 0
|
||||
|
||||
|
@ -65,7 +68,8 @@ def mk_structure(cfg_camel):
|
|||
def mk_storage(cfg_camel):
|
||||
storagePath = f"{protobufPath}/storage.proto"
|
||||
file = open(storagePath, 'w')
|
||||
file.write('// Code generated by gen-struct. DO NOT EDIT.\n// make gen-protobuf generated\n\nsyntax = "proto3";\n\noption go_package = "pkg/proto";\n\n')
|
||||
file.write(
|
||||
'// Code generated by gen-struct. DO NOT EDIT.\n// make gen-protobuf generated\n\nsyntax = "proto3";\n\noption go_package = "pkg/proto";\n\n')
|
||||
for key, value in cfg_camel.items():
|
||||
file.write('import "' + key + '.proto";\n')
|
||||
file.write('\nmessage CommendResponse {\n repeated string result = 1;\n}\n\nservice CommServer {\n')
|
||||
|
@ -81,7 +85,3 @@ if __name__ == "__main__":
|
|||
conf, cfg_camel = load_conf()
|
||||
mk_structure(cfg_camel) # 生成对应的数据结构proto文件
|
||||
mk_storage(cfg_camel)
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue