def pub_init(self): """ 安装,需要手动启动 """ # _ssh.rm(PUB_PATH) # _ssh.mkdir(PUB_PATH) # self.update_svr() #bin bin_file = _ssh.join(BIN_PATH, GAME_NAME) bin_cmd = '%s %s $*' % (PY_BIN, GAME_MAIN) _ssh.mk_sh(bin_file, bin_cmd) #ln -s _ssh.ln(PY_BIN, _ssh.join(BIN_PATH, 'tdpy'))
def _up_fab(self): """ 上传fabric脚本 """ if getattr(self, '_up_fabed', False): return self._up_fabed = True fab_local = path.join(dist_path, 'fabfiles', 'server.py') fab_ssh = _ssh.join(DIST_PATH, 'fabfile.py') _ssh.put(fab_local, fab_ssh) util_local = path.join(dist_path, 'fab_util.py') util_ssh = _ssh.join(DIST_PATH, 'fab_util.py') _ssh.put(util_local, util_ssh)
def update_svr(self, ver=None): """ 上传新的服务端压缩包 """ _ssh.mkdir(PUB_PATH) _ssh.mkdir(CFG_PATH) if ver: name = '%s%s' % (lastest_back_prefix, ver) else: name = lastest_file with _ssh.cd(PUB_PATH): _ssh.rm(lastest_file) _ssh.put('config/%s' % cfg_config, _ssh.join(CFG_PATH, cfg_config)) _ssh.put('%s/%s' % (pub_name, name), _ssh.join(PUB_PATH, lastest_file)) _ssh.rm(env_name) _ssh.rm(svr_name) _ssh.run('tar -xzf %s' % lastest_file)
def dist_pkg(self): """ 安装py模块 """ easy_install = _ssh.join(ENV_PATH, 'bin', 'easy_install') #easy_install = _ssh.join(ENV_PATH, 'bin', 'pip') cmd = '%s -f %s %s' for m in self.PY_PKGS: _ssh.run(cmd % (easy_install, MODULES_FOLDER, m))
def up_svr(self): """ 更新服务器代码 """ self.up_svn_info() corelib = ('lib', 'corelib') _corelib_pyx = corelib + ('_corelib.pyx', ) #编译pyx _tool.cython(path.join(svr_path, *_corelib_pyx)) # _tool.compile_pyc(svr_path) rpath = GAME_PATH if _ssh.exists(rpath): _ssh.rm(rpath) _ssh.mkdir(rpath) _ssh.mkdir(PUB_PATH) exclude = ('.hg/', '.svn/', 'pkg/', 'runtime/', '*.py', '*.log', '*.profile', '*.pyx', '*/build/', '*.so', '*.pyd', '.*', 'dist/', '**local_config.pyc', '*.rar') _ssh.rsync_project(local_dir=path.join(svr_path, '*'), remote_dir=rpath+'/', delete=True, exclude=exclude, extra_opts='--delete-excluded') with _ssh.cd(DIST_PATH): #编译 with _ssh.cd(_ssh.join(DIST_PATH, 'svr', *corelib)): _ssh.run('%s setup.pyc build_ext --inplace' % PY_BIN) # 打包 _ssh.run('tar -czf %s/%s ./%s ./%s' % (pub_name, lastest_file, env_name, svr_name)) #备份处理 _ssh.run('cp %s/%s %s/%s%s' % (pub_name, lastest_file, pub_name, lastest_back_prefix, _tool.strftime()))
#!/usr/bin/env python # -*- coding:utf-8 -*- from os import path from fab_util import (_tool, _ssh, _init_, _load_cfg, lastest_back_prefix, lastest_file, env_name, svr_name, pub_name, cfg_config, GAME_NAME, HOME_PATH, BIN_PATH, PUB_PATH, ) dist_path = path.abspath(path.dirname(__file__)) #ssh 目录 CFG_PATH = _ssh.join(PUB_PATH, 'config') ENV_PATH = _ssh.join(PUB_PATH, env_name) GAME_PATH = _ssh.join(PUB_PATH, svr_name) PY_BIN = _ssh.join(ENV_PATH, 'bin', 'python') GAME_MAIN = _ssh.join(GAME_PATH, 'main.pyc') class _Publish(object): """ 执行实际发布动作 """ def update_svr(self, ver=None): """ 上传新的服务端压缩包 """ _ssh.mkdir(PUB_PATH) _ssh.mkdir(CFG_PATH) if ver: name = '%s%s' % (lastest_back_prefix, ver) else: name = lastest_file with _ssh.cd(PUB_PATH): _ssh.rm(lastest_file)
def web_pkg(self): """ 安装web需要的模块 """ easy_install = _ssh.join(ENV_PATH, 'bin', 'pip install ') cmd = '%s -f %s %s' for m in self.WEB_PY_PKGS: _ssh.run(cmd % (easy_install, MODULES_FOLDER, m))
# -*- coding:utf-8 -*- import os from os import path from fab_util import (_tool, _ssh, _init_, _load_cfg, lastest_back_prefix, lastest_file, env_name, svr_name, pub_name, cfgs, USER_NAME, GAME_NAME, HOME_PATH, BIN_PATH, DIST_PATH, ) #本地路径 dist_path = path.dirname(path.abspath(__file__)) app_path = path.dirname(dist_path) svr_path = path.join(app_path, 'code') #发布机路径 CFG_PATH = _ssh.join(DIST_PATH, 'config') GAME_PATH = _ssh.join(DIST_PATH, svr_name) ENV_PATH = _ssh.join(DIST_PATH, env_name) PY_BIN = _ssh.join(ENV_PATH, 'bin', 'python') GAME_MAIN = _ssh.join(GAME_PATH, 'main.pyc') MODULES_FOLDER = _ssh.join(HOME_PATH, '%smodules'%GAME_NAME) PUB_PATH = _ssh.join(DIST_PATH, pub_name) class _Dist(object): """ 发布机 """ DEBIAN_PKGS =["python-setuptools", "python-pip", "python-virtualenv", "libevent-1.4-2", ] PY_PKGS = [
lastest_back_prefix, lastest_file, env_name, svr_name, pub_name, cfg_config, GAME_NAME, HOME_PATH, BIN_PATH, PUB_PATH, ) dist_path = path.abspath(path.dirname(__file__)) #ssh 目录 CFG_PATH = _ssh.join(PUB_PATH, 'config') ENV_PATH = _ssh.join(PUB_PATH, env_name) GAME_PATH = _ssh.join(PUB_PATH, svr_name) PY_BIN = _ssh.join(ENV_PATH, 'bin', 'python') GAME_MAIN = _ssh.join(GAME_PATH, 'main.pyc') class _Publish(object): """ 执行实际发布动作 """ def update_svr(self, ver=None): """ 上传新的服务端压缩包 """ _ssh.mkdir(PUB_PATH) _ssh.mkdir(CFG_PATH) if ver: name = '%s%s' % (lastest_back_prefix, ver) else: