示例#1
0
def is_virtualenv_installed_in_user():
    """
    检查virtualenv是否在系统目录安装
    """

    with settings(warn_only=True):
        return exists('~/.local/bin/virtualenv')
示例#2
0
def kill_by_name(name):
    """
    停止指定特征的进程
    """

    with settings(warn_only=True):
        run("ps aux | grep '%s' | grep -v 'grep' | awk '{print $2}' | xargs kill -9" % name)
示例#3
0
def is_virtualenv_installed_in_user():
    """
    检查virtualenv是否在系统目录安装
    """

    with settings(warn_only=True):
        return exists('~/.local/bin/virtualenv')
示例#4
0
def is_virtualenv_installed_in_system():
    """
    检查virtualenv是否在系统目录安装
    """

    with settings(warn_only=True):
        return 'no virtualenv' not in run('which virtualenv') or \
            'which' not in run('which virtualenv')
示例#5
0
def kill_by_name(name):
    """
    停止指定特征的进程
    """

    with settings(warn_only=True):
        run("ps aux | grep '%s' | grep -v 'grep' | awk '{print $2}' | xargs kill -9"
            % name)
示例#6
0
def is_virtualenv_installed_in_system():
    """
    检查virtualenv是否在系统目录安装
    """

    with settings(warn_only=True):
        return 'no virtualenv' not in run('which virtualenv') or \
            'which' not in run('which virtualenv')
示例#7
0
def _supervisor_command(command, venv_dir=None):
    if venv_dir:
        with virtualenv.activate(venv_dir):
            _supervisor_command(command)

    if not 'CURRENT_VIRTUAL_ENV_DIR' in env:
        raise Exception(u'只可以在虚拟环境安装Python包')

    venv_dir = env.CURRENT_VIRTUAL_ENV_DIR

    # 停止supervisor管理的进程
    with settings(warn_only=True), cd(venv_dir):
        run('bin/supervisorctl -c etc/supervisord.conf ' + command)
示例#8
0
def _supervisor_command(command, venv_dir=None):
    if venv_dir:
        with virtualenv.activate(venv_dir):
            _supervisor_command(command)

    if not 'CURRENT_VIRTUAL_ENV_DIR' in env:
        raise Exception(u'只可以在虚拟环境安装Python包')

    venv_dir = env.CURRENT_VIRTUAL_ENV_DIR

    # 停止supervisor管理的进程
    with settings(warn_only=True), cd(venv_dir):
        run('bin/supervisorctl -c etc/supervisord.conf ' + command)
示例#9
0
def start(venv_dir=None):
    """重启指定虚拟环境的supervisor"""

    if venv_dir:
        with virtualenv.activate(venv_dir):
            start()

    if not 'CURRENT_VIRTUAL_ENV_DIR' in env:
        raise Exception(u'只可以在虚拟环境安装Python包')

    venv_dir = env.CURRENT_VIRTUAL_ENV_DIR

    with settings(warn_only=True), cd(venv_dir):
        # 停止supervisor管理的进程
        run('bin/supervisord -c etc/supervisord.conf ')
示例#10
0
def is_installed(package):
    """检查Python包是否被安装

    注意:只能在虚拟Python环境中执行
    """

    if not 'CURRENT_VIRTUAL_ENV_DIR' in env:
        raise Exception(u'只可以在虚拟环境安装Python包')
    venv_dir = env.CURRENT_VIRTUAL_ENV_DIR

    with settings(warn_only=True):
        res = run('%(venv_dir)s/bin/pip freeze' % locals())
    packages = [line.split('==')[0].lower() for line in res.splitlines()]

    return package.lower() in packages
示例#11
0
def start(venv_dir=None):
    """重启指定虚拟环境的supervisor"""

    if venv_dir:
        with virtualenv.activate(venv_dir):
            start()

    if not 'CURRENT_VIRTUAL_ENV_DIR' in env:
        raise Exception(u'只可以在虚拟环境安装Python包')

    venv_dir = env.CURRENT_VIRTUAL_ENV_DIR

    with settings(warn_only=True), cd(venv_dir):
        # 停止supervisor管理的进程
        run('bin/supervisord -c etc/supervisord.conf ')
示例#12
0
def is_installed(package):
    """检查Python包是否被安装

    注意:只能在虚拟Python环境中执行
    """

    if not 'CURRENT_VIRTUAL_ENV_DIR' in env:
        raise Exception(u'只可以在虚拟环境安装Python包')
    venv_dir = env.CURRENT_VIRTUAL_ENV_DIR

    with settings(warn_only=True):
        res = run('%(venv_dir)s/bin/pip freeze' % locals())
    packages = [line.split('==')[0].lower() for line in res.splitlines()]

    return package.lower() in packages
示例#13
0
def sync(*packages):
    """从http://pypi.python.org同步包

    用法:
        fab pypi.sync:django==1.3,tornado
    """

    config.check('PYPI_HOST',
                 'PYPI_USER',
                 'PYPI_ROOT')

    with settings(host_string=env.PYPI_HOST, user=env.PYPI_USER):
        cmd = ["pip", "-q", "install", "--no-deps", "-i", "https://pypi.python.org/simple",
               "-d", env.PYPI_ROOT,
               ' '.join(packages)]

        run(" ".join(cmd))
示例#14
0
def sync(*packages):
    """从http://pypi.python.org同步包

    用法:
        fab pypi.sync:django==1.3,tornado
    """

    config.check('PYPI_HOST', 'PYPI_USER', 'PYPI_ROOT')

    with settings(host_string=env.PYPI_HOST, user=env.PYPI_USER):
        cmd = [
            "pip", "-q", "install", "--no-deps", "-i",
            "https://pypi.python.org/simple", "-d", env.PYPI_ROOT,
            ' '.join(packages)
        ]

        run(" ".join(cmd))