1 Star 0 Fork 11

DengSir/rpc-repo

forked from Plato/rpc-repo 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
go_pub_driver.py 3.08 KB
一键复制 编辑 原始数据 按行查看 历史
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os
import shutil
import json
import platform
import sys
import subprocess
from pub_driver import Publisher
from option import Options
default_config='''
name: service-box-go
listener:
- host : "0.0.0.0:7999" # 监听端口
expose_host: "127.0.0.1:7999" #注册端口
service_finder:
type: zookeeper
host: 192.168.82.22:2181
logger:
level: debug
mode: ["console", "file"]
outfile: service-box.log
style: console
'''
class Publisher_go(Publisher):
def init(self):
self.cwd = os.getcwd().replace('\\', '/')
def publish(self, idl_name, service_name, out_dir, orig_dir):
if platform.system() == "Windows":
print("暂不支持windows版本,请在linux上使用此功能")
return
print("========================= Start Pub Go =========================")
print("out_dir: ", out_dir)
print("cur_dir:", os.getcwd())
print("root_dir:", self.cwd)
if not os.path.exists(out_dir):
# 输出目录不存在则建立
os.makedirs(out_dir)
#检查中间文件是否正常生成
box_dir = '%s/tmp/pkg/servicebox'%(self.cwd)
if not os.path.exists(box_dir):
print("请运行编译命令, 编译idl, 在进行发布")
return False
os.chdir(box_dir)
#尝试编译-检查依赖文件
cmd = subprocess.Popen(["go", "mod", "tidy"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
ret = cmd.communicate()
if cmd.returncode != 0:
print(ret[1].decode("utf-8"))
return False
#尝试编译
cmd = subprocess.Popen(["go", "build"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
ret = cmd.communicate()
if cmd.returncode != 0:
print(ret[1].decode("utf-8"))
return False
#创建配置
self.create_config_file(out_dir)
print(os.getcwd())
if platform.system() == "Windows":
wfile = '%s/servicebox.exe'%(out_dir)
if os.path.exists(wfile):
os.remove(wfile)
shutil.copyfile("./servicebox.exe", wfile)
else:
ufile = '%s/servicebox'%(out_dir)
if os.path.exists(ufile):
os.remove(ufile)
shutil.copyfile("./servicebox", ufile)
print(" ========================= End Pub Go =========================")
return True
def check(self):
return True
def pub_service(self, idl_name, service_name, out_dir):
pass
def copy_file_windows(self, from_dir, to_dir, prefix, suffix, service_name):
pass
def copy_file_linux(self, from_dir, to_dir, prefix, suffix, service_name):
pass
def create_config_file(self, to_dir):
cfg_file = '%s/default.yaml'%(to_dir)
if os.path.exists(cfg_file):
os.remove(cfg_file)
with open(cfg_file, "w") as f:
f.write(default_config)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/DengSir/rpc-repo.git
[email protected]:DengSir/rpc-repo.git
DengSir
rpc-repo
rpc-repo
v0.3.0-alpha

搜索帮助