本文整理汇总了Python中fabric.context_managers.cd方法的典型用法代码示例。如果您正苦于以下问题:Python context_managers.cd方法的具体用法?Python context_managers.cd怎么用?Python context_managers.cd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fabric.context_managers
的用法示例。
在下文中一共展示了context_managers.cd方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_code_on_server
# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import cd [as 别名]
def update_code_on_server(app_env):
app_path = '/var/www/%s/%s' % (APP_NAME, app_env)
out = run('ls -t %s | grep -v current | grep daimaduan.com' % app_path)
versions = [i.strip() for i in out.split("\n")]
# figure out the release name and version
dist = local('python setup.py --fullname', capture=True).strip()
version = local('python setup.py --version', capture=True).strip()
# upload the source tarball to the temporary folder on the server
put('dist/%s.tar.gz' % dist, '%s/%s.tar.gz' % (app_path, dist))
with cd(app_path):
run('tar xzf %s.tar.gz' % dist)
with cd('%s/%s' % (app_path, dist)):
run('%s/venv/bin/python setup.py develop > /dev/null 2>&1' % app_path)
run('rm -f %s/current' % app_path)
run('ln -s %s/%s/daimaduan %s/current' % (app_path, dist, app_path))
run('cp %s/shared/custom_settings.py %s/current' % (app_path, app_path))
run('sed "s/VERSION.*/VERSION = \'%s\'/" -i %s/current/custom_settings.py' % (version, app_path))
run('sed "s/DEPLOYED_AT.*/DEPLOYED_AT = \'%s\'/" -i %s/current/custom_settings.py' % (
datetime.now().strftime('%Y-%m-%d %H:%M:%S'), app_path))
run('cp %s/shared/deploy.py %s/current' % (app_path, app_path))
# touching uwsgi ini file will reload this app
sudo('touch /etc/uwsgi.d/daimaduan_%s.ini' % app_env)
run('rm -f %s/%s.tar.gz' % (app_path, dist))
return app_path, dist, versions
示例2: rollback_formplayer
# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import cd [as 别名]
def rollback_formplayer():
build_dir = os.path.join(env.code_current, FORMPLAYER_BUILD_DIR)
builds = _get_old_formplayer_builds(build_dir)
if not builds:
utils.abort('No formplayer builds to rollback to.')
rollback_build = builds[0]
if not console.confirm('Confirm rollback to "{}"'.format(rollback_build), default=False):
utils.abort('Action aborted.')
with cd(build_dir):
sudo('ln -sfn {build_dir}/{rollback} {build_dir}/current'.format(
build_dir=build_dir,
rollback=rollback_build
))
示例3: _clone_code_from_local_path
# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import cd [as 别名]
def _clone_code_from_local_path(from_path, to_path, run_as_sudo=True):
cmd_fn = sudo if run_as_sudo else run
git_local_submodule_config = [
'git config {} {}'.format(submodule_config.key, submodule_config.value)
for submodule_config in _get_local_submodule_urls(from_path)
]
git_remote_submodule_config = [
'git config {} {}'.format(submodule_config.key, submodule_config.value)
for submodule_config in _get_remote_submodule_urls(from_path)
]
with cd(from_path):
cmd_fn('git clone {}/.git {}'.format(
from_path,
to_path
))
with cd(to_path):
cmd_fn('git config receive.denyCurrentBranch updateInstead')
cmd_fn(' && '.join(git_local_submodule_config))
cmd_fn('git submodule update --init --recursive')
cmd_fn(' && '.join(git_remote_submodule_config))
示例4: record_successful_deploy
# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import cd [as 别名]
def record_successful_deploy():
start_time = datetime.strptime(env.deploy_metadata.timestamp, DATE_FMT)
delta = datetime.utcnow() - start_time
with cd(env.code_current):
env.deploy_metadata.tag_commit()
sudo((
'%(virtualenv_current)s/bin/python manage.py '
'record_deploy_success --user "%(user)s" --environment '
'"%(environment)s" --url %(url)s --minutes %(minutes)s --mail_admins'
) % {
'virtualenv_current': env.py3_virtualenv_current,
'user': env.user,
'environment': env.deploy_env,
'url': env.deploy_metadata.diff_url,
'minutes': str(int(delta.total_seconds() // 60))
})
示例5: ensure_checkpoints_safe
# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import cd [as 别名]
def ensure_checkpoints_safe():
extras = '--print-only' if env.ignore_kafka_checkpoint_warning else ''
with cd(env.code_root):
try:
sudo('{env.py3_virtualenv_root}/bin/python manage.py validate_kafka_pillow_checkpoints {extras}'.format(
env=env, extras=extras
))
except Exception as e:
if not env.ignore_kafka_checkpoint_warning:
message = (
"Deploy failed, likely because kafka checkpoints weren't available.\n"
"Scroll up for more detailed information.\n"
"You can rerun with --set ignore_kafka_checkpoint_warning=true to prevent this error from blocking the deploy."
).format(e)
raise Exception(message)
else:
# if we were forcing and still got an error this is likely a bug so we should raise it
raise
示例6: bower_install
# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import cd [as 别名]
def bower_install():
yarn_lock = os.path.join(env.code_root, YARN_LOCK)
if files.exists(yarn_lock):
return
with cd(env.code_root):
config = {
'interactive': 'false',
}
if env.http_proxy:
config.update({
'proxy': "http://{}".format(env.http_proxy),
'https-proxy': "http://{}".format(env.http_proxy)
})
bower_command('prune', production=True, config=config)
bower_command('update', production=True, config=config)
示例7: update_manifest
# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import cd [as 别名]
def update_manifest(save=False, soft=False, use_current_release=False):
"""
Puts the manifest.json file with the references to the compressed files
from the proxy machines to the web workers. This must be done on the WEB WORKER, since it
governs the actual static reference.
save=True saves the manifest.json file to redis, otherwise it grabs the
manifest.json file from redis and inserts it into the staticfiles dir.
"""
withpath = env.code_root if not use_current_release else env.code_current
venv = env.py3_virtualenv_root if not use_current_release else env.py3_virtualenv_current
args = ''
if save:
args = ' save'
if soft:
args = ' soft'
cmd = 'update_manifest%s' % args
with cd(withpath):
sudo(
'{venv}/bin/python manage.py {cmd}'.format(venv=venv, cmd=cmd),
user=env.sudo_user
)
示例8: _offline_tag_commit
# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import cd [as 别名]
def _offline_tag_commit(self):
commit = local('cd {}/commcare-hq && git show-ref --hash --heads {}'.format(
OFFLINE_STAGING_DIR,
env.deploy_metadata.deploy_ref,
), capture=True)
tag_name = '{}-{}-offline-deploy'.format(self.timestamp, self._environment)
local('cd {staging_dir}/commcare-hq && git tag -a -m "{message}" {tag} {commit}'.format(
staging_dir=OFFLINE_STAGING_DIR,
message='{} offline deploy at {}'.format(self._environment, self.timestamp),
tag=tag_name,
commit=commit,
))
with settings(warn_only=True):
local('cd {staging_dir}/commcare-hq && git push origin {tag}'.format(
staging_dir=OFFLINE_STAGING_DIR,
tag=tag_name,
))
示例9: reset_pillow
# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import cd [as 别名]
def reset_pillow(pillow):
_require_target()
prefix = 'commcare-hq-{}-pillowtop'.format(env.deploy_env)
supervisor.supervisor_command('stop {prefix}-{pillow}'.format(
prefix=prefix,
pillow=pillow
))
with cd(env.code_root):
command = '{virtualenv_root}/bin/python manage.py ptop_reset_checkpoint {pillow} --noinput'.format(
virtualenv_root=env.py3_virtualenv_root,
pillow=pillow,
)
sudo(command)
supervisor.supervisor_command('start {prefix}-{pillow}'.format(
prefix=prefix,
pillow=pillow
))
示例10: build_measures
# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import cd [as 别名]
def build_measures(environment=None, measures=None):
setup_env_from_environment(environment)
with cd(env.path):
with prefix("source .venv/bin/activate"):
# First we `--check` measures. This option validates all
# the measures, rather than exiting at the first error,
# which makes the debugging cycle shorter when dealing
# with more than one
run(
"cd openprescribing/ && "
"python manage.py import_measures --check "
"--measure {}".format(measures)
)
print("Checks of measures passed")
run(
"cd openprescribing/ && "
"python manage.py import_measures "
"--measure {}".format(measures)
)
print("Rebuild of measures completed")
示例11: deploy
# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import cd [as 别名]
def deploy(environment, force_build=False, branch="master"):
setup_env_from_environment(environment)
env.branch = branch
setup_sudo()
with cd(env.path):
checkpoint(force_build)
git_pull()
pip_install()
npm_install()
npm_install_deps(force_build)
npm_build_js()
npm_build_css(force_build)
deploy_static()
run_migrations()
# build_changed_measures()
graceful_reload()
clear_cloudflare()
setup_cron()
log_deploy()
# check_numbers()
示例12: call_management_command
# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import cd [as 别名]
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))
示例13: bootstrap
# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import cd [as 别名]
def bootstrap(app_env):
"""Create bootstrap environment for daimaduan"""
if not app_env:
print "fab pack deploy:<ENV>"
sys.exit(1)
app_path = '/var/www/%s/%s' % (APP_NAME, app_env)
log_path = '/var/log/%s/%s' % (APP_NAME, app_env)
sudo('mkdir -p %s' % app_path)
sudo('chown %s:%s %s' % (env.user, env.user, app_path))
sudo('mkdir -p %s' % log_path)
sudo('chown %s:%s %s' % (env.user, env.user, log_path))
with cd(app_path):
run('virtualenv --distribute venv')
示例14: clean
# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import cd [as 别名]
def clean():
with lcd('..'):
local('rm -rf dist/*')
with cd('~/data/downloads/'):
run('rm -rf *')
示例15: deploy
# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import cd [as 别名]
def deploy(version):
clean()
with lcd('..'):
local('git tag -a {0} -m \"version {0}\"'.format(version))
local('git push --tags')
local('python setup.py sdist')
#local('python setup.py bdist_wheel')
put('./dist/pyscenic*', '~/data/downloads')
with cd('~/data/downloads/'):
run('. activate pyscenic')
run('pip install --upgrade pyscenic-*.tar.gz')