From 4a0729edb1f89da20ad11298a734dd32a84fe1dd Mon Sep 17 00:00:00 2001 From: liwei <2211068034@qq.com> Date: Wed, 19 Jul 2023 14:53:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E7=BC=96=E8=AF=91=E5=B7=A5?= =?UTF-8?q?=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 31 +++++++++++-------------------- pb_2.7.py | 50 ++++++++++++++++++++++++++++---------------------- 2 files changed, 39 insertions(+), 42 deletions(-) diff --git a/.gitignore b/.gitignore index 403adbc..a2ea683 100644 --- a/.gitignore +++ b/.gitignore @@ -1,23 +1,14 @@ -.DS_Store -node_modules -/dist +# ---> Go +# Binaries for programs and plugins +*.exe +*.exe~ +# Test binary, built with `go test -c` +*.test -# local env files -.env.local -.env.*.local +# Output of the go coverage tool, specifically when used with LiteIDE +*.out -# Log files -npm-debug.log* -yarn-debug.log* -yarn-error.log* -pnpm-debug.log* - -# Editor directories and files -.idea -.vscode -*.suo -*.ntvs* -*.njsproj -*.sln -*.sw? +*.log +pb +node_modules \ No newline at end of file diff --git a/pb_2.7.py b/pb_2.7.py index 961207e..cb05d2a 100644 --- a/pb_2.7.py +++ b/pb_2.7.py @@ -14,28 +14,34 @@ if os.path.exists(source_path): # dirs 是一个 list,内容是该文件夹中所有的目录的名字(不包括子目录) # files 同样是 list, 内容是该文件夹中所有的文件(不包括子目录) for root, dirs, files in os.walk(source_path): - for file in files: - folder = os.path.basename(root) - if folder == "proto": - src_file = os.path.join(root, file) - shutil.copy(src_file, target_path) - elif folder != "protobuf": - src_file = os.path.join(root, file) - out_file = os.path.join(target_path, file) - file_data = "" - print(src_file) - with io.open(src_file, "r", encoding='utf-8') as f: - for line in f: - if 'import' in line: - cite = re.findall(r"\"(.+?)\"",line)[0] - cpaths = cite.split("/") - if len(cpaths) == 2: - line = re.sub( - cite, cpaths[1], line) - print(line) - file_data += line - with io.open(out_file, "w", encoding='utf-8') as f: - f.write(file_data) + if not "google" in root: + relative_path = root.split(source_path)[-1].strip("/") + if len(relative_path) == 0: + for file in files: + folder = os.path.splitext(file)[1] + if folder == ".proto": + src_file = os.path.join(root, file) + shutil.copy(src_file, target_path) + else: + for file in files: + folder = os.path.splitext(file)[1] + if folder == ".proto": + src_file = os.path.join(root, file) + out_file = os.path.join(target_path, file) + file_data = "" + print(src_file) + with io.open(src_file, "r", encoding='utf-8') as f: + for line in f: + if 'import' in line: + cite = re.findall(r"\"(.+?)\"",line)[0] + cpaths = cite.split("/") + if len(cpaths) == 2: + line = re.sub( + cite, cpaths[1], line) + print(line) + file_data += line + with io.open(out_file, "w", encoding='utf-8') as f: + f.write(file_data) cmdstr = 'npx pbjs -t json-module -w commonjs -o ./src/pb/proto.js ./src/pb/temop/*.proto' print(cmdstr) os.system(cmdstr)