Python fabric.api.lcd() Examples

The following are 15 code examples of fabric.api.lcd(). 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 Computable with MIT License 6 votes vote down vote up
def nonbower():
    if not os.path.exists(components_dir):
        components()
    
    with open("nonbower.json") as f:
        cfg = json.load(f)
    for name, repo in cfg.get('dependencies', {}).items():
        
        clone = "git clone"
        if '#' in repo:
            repo, tag = repo.split('#')
        else:
            tag = None
            clone += " --depth 1"
        
        with lcd(components_dir):
            
            local("{clone} {repo} {name}".format(**locals()))
            
            if tag:
                with lcd(pjoin(components_dir, name)):
                    local("git checkout -b {0} tags/{0}".format(tag))
        
        # remove the git tree, so we don't get submodules
        shutil.rmtree(pjoin(components_dir, name, '.git')) 
Example #2
Source File: fabfile.py    From Computable with MIT License 6 votes vote down vote up
def postprocess():
    with lcd(pjoin(components_dir, "bootstrap")):
        local("npm install")
        local("make bootstrap-css")
        local("make bootstrap-js")
    
    # add bootsrap packages to the PATH
    # (less.js needs uglify, which bootstrap just installed above)
    bins = glob.glob(pjoin(components_dir, "bootstrap", "node_modules", "*", "bin"))
    os.environ['PATH'] = os.pathsep.join(bins + [os.environ['PATH']])
    
    # build less
    shutil.rmtree(pjoin(components_dir, "less.js", "dist"))
    with lcd(pjoin(components_dir, "less.js")):
        local("make min")
    
    # build highlight.js
    with lcd(pjoin(components_dir, "highlight.js")):
        local("python tools/build.py")
    
    for toignore in glob.glob(pjoin(here, "*", ".gitignore")):
        os.unlink(toignore) 
Example #3
Source File: fabfile.py    From rscoin with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def experiment1collect():        
        # run("ls experiment1/*")
    with cd('/home/ubuntu/projects/rscoin/%s' % env.expname):
        get('issue-times.txt', '%s/%s-issue-times.txt' % (env.expname, env.host))

    with lcd(env.expname):
        local("cat %s-issue-times.txt >> issue-times.txt" % env.host)

    with cd('/home/ubuntu/projects/rscoin/%s' % env.expname):
        get('r1-times.txt', '%s/%s-r1-times.txt' % (env.expname, env.host))
    
    with lcd(env.expname):
        local("cat %s-r1-times.txt >> r1-times.txt" % env.host)

    with cd('/home/ubuntu/projects/rscoin/%s' % env.expname):
        get('r2-times.txt', '%s/%s-r2-times.txt' % (env.expname, env.host))

    with lcd(env.expname):
        local("cat %s-r2-times.txt >> r2-times.txt" % env.host)

        # local("python exp1plot.py experiment1") 
Example #4
Source File: commands.py    From rpl-attacks with GNU Affero General Public License v3.0 6 votes vote down vote up
def versions(**kwargs):
    """
    Check versions of Contiki-OS and RPL Attacks Framework.

    :param kwargs: simulation keyword arguments (see the documentation for more information)
    """
    with hide(*HIDDEN_ALL):
        with lcd(CONTIKI_FOLDER):
            cversion = local('git --git-dir .git describe --tags --always', capture=True)
        logger.warn("Contiki-OS: {}".format(cversion))
        with lcd(FRAMEWORK_FOLDER):
            cversion = local('git --git-dir .git describe --tags --always', capture=True)
        logger.warn("RPL Attacks Framework: {}".format(cversion))


# **************************************** MAGICAL COMMANDS *************************************** 
Example #5
Source File: fabfile.py    From Computable with MIT License 5 votes vote down vote up
def bower():
    """install components with bower"""
    with lcd(here):
        local('bower install') 
Example #6
Source File: fabfile.py    From Computable with MIT License 5 votes vote down vote up
def _compile_less(source, target, minify=True, verbose=False):
    """Compile a less file by source and target relative to static_dir"""
    minify = _to_bool(minify)
    verbose = _to_bool(verbose)
    min_flag = '-x' if minify is True else ''
    ver_flag = '--verbose' if verbose is True else ''
    lessc = os.path.join('components', 'less.js', 'bin', 'lessc')
    with lcd(static_dir):
        local('{lessc} {min_flag} {ver_flag} {source} {target}'.format(**locals())) 
Example #7
Source File: fabfile.py    From Doodle with MIT License 5 votes vote down vote up
def get_config_branch():
    with lcd('private'):
        output = local('git branch', capture=True)
        for line in output.splitlines():
            if line[:2] == '* ':
                return line[2:]
    return 'master' 
