def uncompress(cls, fullname, parent_dir, overwrite=True): parent_dir = parent_dir if parent_dir else PKG_DIR src = os.path.join(PKG_CACHE_DIR, fullname) if not os.path.exists(src): raise NotExistsError('The cache of '.format(fullname)) # ensure make target_dir for dir_name in [parent_dir, PKG_UNCOMPRESS_DIR]: if not nfs.exists(dir_name): nfs.makedirs(dir_name, 0750) # clear PKG_UNCOMPRESS_DIR for name in os.listdir(PKG_UNCOMPRESS_DIR): nfs.remove(os.path.join(PKG_UNCOMPRESS_DIR, name)) # extract file with tarfile.open(src) as tar: tar.extractall(PKG_UNCOMPRESS_DIR) extract_path = os.path.join(PKG_UNCOMPRESS_DIR, os.listdir(PKG_UNCOMPRESS_DIR)[0]) pkg_yml_path = os.path.join(extract_path, PKG_YAML_NAME) pkg_info = cls.get_info(pkg_yml_path, fullname) dst = os.path.join(parent_dir, pkg_info['name']) if not overwrite and os.path.exists(dst): return dst nfs.rename(extract_path, dst, overwrite) return dst, pkg_info
def disable(cls): if nfs.exists(cls.enable_conf): nfs.rename(cls.enable_conf, cls.disable_conf) yield cls.rm_openresty() if not nfs.exists(cls.disable_conf): raise MessageError('Disable openresty failed !')
def deploy_dispatcher(self): with cd(self.project_name): execute(['../node/bin/node', '../node/bin/yarn']) execute(['../node/bin/node', '../node/lib/node_modules/npm/bin/npm-cli.js', 'run', 'build']) if nfs.exists('dispatcher'): nfs.remove('dispatcher') nfs.rename('dist', 'dispatcher') cmd = 'su uyun -c "pm2 delete all"' excutor_cmd(cmd) for file in ['node_modules', 'bin', 'scripts', 'install.sh', 'uninstall.sh', 'check_status.sh', 'dispatcher']: local_path = os.path.join(self.project_name, file) server_path = INSTALL_DIR[self.project_name] scp_upload_file(local_path, server_path) cmd = 'cd {} && su uyun -c "pm2 start process.json"'.format( INSTALL_DIR[self.project_name]) excutor_cmd(cmd)
def maybe_download_python(): system = platform.system.lower() cwd = os.getcwd() if WINDOWS: python = fs.join(cwd, 'embedded/python.exe') pip = fs.join(cwd, 'embedded/Scripts/pip.exe') else: python = fs.join(cwd, 'embedded/bin/python') pip = fs.join(cwd, 'embedded/bin/pip') if not fs.exists(fs.join(cwd, 'embedded')): python_name = 'python-{}-{}.{}'.format(system, platform.cpu, POSTFIX.get(system, 'tgz')) python_url = PYTHON_TEMPLATE_URL.format(python_name) download(python_url, python_name) fs.uncompress(python_name) fs.rename('python-{}-{}'.format(system, platform.cpu), 'embedded') return python, pip
def enable(cls): if nfs.exists(cls.disable_conf): nfs.rename(cls.disable_conf, cls.enable_conf) if not nfs.exists(cls.enable_conf): raise MessageError('Enable openresty failed !') yield cls.reload()