def ensure(venv_dir, sub_dirs=None, user_mode=True): """ 确保虚拟环境存在 :: .. _virtual environment: http://www.virtualenv.org/ """ if not venv_dir.startswith("/"): if "VIRTUALENV_PREFIX" in env: venv_dir = path.join(env.VIRTUALENV_PREFIX, venv_dir) else: user_home = run("USER_HOME=$(eval echo ~${SUDO_USER}) && echo ${USER_HOME}") venv_dir = path.join(user_home, "w", venv_dir) if is_virtualenv(venv_dir): return if package.is_virtualenv_installed_in_system(): virtualenv_bin = "virtualenv" else: virtualenv_bin = "~/.local/bin/virtualenv" command = '%(virtualenv_bin)s --quiet "%(venv_dir)s"' % locals() run(command) if not sub_dirs: sub_dirs = ["logs", "etc", "tmp"] if "VIRTUALENV_SUB_DIRS" in env: sub_dirs = list(set(sub_dirs + env.VIRTUALENV_SUB_DIRS)) for sub_dir in sub_dirs: fs.ensure_dir(path.join(venv_dir, sub_dir))
def ensure(venv_dir, sub_dirs=None, user_mode=True): """ 确保虚拟环境存在 :: .. _virtual environment: http://www.virtualenv.org/ """ if not venv_dir.startswith('/'): if 'VIRTUALENV_PREFIX' in env: venv_dir = path.join(env.VIRTUALENV_PREFIX, venv_dir) else: user_home = run( 'USER_HOME=$(eval echo ~${SUDO_USER}) && echo ${USER_HOME}') venv_dir = path.join(user_home, 'w', venv_dir) if is_virtualenv(venv_dir): return if package.is_virtualenv_installed_in_system(): virtualenv_bin = 'virtualenv' else: virtualenv_bin = '~/.local/bin/virtualenv' command = '%(virtualenv_bin)s --quiet "%(venv_dir)s"' % locals() run(command) if not sub_dirs: sub_dirs = ['logs', 'etc', 'tmp'] if 'VIRTUALENV_SUB_DIRS' in env: sub_dirs = list(set(sub_dirs + env.VIRTUALENV_SUB_DIRS)) for sub_dir in sub_dirs: fs.ensure_dir(path.join(venv_dir, sub_dir))
def ensure(venv_dir, sub_dirs=None, user_mode=True): """ 确保虚拟环境存在 :: .. _virtual environment: http://www.virtualenv.org/ """ if not venv_dir.startswith('/'): if 'VIRTUALENV_PREFIX' in env: venv_dir = path.join(env.VIRTUALENV_PREFIX, venv_dir) else: user_home = run('USER_HOME=$(eval echo ~${SUDO_USER}) && echo ${USER_HOME}') venv_dir = path.join(user_home, 'w', venv_dir) if is_virtualenv(venv_dir): return if package.is_virtualenv_installed_in_system(): virtualenv_bin = 'virtualenv' else: virtualenv_bin = '~/.local/bin/virtualenv' command = '%(virtualenv_bin)s --quiet "%(venv_dir)s"' % locals() run(command) if not sub_dirs: sub_dirs = ['logs', 'etc', 'tmp'] if 'VIRTUALENV_SUB_DIRS' in env: sub_dirs = list(set(sub_dirs + env.VIRTUALENV_SUB_DIRS)) for sub_dir in sub_dirs: fs.ensure_dir(path.join(venv_dir, sub_dir))
def init_project(project, template='default'): """初始化本地项目 此方法不需要连接git服务器 """ if project is None: project_dir = path.abspath('.') template = 'init' project = '' params = {'project_name': project} else: project_dir = path.abspath(project) fs.ensure_dir(project, in_local=True) params = {'project_name': project} build_structure(project, project_dir, params, template)
def ensure_rq(venv_dir): if virtualenv.is_virtualenv(venv_dir): return if package.is_virtualenv_installed_in_system(): virtualenv_bin = 'virtualenv' else: virtualenv_bin = '~/.local/bin/virtualenv' print virtualenv_bin command = '%(virtualenv_bin)s --quiet "%(venv_dir)s"' % locals() run(command) sub_dirs = ['logs', 'etc', 'tmp'] if 'VIRTUALENV_SUB_DIRS' in env: sub_dirs = list(set(sub_dirs + env.VIRTUALENV_SUB_DIRS)) for sub_dir in sub_dirs: fs.ensure_dir(path.join(venv_dir, sub_dir))
def build_structure(project, dst, params, template='default'): """ 拷贝工程打包及fab文件到工程 """ dst = dst.rstrip('/') template_dir = path.join(settings.PROJECT_ROOT, 'templates', template) for root, dirs, files in os.walk(template_dir): for name in files: if name.endswith('.tpl'): src = path.join(root, name) dst_filename = src.replace(template_dir, dst).rstrip('.tpl').replace('__project__', project) dst_dir = os.path.dirname(dst_filename) fs.ensure_dir(dst_dir, in_local=True) content = open(src).read().decode('utf-8') if not name.endswith('.conf.tpl'): content = string.Template(content).safe_substitute(**params) open(dst_filename, 'w').write(content.encode('utf-8'))
def init_project(project, template='default'): """初始化本地项目 此方法不需要连接git服务器 """ if project is None: project_dir = path.abspath('.') template = 'server_init' project = '' params = { 'project_name': project } else: project_dir = path.abspath(project) fs.ensure_dir(project, in_local=True) params = { 'project_name': project } build_structure(project, project_dir, params, template)
def build_structure(project, dst, params, template='default'): """ 拷贝工程打包及fab文件到工程 """ dst = dst.rstrip('/') template_dir = path.join(settings.PROJECT_ROOT, 'templates', template) for root, dirs, files in os.walk(template_dir): for name in files: if name.endswith('.tpl'): src = path.join(root, name) dst_filename = src.replace(template_dir, dst).rstrip('.tpl').replace( '__project__', project) dst_dir = os.path.dirname(dst_filename) fs.ensure_dir(dst_dir, in_local=True) content = open(src).read().decode('utf-8') if not name.endswith('.conf.tpl'): content = string.Template(content).safe_substitute( **params) open(dst_filename, 'w').write(content.encode('utf-8'))