Example #8
Source File: deploy.py    From rorolite with Apache License 2.0 5 votes vote down vote up
def push_directory(self):
        with tempfile.TemporaryDirectory() as tmpdir:
            archive = self.archive(rootdir=".", output_dir=tmpdir)
            remote.put(archive, "/tmp/rorolite-project.tgz")

            with lcd(tmpdir):
                self.generate_supervisor_config(rootdir=tmpdir)

                supervisor_archive = self.archive(tmpdir, base_dir=".rorolite", filename="rorolite-supervisor")
                remote.put(supervisor_archive, "/tmp/rorolite-supervisor.tgz")

            with remote.cd(self.deploy_root):
                remote.sudo("chown {} .".format(env.user))
                remote.run("tar xzf /tmp/rorolite-project.tgz")
                remote.run("tar xzf /tmp/rorolite-supervisor.tgz") 
Example #9
Source File: fabfile.py    From serapis with MIT License 5 votes vote down vote up
def update():
    # Run tests
    # local("py.test serapis/tests/")

    # Updates code in zip file with current Master without going to EC2 first.
    local('git archive --format=zip HEAD -o %s' % gitfile, capture=False)
    local('unzip -d git_tmp -o -u %s' % gitfile)
    with lcd('git_tmp'):
        local('zip -9r ../%s .' % lambdafile)
    local('zip -9 %s serapis/config/credentials.yaml' % lambdafile)

    for corpus in corpora:
        local('zip -9r {} {}'.format(lambdafile, corpus))
    local('rm -r git_tmp') 
Example #10
Source File: commands.py    From rpl-attacks with GNU Affero General Public License v3.0 5 votes vote down vote up
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) 
Example #11
Source File: commands.py    From rpl-attacks with GNU Affero General Public License v3.0 5 votes vote down vote up
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") 
Example #12
Source File: commands.py    From rpl-attacks with GNU Affero General Public License v3.0 5 votes vote down vote up
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) 
Example #13
Source File: fabfile.py    From React-News-Board with GNU General Public License v2.0 5 votes vote down vote up
def build():
    with lcd("{}/client".format(PROJECT_LOCAL_DIR)):
        local("npm run build") 
Example #14
Source File: fabfile.py    From pywren with Apache License 2.0 5 votes vote down vote up
def create_zip():
    with lcd("pywren"):
        
        local("zip ../deploy.zip *.py") 
Example #15
Source File: commands.py    From rpl-attacks with GNU Affero General Public License v3.0 4 votes vote down vote up
def __run(name, **kwargs):
    """
    Run an experiment.

    :param name: experiment name
    :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)
    """
    set_logging(kwargs.get('loglevel'))
    path = kwargs['path']
    check_structure(path, remove=True)
    with settings(hide(*HIDDEN_ALL), warn_only=True):
        for sim in ["without", "with"]:
            sim_path = join(path, "{}-malicious".format(sim))
            data, results = join(sim_path, 'data'), join(sim_path, 'results')
            # the Makefile is at experiment's root ('path')
            logger.debug(" > Running simulation {} the malicious mote...".format(sim))
            task = kwargs.get('task', "run")
            with lcd(sim_path):
                output = local("make run TASK={}".format(task), capture=True)
            remove_files(sim_path, '.{}'.format(task))
            error, interrupt, error_buffer = False, False, []
            for line in output.split('\n'):
                if line.strip().startswith("FATAL") or line.strip().startswith("ERROR"):
                    error, interrupt = True, True
                elif line.strip().startswith("INFO"):
                    error = False
                    if len(error_buffer) > 0:
                        logger.error('Cooja error:\n' + '\n'.join(error_buffer))
                        error_buffer = []
                if error:
                    error_buffer.append(line)
            if interrupt:
                logger.warn("Cooja failed to execute ; 'run' interrupted (no parsing done)")
                raise Exception("Cooja failed to execute")
            # once the execution is over, gather the screenshots into a single GIF and keep the first and
            #  the last screenshots ; move these to the results folder
            logger.debug(" > Gathering screenshots in an animated GIF...")
            with lcd(data):
                local('convert -delay 10 -loop 0 network*.png wsn-{}-malicious.gif'.format(sim), capture=True)
            network_images = {int(fn.split('.')[0].split('_')[-1]): fn for fn in listdir(data)
                              if fn.startswith('network_')}
            move_files(data, results, 'wsn-{}-malicious.gif'.format(sim))
            if len(network_images) > 0:
                net_start_old = network_images[min(network_images.keys())]
                net_start, ext = splitext(net_start_old)
                net_start_new = 'wsn-{}-malicious_start{}'.format(sim, ext)
                net_end_old = network_images[max(network_images.keys())]
                net_end, ext = splitext(net_end_old)
                net_end_new = 'wsn-{}-malicious_end{}'.format(sim, ext)
                move_files(data, results, (net_start_old, net_start_new), (net_end_old, net_end_new))
                remove_files(data, *network_images.values())
            # then start the parsing functions to derive more results
            parsing_chain(sim_path, logger)
            move_files(sim_path, results, 'COOJA.log')
        # finally, generate the PDF report
        generate_report(path, REPORT_THEME)
    return "Both Cooja executions succeeded"