1 Star 0 Fork 11

张宇/rpc-repo

forked from Plato/rpc-repo 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
python_pub_driver.py 7.23 KB
一键复制 编辑 原始数据 按行查看 历史
CloudGuan 提交于 2022-06-14 14:49 . bug: remove init.py while pub service
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os
import shutil
from distutils import dir_util
import json
import platform
import sys
import subprocess
from pub_driver import Publisher
from option import Options
DEFAULT_CONFIG_FILE = '''
;
; 容器开启的监听器,为一个数组,可以同时开启多个
; host={"127.0.0.1:6888","127.0.0.1:6900"}
;
listener = {
host = ("127.0.0.1:*")
}
;
; 服务发现配置
; 目前只支持zookeeper
;
service_finder = {
type = "zookeeper"
hosts = "127.0.0.1:2181"
}
rpc_root_dir = "{config_path}"
;
; 容器socket缓冲区大小
;
box_channel_recv_buffer_len = `32*K`
;
; 连接到其他容器的超时时间,单位毫秒
;
connect_other_box_timeout = 2000
;
; 连接到服务发现服务的超时时间,单位毫秒
;
service_finder_connect_timeout = 2000
'''
INIT_FILE = '''
import os
file_dir = os.path.split(os.path.realpath(__file__))[0]
import sys
sys.path.append(file_dir)
import plato
'''
class Publisher_python(Publisher):
def init(self):
pass
def publish(self, idl_name, service_name, out_dir, orig_dir):
self.orig_dir = orig_dir
python_dir = os.path.join(out_dir, 'python')
out_dir = os.path.join(out_dir, 'python/lib')
out_sdk_dir = os.path.join(python_dir, 'lib', 'sdk')
if not os.path.exists(out_dir):
# 输出目录不存在则建立
os.makedirs(out_dir)
if not os.path.exists(out_sdk_dir):
os.makedirs(out_sdk_dir)
if platform.system() == "Windows":
if os.path.exists(os.path.join('./tmp/service-box/src/python_rpc/bin/debug', 'rpc_d.pyd')):
shutil.copyfile(os.path.join('./tmp/service-box/src/python_rpc','bin', 'debug', 'rpc_d.pyd'), os.path.join(out_dir, 'rpc_d.pyd'))
shutil.copyfile(os.path.join('./tmp/service-box/src/python_rpc','bin','release', 'rpc.pyd'), os.path.join(out_dir, 'rpc.pyd'))
if os.path.exists(os.path.join('./tmp/service-box/src/python_rpc/bin/debug', 'rpc_sdk_d.pyd')):
shutil.copyfile(os.path.join('./tmp/service-box/src/python_rpc','bin', 'debug', 'rpc_sdk_d.pyd'), os.path.join(out_sdk_dir, 'rpc_d.pyd'))
shutil.copyfile(os.path.join('./tmp/service-box/src/python_rpc','bin', 'release', 'rpc_sdk.pyd'), os.path.join(out_sdk_dir, 'rpc.pyd'))
if os.path.exists(os.path.join('./tmp/service-box/src/python_log/bin/debug', 'log_d.pyd')):
shutil.copyfile(os.path.join('./tmp/service-box/src/python_log','bin', 'debug', 'log_d.pyd'), os.path.join(out_dir, 'log_d.pyd'))
shutil.copyfile(os.path.join('./tmp/service-box/src/python_log','bin','release', 'log.pyd'), os.path.join(out_dir, 'log.pyd'))
if os.path.exists(os.path.join('./tmp/service-box/src/python_config/bin/debug', 'config_d.pyd')):
shutil.copyfile(os.path.join('./tmp/service-box/src/python_config','bin', 'debug', 'config_d.pyd'), os.path.join(out_dir, 'config_d.pyd'))
shutil.copyfile(os.path.join('./tmp/service-box/src/python_config','bin','release', 'config.pyd'), os.path.join(out_dir, 'config.pyd'))
else:
if os.path.exists(os.path.join('./tmp/service-box/src/python_rpc', 'bin', 'librpc.so')):
shutil.copyfile(os.path.join('./tmp/service-box/src/python_rpc', 'bin','librpc.so'), os.path.join(out_dir, 'rpc.so'))
if os.path.exists(os.path.join('./tmp/service-box/src/python_rpc', 'bin', 'librpc_d.so')):
shutil.copyfile(os.path.join('./tmp/service-box/src/python_rpc', 'bin','librpc_d.so'), os.path.join(out_dir, 'rpc_d.so'))
if os.path.exists(os.path.join('./tmp/service-box/src/python_rpc', 'bin', 'librpc_sdk.so')):
shutil.copyfile(os.path.join('./tmp/service-box/src/python_rpc', 'bin', 'librpc_sdk.so'), os.path.join(out_sdk_dir, 'rpc.so'))
if os.path.exists(os.path.join('./tmp/service-box/src/python_config', 'bin', 'libconfig.so')):
shutil.copyfile(os.path.join('./tmp/service-box/src/python_config', 'bin','libconfig.so'), os.path.join(out_dir, 'config.so'))
shutil.copyfile(os.path.join('./tmp/service-box/src/python_config', 'bin','libconfig_d.so'), os.path.join(out_dir, 'config_d.so'))
if os.path.exists(os.path.join('./tmp/service-box/src/python_log', 'bin', 'liblog.so')):
shutil.copyfile(os.path.join('./tmp/service-box/src/python_log', 'bin','liblog.so'), os.path.join(out_dir, 'log.so'))
shutil.copyfile(os.path.join('./tmp/service-box/src/python_log', 'bin','liblog_d.so'), os.path.join(out_dir, 'log_d.so'))
shutil.copyfile('./tmp/rpc-backend-python3/plato.py', os.path.join(out_dir, 'plato.py'))
self.orig_root = os.path.join(orig_dir, 'usr', 'python', 'lib', 'rpc_config')
for cur_service_name in os.listdir(self.orig_root):
path = os.path.join(self.orig_root, cur_service_name)
if os.path.exists(path) and os.path.isfile(path):
if idl_name != None:
if idl_name + ".py" == cur_service_name:
self.pub_service(idl_name, service_name, python_dir)
else:
self.pub_service(idl_name, os.path.basename(cur_service_name).split('.')[0], python_dir)
def pub_service(self, idl_name, service_name, out_dir):
config_dir = os.path.join(out_dir, 'lib', 'config')
rpc_config_dir = os.path.join(out_dir, 'lib', 'rpc_config')
if not os.path.exists(config_dir):
os.makedirs(config_dir)
if not os.path.exists(rpc_config_dir):
os.makedirs(rpc_config_dir)
config_root = os.path.join(self.orig_dir, 'usr', 'python', 'lib', 'config')
shutil.copy(os.path.join(config_root, idl_name+'.idl.protobuf.json'), os.path.join(config_dir, idl_name+'.idl.protobuf.json'))
shutil.copy(os.path.join(config_root, idl_name+'.service.proto'), os.path.join(config_dir, idl_name+'.service.proto'))
shutil.copy(os.path.join(self.orig_dir, 'usr', 'python', 'lib', 'rpc_config', idl_name + '.py'), os.path.join(out_dir, 'lib', 'rpc_config', idl_name + '.py'))
self.create_config_file(config_dir)
self.create_init_file(os.path.join(out_dir, 'lib'))
for file_name in os.listdir(os.path.join(self.orig_dir, 'usr', 'python')):
if file_name == '__pycache__' or file_name.startswith('.') or file_name == "lib":
continue
path = os.path.join(os.path.join(self.orig_dir, 'usr', 'python'), file_name)
if os.path.exists(path) and os.path.isfile(path):
shutil.copy(path, os.path.join(out_dir, file_name))
else:
if os.path.exists(os.path.join(out_dir, file_name)):
shutil.rmtree(os.path.join(out_dir, file_name))
shutil.copytree(path, os.path.join(out_dir, file_name))
def check(self):
return True
def create_config_file(self, to_dir):
open(os.path.join(to_dir, "config.default.cfg"), "w").write(DEFAULT_CONFIG_FILE.replace('{config_path}', to_dir))
def create_init_file(self, to_dir):
open(os.path.join(to_dir, '__init__.py'), "w").write(INIT_FILE)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/zy704599894/rpc-repo.git
[email protected]:zy704599894/rpc-repo.git
zy704599894
rpc-repo
rpc-repo
v0.3.0-alpha

搜索帮助