本文整理汇总了Python中fabric.state.env.get方法的典型用法代码示例。如果您正苦于以下问题:Python env.get方法的具体用法?Python env.get怎么用?Python env.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fabric.state.env
的用法示例。
在下文中一共展示了env.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup
# 需要导入模块: from fabric.state import env [as 别名]
# 或者: from fabric.state.env import get [as 别名]
def setup():
'''
Perform initial setup (create docker-compose-config and mount dirs)
'''
settings = skeppa_settings.get_settings()
# Create compose config files
remote_conf_dir = os.path.join(env.path, settings.env_files_dir)
env.run('mkdir -p {0}'.format(remote_conf_dir))
# Create mount dir
mount_dir = os.path.join(env.path, settings.mount_dir)
env.run('mkdir -p {0}'.format(mount_dir))
# Upload files
if env.get('env_files', None):
_upload_env_files(env.env_files)
if env.get('compose_files', None):
_upload_compose_files(env.compose_files)
if env.get('files', None):
_upload_files(env.files)
示例2: _build_image
# 需要导入模块: from fabric.state import env [as 别名]
# 或者: from fabric.state.env import get [as 别名]
def _build_image(image):
current_dir = os.getcwd()
image_path = os.path.join(current_dir, image.get('path'))
version = dockerfile.read_tag(image_path)
# Tag release (master/develop)
use_versioning = image.get('use_versioning', False)
repository = image.get('repository')
release_tag = image.get('tag', 'latest')
extra_args = image.get('extra_args', "")
local("docker build {0} -t {1}:{2} {3}".format(extra_args,
image.get('name'),
release_tag,
image_path))
if use_versioning and version:
local("docker build {0} -t {1}:{2} {3}".format(extra_args,
repository['url'],
version,
image_path))
local("docker tag {0}:{1} {2}:{3}".format(image['name'], release_tag,
repository['url'], release_tag))
示例3: create_db
# 需要导入模块: from fabric.state import env [as 别名]
# 或者: from fabric.state.env import get [as 别名]
def create_db():
with settings(warn_only=True), hide('output', 'running'):
if env.get('settings'):
execute('servers.stop_service', 'uwsgi')
with shell_env(**app_config.database):
local('dropdb --if-exists %s' % app_config.database['PGDATABASE'])
if not env.get('settings'):
local('psql -c "DROP USER IF EXISTS %s;"' % app_config.database['PGUSER'])
local('psql -c "CREATE USER %s WITH SUPERUSER PASSWORD \'%s\';"' % (app_config.database['PGUSER'], app_config.database['PGPASSWORD']))
with shell_env(**app_config.database):
local('createdb %s' % app_config.database['PGDATABASE'])
if env.get('settings'):
execute('servers.start_service', 'uwsgi')
示例4: suggest_localhost
# 需要导入模块: from fabric.state import env [as 别名]
# 或者: from fabric.state.env import get [as 别名]
def suggest_localhost(func):
'''Prompt user for value of env.host_string with default to 'localhost'
when env.host_string is empty.
Modification of decorator function fabric.network.needs_host
'''
from fabric.network import handle_prompt_abort, to_dict
@wraps(func)
def host_prompting_wrapper(*args, **kwargs):
while not env.get('host_string', False):
handle_prompt_abort("the target host connection string")
host_string = raw_input("No hosts found. Please specify "
"host string for connection [localhost]: ")
if host_string == '':
host_string = 'localhost'
env.update(to_dict(host_string))
return func(*args, **kwargs)
host_prompting_wrapper.undecorated = func
return host_prompting_wrapper
示例5: subtask
# 需要导入模块: from fabric.state import env [as 别名]
# 或者: from fabric.state.env import get [as 别名]
def subtask(*args, **kwargs):
'''Decorator which prints out the name of the decorated function on
execution.
'''
depth = kwargs.get('depth', 2)
prefix = kwargs.get('prefix', '\n' + '#' * depth + ' ')
tail = kwargs.get('tail', '\n')
doc1 = kwargs.get('doc1', False)
color = kwargs.get('color', cyan)
def real_decorator(func):
if doc1:
return print_full_name(color=color, prefix=prefix,
tail=tail)(print_doc1(func))
return print_full_name(color=color, prefix=prefix, tail=tail)(func)
invoked = bool(not args or kwargs)
if not invoked:
# invoke decorator function which returns the wrapper function
return real_decorator(func=args[0])
return real_decorator
示例6: _is_sudoer
# 需要导入模块: from fabric.state import env [as 别名]
# 或者: from fabric.state.env import get [as 别名]
def _is_sudoer(what_for=''):
'''Return True if current user is a sudoer, else False.
Should be called non-eager if sudo is wanted only.
'''
if env.get('nosudo', None) == None:
if what_for:
print(yellow(what_for))
with quiet():
# possible outputs:
# en: "Sorry, user winhost-tester may not run sudo on <hostname>"
# en: "sudo: a password is required" (=> is sudoer)
# de: "sudo: Ein Passwort ist notwendig" (=> is sudoer)
output = run('sudo -nv', capture=True)
env.nosudo = not (output.startswith('sudo: ') or output == '')
if env.nosudo:
print('Cannot execute sudo-commands')
return not env.nosudo
示例7: combine_rc
# 需要导入模块: from fabric.state import env [as 别名]
# 或者: from fabric.state.env import get [as 别名]
def combine_rc(rc_filename, overlay=None):
"""Take a rc filename, load it as fabric would.
If it specifies an _extends value, consider this file
to be an overlay of the named file."""
from fabric.main import load_settings
assert os.path.exists(rc_filename), "Can't find " + rc_filename
service_config = load_settings(rc_filename)
if '_extends' in service_config:
fname = service_config['_extends']
# We want fname to be usable both on host and target.
# Use project-path-relative names to that effect.
if fname.startswith('~/'):
path = dirname(__file__)
if not is_local(env.host_string):
path = env.get('projectpath', path)
fname = join(path, fname[2:])
else:
fname = join(dirname(rc_filename), fname)
service_config = combine_rc(fname, service_config)
if overlay is not None:
service_config.update(overlay)
service_config.pop('_extends', None)
service_config.pop('', None)
return service_config
示例8: install_certbot
# 需要导入模块: from fabric.state import env [as 别名]
# 或者: from fabric.state.env import get [as 别名]
def install_certbot():
"""Install letsencrypt.org certbot"""
if env.mac:
return
if exists('/etc/os-release'):
release_data = run('cat /etc/os-release')
if 'jessie' in release_data:
sudo("echo 'deb http://ftp.debian.org/debian jessie-backports main' >> /etc/apt/sources.list")
sudo("apt-get update")
elif 'ubuntu' in release_data:
sudo("apt-get install software-properties-common")
sudo("add-apt-repository ppa:certbot/certbot")
sudo("apt-get update")
else:
raise NotImplementedError("Unknown distribution")
sudo("apt-get install python3-certbot-nginx")
示例9: install_redis
# 需要导入模块: from fabric.state import env [as 别名]
# 或者: from fabric.state.env import get [as 别名]
def install_redis():
"""
Install redis server
"""
print(cyan('Installing redis server'))
if env.mac:
run('brew install redis')
run('brew tap homebrew/services')
run('brew services start redis')
else:
sudo('apt-get install -y redis-server')
if exists('/etc/systemd/system/redis.service'):
sudo('sudo systemctl start redis.service')
elif exists('/etc/init.d/redis-server'):
sudo('/etc/init.d/redis-server start')
else:
print(red("Make sure that redis is running"))
示例10: start_edit_fontello_fonts
# 需要导入模块: from fabric.state import env [as 别名]
# 或者: from fabric.state.env import get [as 别名]
def start_edit_fontello_fonts():
"""Prepare to edit the fontello fonts in Fontello."""
assert are_local(env.hosts), "Meant to be run locally"
import requests
font_dir = join(
env.projectpath, 'assembl', 'static', 'css', 'fonts')
config_file = join(font_dir, 'config.json')
id_file = join(font_dir, 'fontello.id')
r = requests.post("http://fontello.com",
files={'config': open(config_file)})
if not r.ok:
raise RuntimeError("Could not get the ID")
fid = r.text
with open(id_file, 'w') as f:
f.write(fid)
if are_local(env.hosts):
import webbrowser
webbrowser.open('http://fontello.com/' + fid)
示例11: compile_fontello_fonts
# 需要导入模块: from fabric.state import env [as 别名]
# 或者: from fabric.state.env import get [as 别名]
def compile_fontello_fonts():
"""Compile the fontello fonts once you have edited them in Fontello. Run start_edit_fontello_fonts first."""
from zipfile import ZipFile
from io import BytesIO
assert are_local(env.hosts), "Meant to be run locally"
import requests
font_dir = join(
env.projectpath, 'assembl', 'static', 'css', 'fonts')
config_file = join(font_dir, 'config.json')
id_file = join(font_dir, 'fontello.id')
assert os.path.exists(id_file)
with open(id_file) as f:
fid = f.read()
r = requests.get("http://fontello.com/%s/get" % fid)
if not r.ok:
raise RuntimeError("Could not get the data")
with ZipFile(BytesIO(r.content)) as data:
for name in data.namelist():
dirname, fname = split(name)
dirname, subdir = split(dirname)
if fname and (subdir == 'font' or fname == 'config.json'):
with data.open(name) as fdata:
with open(join(font_dir, fname), 'wb') as ffile:
ffile.write(fdata.read())
示例12: install_yarn
# 需要导入模块: from fabric.state import env [as 别名]
# 或者: from fabric.state.env import get [as 别名]
def install_yarn(local=True):
"""Install yarn"""
if local:
node_modules = get_node_modules_path()
if not exists(join(node_modules, '.bin', 'yarn')):
# Start fresh if installing local yarn
run('rm -rf '+node_modules)
with cd(get_node_base_path()):
venvcmd('npm install --no-save yarn', chdir=False)
elif not env.mac:
if not exists('/etc/apt/sources.list.d/yarn.list'):
sudo('echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list')
sudo('curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -')
sudo('apt-get update')
sudo('apt-get install yarn')
else:
run('brew install yarn')
示例13: _push_image
# 需要导入模块: from fabric.state import env [as 别名]
# 或者: from fabric.state.env import get [as 别名]
def _push_image(image):
ext.dispatch("before_push", image)
current_dir = os.getcwd()
image_path = os.path.join(current_dir, image.get('path'))
version = dockerfile.read_tag(image_path)
use_versioning = image.get('use_versioning', False)
repository = image.get('repository')
release_tag = image.get('tag', 'latest')
if use_versioning and version:
local("docker push {0}:{1}".format(repository['url'], version))
local("docker push {0}:{1}".format(repository['url'], release_tag))
示例14: deploy
# 需要导入模块: from fabric.state import env [as 别名]
# 或者: from fabric.state.env import get [as 别名]
def deploy():
'''
Pull latest image and restart containers
'''
images = env.image
compose_file = env.compose_files[0]
if not isinstance(env.image, list):
images = [env.image]
with env.cd(env.path):
# Update images
for image in images:
repository = image.get('repository')
release_tag = image.get('tag', 'latest')
# Trigger before deploy hooks
ext.dispatch("before_deploy", image)
# Pull latest repro changes
env.run("docker pull {0}:{1}".format(repository['url'],
release_tag))
# Stop all containers
env.run("docker-compose -f {0} -p {1} stop".format(compose_file,
env.project))
# Start all containers
env.run("docker-compose -f {0} -p {1} up -d".format(compose_file,
env.project))
# Trigger after deploy hooks
for image in images:
ext.dispatch("after_deploy", image)
# Remove dangeling images
env.run("docker images --quiet --filter=dangling=true"
" | xargs --no-run-if-empty docker rmi")
示例15: install_packages
# 需要导入模块: from fabric.state import env [as 别名]
# 或者: from fabric.state.env import get [as 别名]
def install_packages(packages,
what_for='for a complete setup to work properly'):
'''Try to install .deb packages given by list.
Return True, if packages could be installed or are installed already, or if
they cannot be installed but the user gives feedback to continue.
Else return False.
'''
res = True
non_installed_packages = _non_installed(packages)
packages_str = ' '.join(non_installed_packages)
if non_installed_packages:
with quiet():
dpkg = _has_dpkg()
hint = ' (You may have to install them manually)'
do_install = False
go_on = True
if dpkg:
if _is_sudoer('Want to install dpkg packages'):
do_install = True
else:
do_install = False # cannot install anything
info = yellow(' '.join([
'This deb packages are missing to be installed',
flo("{what_for}: "), ', '.join(non_installed_packages),]))
question = ' Continue anyway?'
go_on = query_yes_no(info + hint + question, default='no')
else:
# dpkg == False, unable to determine if packages are installed
do_install = False # cannot install anything
info = yellow(' '.join([flo('Required {what_for}: '),
', '.join(non_installed_packages),]))
go_on = query_yes_no(info + hint + ' Continue?', default='yes')
if not go_on:
sys.exit('Abort')
if do_install:
command = flo('sudo apt-get install {packages_str}')
res = run(command).return_code == 0
return res