From ddd7a8a5edd4d291d8262e14f1ad4f6c70d5084f Mon Sep 17 00:00:00 2001 From: bandl <1658002533@qq.com> Date: Tue, 21 Sep 2021 20:16:08 +0800 Subject: [PATCH] refactor(structure, shell): update shell, structure --- pkg/structure/generate/tem.yaml | 5 +- pkg/structure/stringx/option.go | 14 ---- pkg/structure/stringx/string.go | 3 - shell/gen_protobuf.py | 2 +- shell/gen_struct_interface.py | 109 -------------------------------- shell/make-struct.py | 8 +-- 6 files changed, 6 insertions(+), 135 deletions(-) delete mode 100644 shell/gen_struct_interface.py diff --git a/pkg/structure/generate/tem.yaml b/pkg/structure/generate/tem.yaml index b81c1bf..9aae05e 100644 --- a/pkg/structure/generate/tem.yaml +++ b/pkg/structure/generate/tem.yaml @@ -6,7 +6,4 @@ STRING_X: - add - reduce - setbit - - getbit - -LIST_X: - - set \ No newline at end of file + - getbit \ No newline at end of file diff --git a/pkg/structure/stringx/option.go b/pkg/structure/stringx/option.go index f6c7490..653ddc2 100644 --- a/pkg/structure/stringx/option.go +++ b/pkg/structure/stringx/option.go @@ -1,15 +1 @@ package stringx - -import "gitee.com/timedb/wheatCache/pkg/proto" - -func (s *StringX) Set(req *proto.SetRequest) ([]string, error) { - s.Value = req.Value - return nil, nil -} - -func (s *StringX) Get(req *proto.GetRequest) ([]string, error) { - result := make([]string, 0, 1) - result = append(result, s.Value) - - return result, nil -} diff --git a/pkg/structure/stringx/string.go b/pkg/structure/stringx/string.go index a5f4e71..5e9740c 100644 --- a/pkg/structure/stringx/string.go +++ b/pkg/structure/stringx/string.go @@ -1,8 +1,5 @@ package stringx -import "gitee.com/timedb/wheatCache/pkg/structure" - type StringX struct { - structure.KeyBase Value string } diff --git a/shell/gen_protobuf.py b/shell/gen_protobuf.py index 5067550..2ca11a2 100644 --- a/shell/gen_protobuf.py +++ b/shell/gen_protobuf.py @@ -17,7 +17,7 @@ def load_conf(): with open(conf_path, 'r', encoding='utf-8') as f: cfg = f.read() - cfg = yaml.load(cfg) + cfg = yaml.load(cfg, Loader=yaml.FullLoader) cfg_camel = {} diff --git a/shell/gen_struct_interface.py b/shell/gen_struct_interface.py deleted file mode 100644 index 4e22bfd..0000000 --- a/shell/gen_struct_interface.py +++ /dev/null @@ -1,109 +0,0 @@ -import os - - -def DealList(li: list): - # 对列表进行处理 - flag = 0 - InterName = [] - BlankNum = [] - SliceNum = [] - for i in range(len(li)): - if flag == 0: - SliceNum.append(i) - InterName.append(f"{li[i].lower().title()}Interface".replace("_", "").replace(":", "")) - flag = 1 - if li[i] == '': - BlankNum.append(i) - flag = 0 - Dict = {} - for i in range(len(InterName)-1): - Dict[InterName[i]] = li[SliceNum[i]+1:BlankNum[i]] - Dict[InterName[-1]] = li[BlankNum[-1]+2:] - return Dict - - -def SetInterface(): - # 对读取到的yaml进行处理 - Temp = [] - path = os.getcwd() - WirtePath = f"{path}/pkg/structure/interface.go" - ReadPath = f"{path}/pkg/structure/generate/tem.yaml" - with open(ReadPath, "r") as f: - title = f.read() - title = title.split("\n")[2:] - for i in title: - if ' - ' not in i: - Temp.append(i) - if ' - ' in i: - i = i.split("-")[1] - Temp.append(i) - - # 对列表进行处理,便于自动补全 - dic = DealList(Temp) - - # 通过传入的列表对interface.go进行自动补全 - Temp = [] - AppendList = [] - with open(WirtePath, "r") as f: - context = f.read() - context = context.split("\n") - flag = 0 - for i in context: - if "interface" in i: - flag = 1 # 开锁 - if "}" in i: - Temp.append(i) - AppendList.append(Temp) - Temp = [] - flag = 0 # 上锁 - if flag == 1: - Temp.append(i) - - # 拆分成功, 开始匹配 - Del = [] - res = context[0:20] - for i in AppendList[2:]: - x = i[0:2] - for key, values in dic.items(): - if key in i[0]: - Del.append(key) - for val in values: - x.append(f'\t{val.title().lstrip()}(*pr' - f'oto.{val.title().lstrip()}Request) ([]string, error)'.replace("_", "")) - x.append("\n}\n\n") - for j in x: - res.append(j) - for i in Del: - dic.pop(i) - # 添加新增的 - for key, values in dic.items(): - w = [] - w.append(f"type {key} interface" + "{") - w.append('\tKeyBaseInterface') - for val in values: - w.append(f'\t{val.title().lstrip()}(*pr' - f'oto.{val.title().lstrip()}Request) ([]string, error)'.replace("_", "")) - w.append("\n}\n\n") - for j in w: - res.append(j) - f = open(WirtePath, 'w') - judge = "" - for i in res: - if judge == i: - continue - judge = i - if "package" in i: - i = f"{i}\n" - if "import" in i: - i = f"{i}\n" - if i == '': - i = '\n' - if i == '}' or i == '\n{\n': - i = '\n}\n' - i = i.replace('\t', '\n\t') - f.write(i) - f.close() - - -if __name__ == "__main__": - SetInterface() \ No newline at end of file diff --git a/shell/make-struct.py b/shell/make-struct.py index 994c094..64aa538 100644 --- a/shell/make-struct.py +++ b/shell/make-struct.py @@ -1,6 +1,7 @@ import os -from jinja2 import Template + import yaml +from jinja2 import Template sysPath = os.getcwd() tempPath = f"{sysPath}/pkg/structure/generate" @@ -29,15 +30,13 @@ def load_conf(): with open(conf_path, 'r', encoding='utf-8') as f: cfg = f.read() - cfg = yaml.load(cfg) + cfg = yaml.load(cfg, Loader=yaml.FullLoader) cfg_camel = {} for key, val in cfg.items(): cfg_camel[key] = [to_camel(v) for v in val] - print(cfg_camel) - return cfg, cfg_camel @@ -60,6 +59,7 @@ def set_structure_const_template(conf: dict): with open(temp_path, 'w', encoding='utf-8') as f: f.write(text) + # 生成接口