From 27fbb69034a99b9b3962daa2f95af880ceb03265 Mon Sep 17 00:00:00 2001 From: yu_lang <534013339@qq.com> Date: Mon, 20 Sep 2021 14:01:15 +0800 Subject: [PATCH] =?UTF-8?q?feat(proto):add=20proto=20=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96=E7=94=9F=E6=88=90=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/structure/generate/tem.yaml | 7 ++- protobuf/listx.proto | 22 ++++++++++ protobuf/stringx.proto | 9 +++- shell/gen_protobuf.py | 77 ++++++++++++++++++++++++++++++++- 4 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 protobuf/listx.proto diff --git a/pkg/structure/generate/tem.yaml b/pkg/structure/generate/tem.yaml index 81cb823..95156c6 100644 --- a/pkg/structure/generate/tem.yaml +++ b/pkg/structure/generate/tem.yaml @@ -9,4 +9,9 @@ STRING_X: - getbit LIST_X: - - l_set \ No newline at end of file + - l_set + - l_get + - l_add + - l_queue + - l_setbit + - l_getbit diff --git a/protobuf/listx.proto b/protobuf/listx.proto new file mode 100644 index 0000000..cc2733b --- /dev/null +++ b/protobuf/listx.proto @@ -0,0 +1,22 @@ +syntax = "proto3"; +import "base.proto"; +option go_package = "pkg/proto"; + +message LSetRequest { + BaseKey key = 1; +} +message LGetRequest { + BaseKey key = 1; +} +message LAddRequest { + BaseKey key = 1; +} +message LQueueRequest { + BaseKey key = 1; +} +message LSetbitRequest { + BaseKey key = 1; +} +message LGetbitRequest { + BaseKey key = 1; +} \ No newline at end of file diff --git a/protobuf/stringx.proto b/protobuf/stringx.proto index edf3c43..9499847 100644 --- a/protobuf/stringx.proto +++ b/protobuf/stringx.proto @@ -19,6 +19,13 @@ message AddRequest { int64 value = 2; } -message RedceRequest { +message ReduceRequest { BaseKey key = 1; } + +message SetbitRequest { + BaseKey key = 1; +} +message GetbitRequest { + BaseKey key = 1; +} \ No newline at end of file diff --git a/shell/gen_protobuf.py b/shell/gen_protobuf.py index 0aba17d..077e013 100644 --- a/shell/gen_protobuf.py +++ b/shell/gen_protobuf.py @@ -1 +1,76 @@ -import os \ No newline at end of file +import os +from typing import Dict, List +from jinja2 import Template +import yaml + +sysPath = os.getcwd() +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: + cfg = f.read() + + cfg = yaml.load(cfg) + + cfg_camel = {} + + for key, val in cfg.items(): + key = to_camel(key).lower() + cfg_camel[key] = [to_camel(v) for v in val] + +# print(cfg_camel) + + return cfg, cfg_camel + + +# 生成文件,并写入 +def mkdir(cfg_camel): + path = "protobuf" + path = path.strip() + # 判断路径是否存在 + isExists = os.path.exists(path) + # 判断结果 + if not isExists: + os.makedirs(path) + print(path + ' 创建成功') + else: # 如果目录存在则不创建,并提示目录已存在 + # print(path + ' 目录已存在') + for key,value in cfg_camel.items(): +# print(key) + proto_path = path + '/' + key + '.proto' + if not os.path.exists(proto_path): # 如果这个文件不存在 + 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\tBaseKey key = 1;\n}') + file.close() + else: # 如果这个文件存在 + with open(proto_path) as f: + line = f.readlines() +# print(line) + f.close() + for v in value: + function = v + 'Request' + flag = 0 + for l in line: + if function in l: + flag=1 + break + if flag == 0: + file = open(proto_path,'a') + file.write('\nmessage ' + v +'Request '+'{\n\tBaseKey key = 1;\n}') + file.close() + flag = 0 + + +if __name__ == "__main__": + conf, cfg_camel = load_conf() +# + mkdir(cfg_camel) +