代码拉取完成,页面将自动刷新
同步操作将从 Plato/rpc-repo 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/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)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。