def dev():
with api.lcd('../client'):
client_fabfile.dev()
python类lcd()的实例源码
def local_git_clone(repo_url):
"clones master of repo_url"
with lcd(LOGDIR):
local('if [ -d letsencrypt ]; then rm -rf letsencrypt; fi')
local('git clone %s letsencrypt'% repo_url)
local('tar czf le.tar.gz letsencrypt')
def local_git_branch(repo_url, branch_name):
"clones branch <branch_name> of repo_url"
with lcd(LOGDIR):
local('if [ -d letsencrypt ]; then rm -rf letsencrypt; fi')
local('git clone %s letsencrypt --branch %s --single-branch'%(repo_url, branch_name))
local('tar czf le.tar.gz letsencrypt')
def local_git_PR(repo_url, PRnumstr, merge_master=True):
"clones specified pull request from repo_url and optionally merges into master"
with lcd(LOGDIR):
local('if [ -d letsencrypt ]; then rm -rf letsencrypt; fi')
local('git clone %s letsencrypt'% repo_url)
local('cd letsencrypt && git fetch origin pull/%s/head:lePRtest'%PRnumstr)
local('cd letsencrypt && git checkout lePRtest')
if merge_master:
local('cd letsencrypt && git remote update origin')
local('cd letsencrypt && git merge origin/master -m "testmerge"')
local('tar czf le.tar.gz letsencrypt')
def local_repo_to_remote():
"copies local tarball of repo to remote"
with lcd(LOGDIR):
put(local_path='le.tar.gz', remote_path='')
run('tar xzf le.tar.gz')
def local_repo_clean():
"delete tarball"
with lcd(LOGDIR):
local('rm le.tar.gz')
def integrate():
with lcd("../django_ecommerce/"):
local("pwd")
local("./manage.py test ../tests/unit")
with settings(warn_only=True):
local("git add -p && git commit")
local("git pull")
local("./manage.py test ../tests")
local("git push")
def release(force=False):
""" releases the master branch at the current version to pypi """
with api.lcd(THIS_DIR):
return _release(force=force)
def _hotswap(file, type, keywords):
file_with_full_path = '/app/online/{}{}'.format(GAME, file)
file_path = os.path.dirname(file_with_full_path)
#local('rsync -aqP {}/{{hotswap.zip,md5.txt}} {}@{}:{}/'.format(file_path, env.user, env.host_string, REMOTE_DIR))
run('mkdir -p {}'.format(REMOTE_DIR))
with lcd(file_path):
put('hotswap.zip', REMOTE_DIR)
put('md5.txt', REMOTE_DIR)
with cd(REMOTE_DIR):
run('dos2unix md5.txt && md5sum -c md5.txt')
run('unzip -q hotswap.zip')
run('cd hotswap && chmod +x attach remote update')
ret_value = {}
for gameServer in LOCATE_GAME_SRVS[env.host_string]:
with cd('/app/{}/backend/logs'.format(gameServer)):
run('echo >start.out')
with cd('{}/hotswap'.format(REMOTE_DIR)):
pid = gameServer_pid(gameServer)
run('./{} {}'.format(type, pid))
with cd('/app/{}/backend/logs'.format(gameServer)):
for each_keyword in keywords.split(','):
with quiet():
do_hotswap_success = run('grep --color=never -E -A 20 "reload.*{}" {} | grep --color=never "reload succ"'.format(each_keyword, 'start.out')).succeeded
if not do_hotswap_success:
ret_value[gameServer] = False
break
else:
ret_value[gameServer] = True
return ret_value
def check_local_merge_scripts(local_dir):
scripts = ['clear_small_user.sql', 'db.yml', 'forceId.sql', 'hf.py', 'hf_reward.sql', 'table.yml']
with settings(hide('everything')):
with lcd(local_dir):
for each_file in scripts:
local('test -f {}'.format(each_file))
for replace_str in ['first_force_id', 'second_force_id', 'third_force_id']:
local('grep {} forceId.sql >/dev/null'.format(replace_str))
local('grep "db: db1" db.yml')
local('grep "db: db2" db.yml')
def add_base_hosts_for_ssh(self):
with lcd('/app/opbin/krb_hosts'):
result = local('''grep -nE '[0-9]{1,3}(\.[0-9]{1,3}){3} +%s_match_%s' base_hosts''' % (GAME, self.id - 1))
lines = result.splitlines()
if len(lines) == 1:
rowNum, line = lines[0].split(':', 1) #???????
run('cp base_hosts bak/base_hosts.rb{}'.format(TIME))
run("sed -i '{}a {} {}' base_hosts".format(rowNum, self.ip, self.matchServer))
else:
print('[WARNING] Failed to add_base_hosts_for_ssh, can NOT locate a proper postion to add the new match entry, because there are more than one entry for {}_match_{}'.format(GAME, self.id - 1))
def upload_to_resource_server(game, file):
dir, filename = os.path.split(file)
resource_dir = '/app/www/{}/{}/{}'.format(game, RELEASE_TYPE, TIMESTAMP)
resource_ip = gameOption('www_ssh_ip')
execute(mk_remote_dir, resource_dir, hosts=[resource_ip])
with lcd(dir), settings(host_string=resource_ip):
put(filename, resource_dir)
put('md5.txt', resource_dir)
#local('{} {}/{{{},md5.txt}} {}:{}/'.format(RSYNC, dir, filename, resource_ip, resource_dir))
def clean():
with lcd(os.path.dirname(__file__)):
# local("python3.6 setup.py clean --all")
local("find . | grep -E \"(__pycache__|\.pyc$)\" | xargs rm -rf")
local("rm -rf ./docs/build || true")
local("rm -rf ./docs/source/reference/_autosummary || true")
def docs():
with lcd("./docs"):
local("make clean")
local("make html")
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)
def test(**kwargs):
"""
Run framework's tests.
:param kwargs: simulation keyword arguments (see the documentation for more information)
"""
with settings(warn_only=True):
print(FRAMEWORK_FOLDER)
with lcd(FRAMEWORK_FOLDER):
local("python -m unittest -v tests")
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)
"""
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')
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 not silent:
logger.warn("Restarting the framework...")
restart(PIDFILE)
def make_incremental_build(name, basis="live"):
"""
Archive a build, hard-linking unchanged files from the "basis" build (default live)
This can significantly reduce the disk space used by multiple builds.
On mac, requires ``brew install coreutils``
"""
cp_bin = find_executable('gcp')
if find_executable('gcp'):
cp_bin = "gcp"
else:
cp_bin = "cp"
live_name = dealias_build("_live")
stage_name = dealias_build("_stage")
if name in (live_name, stage_name):
abort("Cannot turn the live or stage build into an incremental build")
basis = dealias_build(basis)
stop(name)
with lcd("%s/deploy/builds" % ROOT_DIR):
local("mv %(name)s %(name)s~" % {'name': name})
with settings(hide("stderr"), warn_only=True):
cp_ret = local("%(cp_bin)s -al %(basis)s %(name)s" % {
'basis': basis,
'name': name,
'cp_bin': cp_bin,
})
if not cp_ret.succeeded:
local("mv %(name)s~ %(name)s" % {'name': name})
abort("Local cp bin does not support -l flag (on mac: brew install coreutils)")
local("rsync -acH --delete %(name)s~/ %(name)s" % {'name': name})
local("rm -rf %(name)s~" % {'name': name})
def make_knnaas():
local('rm -rf knnaas/worker/build')
local('mkdir -p knnaas/worker/build')
with lcd('knnaas/worker/build'):
local('ls')
local('pwd')
local('cmake ..')
local('make')
def make_caffe():
with lcd('build'):
local('git clone https://github.com/nikhilketkar/caffe.git')
with lcd('build/caffe'):
local('rm -rf build')
local('mkdir build')
with lcd('build/caffe/build'):
local('cmake ..')
local('make')
local('make pycaffe')