本文整理汇总了Python中fabric.api.hide方法的典型用法代码示例。如果您正苦于以下问题:Python api.hide方法的具体用法?Python api.hide怎么用?Python api.hide使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fabric.api
的用法示例。
在下文中一共展示了api.hide方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import hide [as 别名]
def build(name, ask=True, **kwargs):
"""
Build the malicious mote to its target hardware.
:param name: experiment name (or absolute path to experiment)
:param ask: ask confirmation
:param path: expanded path of the experiment (dynamically filled in through 'command' decorator with 'expand')
:param kwargs: simulation keyword arguments (see the documentation for more information)
"""
def is_device_present():
with settings(hide(*HIDDEN_ALL), warn_only=True):
return local("if [ -c /dev/ttyUSB0 ]; then echo 'ok'; else echo 'nok'; fi", capture=True) == 'ok'
console = kwargs.get('console')
counter, interval = 0.0, 0.5
while not is_device_present():
sleep(interval)
counter += interval
if counter % 5 == 0:
logger.warning("Waiting for mote to be detected...")
elif counter >= 120:
logger.error("Something failed with the mote ; check that it mounts to /dev/ttyUSB0")
return
remake(name, build=True, **kwargs) if console is None else console.do_remake(name, build=True, **kwargs)
return "Mote built on /dev/ttyUSB0"
示例2: _command
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import hide [as 别名]
def _command(
fabric_method,
command,
ignore_errors=False,
quiet=True,
hide=('running', 'aborts'),
show=(),
abort_exception=Error,
**kwargs
):
if quiet:
hide += ('output', 'warnings')
log('{method}: {command}'.format(
method=fabric_method.__name__,
command=command,
))
with fab.settings(
fab.hide(*hide),
fab.show(*show),
abort_exception=abort_exception,
warn_only=ignore_errors,
):
return fabric_method(command, **kwargs)
示例3: shutdown_admin
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import hide [as 别名]
def shutdown_admin():
print green('Shutdown the mall admin via the shutdown.sh scripts.')
print 'Logs output to the '+log_path+'/shutdown_admin.log'
os.system('mkdir -p '+log_path+' 2>/dev/null >/dev/null')
os.system("echo '' > "+log_path+"/shutdown_admin.log")
with settings(hide('warnings', 'running', 'stdout', 'stderr'),warn_only=True):
os.system("fab -f "+script_name+" shutdown_admin > "+log_path+"/shutdown_admin.log 2>/dev/null >/dev/null")
with settings(hide('warnings', 'running', 'stdout', 'stderr'),warn_only=True):
os.system("fab -f "+script_name+" shutdown_admin > "+log_path+"/shutdown_admin.log 2>/dev/null >/dev/null")
print green('Shutdown the mall admin finished!')
# Startup the mall admin via the startup.sh scripts function.
示例4: shutdown_api
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import hide [as 别名]
def shutdown_api():
print green('Shutdown the mall api via the shutdown.sh scripts.')
print 'Logs output to the '+log_path+'/shutdown_api.log'
os.system('mkdir -p '+log_path+' 2>/dev/null >/dev/null')
os.system("echo '' > "+log_path+"/shutdown_api.log")
with settings(hide('warnings', 'running', 'stdout', 'stderr'),warn_only=True):
os.system("fab -f "+script_name+" shutdown_api > "+log_path+"/shutdown_api.log 2>/dev/null >/dev/null")
with settings(hide('warnings', 'running', 'stdout', 'stderr'),warn_only=True):
os.system("fab -f "+script_name+" shutdown_api > "+log_path+"/shutdown_api.log 2>/dev/null >/dev/null")
print green('Shutdown the mall api finished!')
# Startup the mall api via the startup.sh scripts function.
示例5: shutdown_admin
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import hide [as 别名]
def shutdown_admin():
print green('Shutdown the mall admin via the remote_shutdown.sh scripts.')
print 'Logs output to the '+log_path+'/shutdown_admin.log'
os.system('mkdir -p '+log_path+' 2>/dev/null >/dev/null')
os.system("echo '' > "+log_path+"/shutdown_admin.log")
with settings(hide('warnings', 'running', 'stdout', 'stderr'),warn_only=True):
os.system("fab -f "+script_name+" shutdown_admin > "+log_path+"/shutdown_admin.log 2>/dev/null >/dev/null")
with settings(hide('warnings', 'running', 'stdout', 'stderr'),warn_only=True):
os.system("fab -f "+script_name+" shutdown_admin > "+log_path+"/shutdown_admin.log 2>/dev/null >/dev/null")
print green('Shutdown the mall admin finished!')
# Startup the mall admin via the remote_startup.sh scripts function.
示例6: shutdown_api
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import hide [as 别名]
def shutdown_api():
print green('Shutdown the mall api via the remote_shutdown.sh scripts.')
print 'Logs output to the '+log_path+'/shutdown_api.log'
os.system('mkdir -p '+log_path+' 2>/dev/null >/dev/null')
os.system("echo '' > "+log_path+"/shutdown_api.log")
with settings(hide('warnings', 'running', 'stdout', 'stderr'),warn_only=True):
os.system("fab -f "+script_name+" shutdown_api > "+log_path+"/shutdown_api.log 2>/dev/null >/dev/null")
with settings(hide('warnings', 'running', 'stdout', 'stderr'),warn_only=True):
os.system("fab -f "+script_name+" shutdown_api > "+log_path+"/shutdown_api.log 2>/dev/null >/dev/null")
print green('Shutdown the mall api finished!')
# Startup the mall api via the remote_startup.sh scripts function.
示例7: restart_auth
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import hide [as 别名]
def restart_auth():
print green('Restart the core platform via the restart.sh scripts.')
ret = run("ps -ef|grep cmms-auth|grep -v grep|cut -c 9-15")
if ret:
with settings(hide('warnings', 'running', 'stdout', 'stderr'),warn_only=True):
run("ps -ef|grep cmms-auth|grep -v grep|cut -c 9-15|xargs kill -9 2>/dev/null >/dev/null")
else:
print red("No such progress!")
ret_new = run("ps -ef|grep cmms-auth|grep -v grep|cut -c 9-15")
if ret_new:
print red('Startup already!')
else:
with settings(hide('warnings', 'running', 'stdout', 'stderr'),warn_only=True):
run('cd '+auth_path+' && java -jar cmms-auth.jar 2>/dev/null >/dev/null')
print green('Restart the core platform finished!')
# Deploy core platform via mvn function.
示例8: check_system_support
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import hide [as 别名]
def check_system_support():
# check hardware support
if run("egrep '^flags.*(vmx|svm)' /proc/cpuinfo > /dev/null").failed:
abort("Need hardware VM support (vmx)")
# check minimum kernel version:
# Linux kernel under 3.13.0 has a bug where the kernel crash
# when EPT support enabled with FUSE+mmap.
WORKING_KERNEL_VERSION = "3.13.0"
kernel_version = platform.platform().split("-")[1]
if LooseVersion(kernel_version) < LooseVersion(WORKING_KERNEL_VERSION):
msg = "Linux Kernel lower than %s has a bug when using FUSE + mmap"\
% WORKING_KERNEL_VERSION
abort(msg)
# check OS version
cmd = "cat /etc/lsb-release | grep DISTRIB_CODENAME | awk -F'=' '{print $2}'"
with settings(hide('everything'), warn_only=True):
os_dist = run(cmd)
if os_dist != 'trusty' and os_dist != "xenial":
msg = "Support only Ubuntu Precise (14.04) or Ubuntu Trusty (16.04)"
abort(msg)
return os_dist
return None
示例9: _silencer
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import hide [as 别名]
def _silencer(func):
"""Decorator which runs the wrapped function with hide('stdout') if the
``silent`` keyword argument is provided.
The ``silent`` keyword argument will be removed from the kwargs before
calling the wrapped function.
"""
@wraps(func)
def wrapper(*args, **kwargs):
silent = kwargs.pop('silent', False)
if silent:
with hide('stdout'):
return func(*args, **kwargs)
return func(*args, **kwargs)
return wrapper
示例10: ping
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import hide [as 别名]
def ping():
with hide('running', 'output'):
hostname = run('hostname')
vmballoon = run('vmware-toolbox-cmd stat balloon')
vmswap = run('vmware-toolbox-cmd stat swap')
uptime = run('uptime')
free = run('free -h')
print("===== Hello from %s =====" % hostname)
print("[%s] %s" % (hostname, uptime))
print("[%s] %s" % (hostname, free))
print("[%s] vmware balloon: %s" % (hostname, vmballoon))
print("[%s] vmware swap: %s" % (hostname, vmswap))
#with hide('running'):
示例11: drop_databases
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import hide [as 别名]
def drop_databases():
"""
Drop the databases. This is not part of the normal setup process, rather it's used to recreate the database in development.
:return:
"""
db_name = os.environ['DATABASE_NAME']
for database_name in ['test_{0}'.format(db_name), db_name]:
with settings(hide('running', 'stdout', 'stderr', 'warnings'), warn_only=True):
exists = psql("", database_name=database_name).succeeded
# Drop the database if it exists
if exists:
drop_db_connections(database_name)
run_as_pg("dropdb {db};".format(db=database_name))
示例12: get_commit
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import hide [as 别名]
def get_commit(build_type='prod'):
with cd(get_django_setting(build_type, 'ROOT_PATH')):
with hide('output'):
commit = run("git rev-list HEAD --max-count=1 --pretty --oneline").stdout
print str(commit)
return commit
示例13: clean
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import hide [as 别名]
def clean(name, ask=True, **kwargs):
"""
Remove an experiment.
:param name: experiment name (or absolute path to experiment)
:param ask: ask confirmation
:param kwargs: simulation keyword arguments (see the documentation for more information)
"""
path = kwargs.get('path')
console = kwargs.get('console')
if console is None or not console.task_pending(name):
logger.debug(" > Cleaning folder...")
with hide(*HIDDEN_ALL):
local("rm -rf {}".format(path))
return "Cleaned"
示例14: cooja
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import hide [as 别名]
def cooja(name, with_malicious=True, **kwargs):
"""
Start an experiment in Cooja with/without the malicious mote and updates the experiment if motes' positions
were changed.
:param name: experiment name
:param with_malicious: use the simulation WITH the malicious mote or not
:param path: expanded path of the experiment (dynamically filled in through 'command' decorator with 'expand')
:param kwargs: simulation keyword arguments (see the documentation for more information)
"""
sim_path = join(kwargs['path'], 'with{}-malicious'.format(['out', ''][with_malicious is True]))
motes_before = get_motes_from_simulation(join(sim_path, 'simulation.csc'), as_dictionary=True)
with hide(*HIDDEN_ALL):
with lcd(sim_path):
local("make cooja TASK={}".format(kwargs.get('task', "cooja")))
motes_after = get_motes_from_simulation(join(sim_path, 'simulation.csc'), as_dictionary=True)
# if there was a change, update the other simulation in this experiment
if len(set(motes_before.items()) & set(motes_after.items())) > 0:
other_sim_path = join(kwargs['path'], 'with{}-malicious'.format(['', 'out'][with_malicious is True]))
set_motes_to_simulation(join(other_sim_path, 'simulation.csc'), motes_after)
# if this experiment is part of a campaign, update this
campaign = read_config(kwargs['path']).get('campaign')
if campaign is not None:
for experiment in get_experiments(campaign):
if experiment in ['BASE', name]:
continue
exp_path = join(EXPERIMENT_FOLDER, experiment)
set_motes_to_simulation(join(exp_path, 'with-malicious', 'simulation.csc'), motes_after)
set_motes_to_simulation(join(exp_path, 'without-malicious', 'simulation.csc'), motes_after)
示例15: update
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import hide [as 别名]
def update(silent=False, **kwargs):
"""
Update Contiki-OS and RPL Attacks Framework.
:param silent: run command silently
:param kwargs: simulation keyword arguments (see the documentation for more information)
"""
updated = False
for folder, repository in zip([CONTIKI_FOLDER, FRAMEWORK_FOLDER], ["Contiki-OS", "RPL Attacks Framework"]):
with hide(*HIDDEN_ALL):
with lcd(folder):
if "Could not resolve proxy" in local('git fetch --all', capture=True):
logger.error("Update failed ; please check your proxy settings")
break
uptodate = "branch is up-to-date" in local('git checkout master', capture=True).strip().split('\n')[-1]
if not uptodate:
req_exists = exists("requirements.txt")
if req_exists:
req_md5 = hash_file("requirements.txt")
logger.warn("You are about to loose any custom change made to {} ;".format(repository))
if silent or std_input("Proceed anyway ? (yes|no) [default: no] ", 'yellow') == 'yes':
local('git submodule update --init')
local('git fetch --all')
local('git reset --hard origin/master')
local('git pull')
if req_exists and hash_file("requirements.txt") != req_md5:
local('pip install -r requirements.txt')
updated = True
if repository == "RPL Attacks Framework":
remove_files(folder, "Vagrantfile")
remove_folder(join(folder, "provisioning"))
logger.debug(" > {} {}".format(repository, ["updated", "already up-to-date"][uptodate]))
if updated:
setup(silent)
if not silent:
logger.warn("Restarting the framework...")
restart(PIDFILE)