Python fabric.api.prefix() Examples

The following are 23 code examples of fabric.api.prefix(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module fabric.api , or try the search function .
Example #1
Source File: fabfile.py    From openprescribing with MIT License 6 votes vote down vote up
def call_management_command(command_name, environment, *args, **kwargs):
    """Invokes management command in environment.

    Prints output of command.
    """

    cmd = "python openprescribing/manage.py {}".format(command_name)

    for arg in args:
        cmd += " {}".format(shlex.quote(arg))

    for k, v in kwargs.items():
        cmd += " --{}={}".format(shlex.quote(k), shlex.quote(v))

    setup_env_from_environment(environment)
    with cd(env.path):
        with prefix("source .venv/bin/activate"):
            print(run(cmd)) 
Example #2
Source File: fabfile.py    From openprescribing with MIT License 6 votes vote down vote up
def log_deploy():
    current_commit = run("git rev-parse --verify HEAD")
    url = "https://github.com/ebmdatalab/openprescribing/compare/%s...%s" % (
        env.previous_commit,
        current_commit,
    )
    log_line = json.dumps(
        {
            "started_at": str(env.started_at),
            "ended_at": str(datetime.utcnow()),
            "changes_url": url,
        }
    )
    run("echo '%s' >> deploy-log.json" % log_line)
    with prefix("source .venv/bin/activate"):
        run(
            "python deploy/notify_deploy.py {revision} {url} {fab_env}".format(
                revision=current_commit, url=url, fab_env=env.environment
            )
        ) 
Example #3
Source File: fabfile.py    From ansible-mezzanine with MIT License 5 votes vote down vote up
def virtualenv():
    """
    Runs commands within the project's virtualenv.
    """
    with cd(env.venv_path):
        with prefix("source %s/bin/activate" % env.venv_path):
            yield 
Example #4
Source File: fabfile.py    From flask-blog with MIT License 5 votes vote down vote up
def source_virtualenv():
    with prefix("source {}".format(VENV_PATH)):
        yield 
Example #5
Source File: fabfile.py    From openprescribing with MIT License 5 votes vote down vote up
def clear_cloudflare():
    if env.environment != "production":
        return

    with cd(env.path):
        with prefix("source .venv/bin/activate"):
            run("python deploy/clear_cache.py") 
Example #6
Source File: fabfile.py    From openprescribing with MIT License 5 votes vote down vote up
def run_migrations():
    if env.environment == "production":
        with prefix("source .venv/bin/activate"):
            run("cd openprescribing/ && python manage.py migrate")
    else:
        warn("Refusing to run migrations in staging environment") 
Example #7
Source File: fabfile.py    From openprescribing with MIT License 5 votes vote down vote up
def deploy_static():
    bootstrap_environ = {"MAILGUN_WEBHOOK_USER": "foo", "MAILGUN_WEBHOOK_PASS": "foo"}
    with shell_env(**bootstrap_environ):
        with prefix("source .venv/bin/activate"):
            run(
                "cd openprescribing/ && " "python manage.py collectstatic -v0 --noinput"
            ) 
Example #8
Source File: fabfile.py    From openprescribing with MIT License 5 votes vote down vote up
def check_numbers():
    if env.environment != "production":
        return

    with prefix("source .venv/bin/activate"):
        run("cd openprescribing/ && python manage.py check_numbers") 
Example #9
Source File: fabfile.py    From openprescribing with MIT License 5 votes vote down vote up
def pip_install():
    if "requirements.txt" in env.changed_files:
        with prefix("source .venv/bin/activate"):
            run("pip install -r requirements.txt") 
Example #10
Source File: fabfile.py    From React-News-Board with GNU General Public License v2.0 5 votes vote down vote up
def source_virtualenv():
    with prefix("source {}".format(VENV_PATH)):
        yield 
Example #11
Source File: fabfile.py    From eshop with MIT License 5 votes vote down vote up
def manage(command=""):
    with prefix('source {0}venv/bin/activate && export DATABASE_URL={1}'.format(PROJECT_DIR, DATABASE_URL)):
        with cd(DJANGO_DIR):
            run('python manage.py {0}'.format(command)) 
Example #12
Source File: fabfile.py    From eshop with MIT License 5 votes vote down vote up
def install_requirements():
    with prefix('source {}/venv/bin/activate'.format(PROJECT_DIR)):
        run('pip install -r {}'.format(
            os.path.join(PROJECT_DIR, 'requirements.txt')
        )) 
Example #13
Source File: fabfile.py    From university-domains-list-api with MIT License 5 votes vote down vote up
def virtualenv():
    with cd(env.directory):
        with prefix(env.activate):
            yield 
Example #14
Source File: fabfile.py    From volontulo with MIT License 5 votes vote down vote up
def update():
    u"""Function defining all steps required to properly update application."""

    # Django app refresh:
    with cd('/var/www/volontulo'):
        run('git checkout -f {}'.format(env_vars[env.host_string]['git_branch']))
        run('git pull')

    with contextlib.nested(
        prefix('workon volontulo'),
        cd('/var/www/volontulo/backend'),
    ):
        run('pip install --upgrade -r requirements/base.txt')

    # Django site refresh:
    with contextlib.nested(
        cd('/var/www/volontulo/backend'),
        prefix('workon volontulo')
    ):
        run('python manage.py migrate --traceback')

    # Angular assets refresh:
    with contextlib.nested(
        prefix('nvm use {}'.format(NODE_VERSION)),
        cd('/var/www/volontulo/frontend'),
    ):
        run('npm install .')
        run('$(npm bin)/ng build --prod --env={}'.format(env.host_string))
        run('$(npm bin)/ng build --prod --env={} --app 1 --output-hashing=false'.format(env.host_string))
        run('./node_modules/.bin/webpack --config webpack.server.config.js --progress --colors')

    run('systemctl restart uwsgi.service')
    run('systemctl restart nginx')
    run('systemctl restart pm2-www-data.service') 
Example #15
Source File: fabfile.py    From Flask-Boost with MIT License 5 votes vote down vote up
def deploy():
    env.host_string = config.HOST_STRING
    with cd('/var/www/#{project}'):
        with shell_env(MODE='PRODUCTION'):
            run('git reset --hard HEAD')
            run('git pull')
            run('npm install')
            run('gulp')
            with prefix('source venv/bin/activate'):
                run('pip install -r requirements.txt')
                run('python manage.py db upgrade')
                run('python manage.py build')
            run('supervisorctl restart #{project}') 
Example #16
Source File: fabfile.py    From pasportaservo with GNU Affero General Public License v3.0 5 votes vote down vote up
def deploy(mode="full", remote="origin"):
    require("site", provided_by=[staging, prod])
    require("branch", provided_by=[staging, prod])

    with prefix(f"workon {env.site}"):
        checkout(remote, env.branch, False)
        pull(remote, env.branch, False)
        if mode == "full":
            requirements()
            updatestrings(False, _inside_env=True)
            updatestatic()
            migrate()
    if mode != "html":
        site_ctl(command="restart") 
Example #17
Source File: fabfile.py    From pasportaservo with GNU Affero General Public License v3.0 5 votes vote down vote up
def updatestrings(runlocal=True, _inside_env=False):
    command = "./manage.py compilemessages"
    if not runlocal or runlocal == "False":
        if _inside_env:
            run(command)
        else:
            with prefix(f"workon {env.site}"):
                run(command)
            site_ctl(command="restart")
    else:
        local(command) 
Example #18
Source File: fabfile.py    From openvpn-admin-ui with Apache License 2.0 5 votes vote down vote up
def act_virtualenv(name):
    with prefix("source ./"+name+"/bin/activate"):
        yield 
Example #19
Source File: fabfile.py    From learning-python with MIT License 5 votes vote down vote up
def deploy():
    env.host_string = config.HOST_STRING
    with cd('/var/www/test'):
        with shell_env(MODE='PRODUCTION'):
            run('git reset --hard HEAD')
            run('git pull')
            run('npm install')
            run('gulp')
            with prefix('source venv/bin/activate'):
                run('pip install -r requirements.txt')
                run('python manage.py db upgrade')
                run('python manage.py build')
            run('supervisorctl restart test') 
Example #20
Source File: fabfile.py    From kobo-predict with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def kobo_workon(_virtualenv_name):
    return prefix('kobo_workon %s' % _virtualenv_name) 
Example #21
Source File: fabfile.py    From crestify with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _git_update():
    with settings(sudo_user="crestify", shell='/bin/bash -c'):
        with cd('/home/crestify/crestify'):
            with prefix('source ../crestifyenv/bin/activate'):
                with settings(sudo_user='crestify', shell='/bin/bash -c'):
                    sudo('git pull')
                    sudo('pip install -r requirements.txt')
                    sudo('honcho run python main.py db upgrade') 
Example #22
Source File: fabfile.py    From crestify with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def run_migrations():
    with settings(sudo_user='crestify', shell='/bin/bash -c'):
        with cd('/home/crestify/crestify'):
            with prefix('source ../crestifyenv/bin/activate'):
                sudo('honcho run python main.py db upgrade')  # Run initial migrations 
Example #23
Source File: fabfile.py    From crestify with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def config_environment():
    sudo('apt-get -y install git screen')
    sudo('adduser crestify --disabled-password --gecos GECOS')
    sudo('locale-gen en_US.UTF-8')
    with settings(sudo_user='crestify', shell='/bin/bash -c'):
        with cd('/home/crestify'):
            sudo('git clone https://github.com/crestify/crestify.git crestify')
            sudo('virtualenv crestifyenv')
            with prefix('source crestifyenv/bin/activate'):
                sudo('pip install -r crestify/requirements.txt')