代码拉取完成,页面将自动刷新
同步操作将从 暖阳/gogame 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/usr/bin/python
# coding:utf-8
import os
import shutil
import time
_root = os.path.abspath(os.path.dirname(__file__)).replace('\\', '/')
# 打包用
# _root = os.path.dirname(os.path.realpath(sys.executable))
_basePath = _root + "/pb/proto"
# 需要转换的语言
languageList = [
"go",
# "python"
]
# 生成python.go存放目录
if "python" in languageList:
_chkFolder = _root + "/pb/pb_python"
if os.path.exists(_chkFolder):
shutil.rmtree(_chkFolder)
os.mkdir(_chkFolder)
with open(f"{_chkFolder}/__init__.py", "w") as f:
f.write(" ")
# 命令执行
def command(base_path, go_out_path, folder, file):
_dir = f"{base_path}/{folder}"
for language in languageList:
_command = None
if language == "go":
_importPath = f"{base_path}/{folder}/{file}" if folder else f"{base_path}/{file}"
_command = f"protoc --proto_path={base_path} --go_out={go_out_path} --go_opt=paths=import {_importPath}"
# print(_command)
elif language == "python":
# 生成init文件变为可导入
_chkFolder = f"{go_out_path}/pb_python/{folder}"
if os.path.exists(_chkFolder):
shutil.rmtree(_chkFolder)
os.mkdir(_chkFolder)
with open(f"{_chkFolder}/__init__.py", "w") as f:
f.write(" ")
_command = f"protoc_python --proto_path={base_path} --{language}_out={go_out_path}/pb_python {base_path}/{folder}/*.proto"
if _command:
os.system(_command)
print(f"{folder}【{file}】转换【{language}】成功")
# 是否是pb文件
def isPBFile(path, file):
if ".proto" not in file:
return False
_filePath = f"{path}/{file}"
# 文件不能为空
if not os.path.getsize(_filePath):
print(f"{_filePath}不能为空!!!!!!!!!!!!!!!!!!")
return False
return True
def pb2go():
_insertList = []
_folderList = os.listdir(_basePath)
_goOutPath = _root + "/pb"
for folder in _folderList:
_toPath = _basePath + "/" + folder
# 是文件夹
if os.path.isdir(_toPath):
_fileList = os.listdir(_toPath)
# 当前目录下没有文件
if not _fileList:
continue
for file in _fileList:
# 不是pb文件
if not isPBFile(_toPath, file):
continue
command(_basePath, _goOutPath, folder, file)
# pb文件
else:
if isPBFile(_basePath, folder):
command(_basePath, _goOutPath, "", folder)
# time.sleep(5)
if __name__ == '__main__':
pb2go()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。