How to use the sh.bash function in sh

To help you get started, we’ve selected a few sh examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github projectcalico / calicoctl / tests / fv / __init__.py View on Github external
def setup_package():
    """
    Sets up docker images and host containers for running the STs.
    """
    containers = docker.ps("-qa").split()
    for container in containers:
        DockerHost.delete_container(container)
    print "Host containers removed."

    # Pull and save each image, so we can use them inside the host containers.
    print sh.bash("./build_node.sh").stdout
    docker.save("--output", "calico-node.tar", "calico/node")
    if not os.path.isfile("busybox.tar"):
        docker.pull("busybox:latest")
        docker.save("--output", "busybox.tar", "busybox:latest")
    if not os.path.isfile("nsenter.tar"):
        docker.pull("jpetazzo/nsenter:latest")
        docker.save("--output", "nsenter.tar", "jpetazzo/nsenter:latest")
    if not os.path.isfile("etcd.tar"):
        docker.pull("quay.io/coreos/etcd:v2.0.10")
        docker.save("--output", "etcd.tar", "quay.io/coreos/etcd:v2.0.10")

    # Create the calicoctl binary here so it will be in the volume mounted on the hosts.
    print sh.bash("./create_binary.sh")
    print "Calicoctl binary created."

    host1 = DockerHost('host1')
github projectcalico / libcalico / tests / fv / __init__.py View on Github external
def setup_package():
    """
    Sets up docker images and host containers for running the STs.
    """
    containers = docker.ps("-qa").split()
    for container in containers:
        DockerHost.delete_container(container)
    print "Host containers removed."

    # Pull and save each image, so we can use them inside the host containers.
    print sh.bash("./build_node.sh").stdout
    docker.save("--output", "calico-node.tar", "calico/node")
    if not os.path.isfile("busybox.tar"):
        docker.pull("busybox:latest")
        docker.save("--output", "busybox.tar", "busybox:latest")
    if not os.path.isfile("nsenter.tar"):
        docker.pull("jpetazzo/nsenter:latest")
        docker.save("--output", "nsenter.tar", "jpetazzo/nsenter:latest")
    if not os.path.isfile("etcd.tar"):
        docker.pull("quay.io/coreos/etcd:v2.0.10")
        docker.save("--output", "etcd.tar", "quay.io/coreos/etcd:v2.0.10")

    # Create the calicoctl binary here so it will be in the volume mounted on the hosts.
    print sh.bash("./create_binary.sh")
    print "Calicoctl binary created."

    host1 = DockerHost('host1')
github codelv / enaml-native-cli / tests / test_cli.py View on Github external
def cmd(*args, **kwargs):
        #: Make a wrapper to a that runs it in the venv
        return sh.bash('-c', 'source {venv}/bin/activate && {cmd} {args}'.format(
            venv=venv, cmd=command, args=" ".join(args)
        ), **kwargs)
github subsyncit / subsyncit / tests / integration_tests_of_sync_operations.py View on Github external
def make_a_big_random_file(self, filename, size):
        start = time.time()
        print("Making " + size + " MB random file " + filename + " (potentially time consuming, but once off) ... ")
        sh.bash("tests/make_a_so_big_file.sh", filename, size)
        print(" ... secs: " + str(round(time.time() - start, 1)))
github Wiredcraft / pipelines / pipelines / plugins / bash_executor.py View on Github external
f = open(self.log_file, 'a+')

        output = {'stdout': ''}
        try:
            def process_line(line):
                log.debug('Got line: %s' % line)
                output['stdout'] += line
                if f:
                    f.write(line)

                if self.event_mgr:
                    if len(line)>0 and line[-1] == '\n':
                        line = line[:-1]
                    self.event_mgr.trigger('on_task_event', {'output': line})

            proc = bash(_in=bash_input, _out=process_line, _err=process_line, _timeout=timeout)
            proc.wait()
            log.debug('Finished: %s, %s, %s' % (proc.exit_code, proc.stdout, proc.stderr))

        except ErrorReturnCode as e:
            log.warning('BashExec failed %s' % e.message)
            raise BashExecuteError("Execution failed with code: %s" % e.exit_code, e.exit_code, data=output)
        except TimeoutException as e:
            log.debug('BashExec timed out after %s seconds' % timeout)
            raise BashExecuteError("Task Timed Out", 1, data=output)
        return output['stdout']
github XiaoMi / mobile-ai-bench / aibench / python / bench_engine.py View on Github external
output_dir,
              dest_path,
              product_model
              ):
    i = 0
    while i < len(benchmark_list):
        print(
            "============================================================="
        )
        print("Trying to lock device %s" % device.address)
        with device_lock(device.address):
            start_time = time.time()
            print("Run on device: %s, %s, %s" %
                  (device.address, product_model, device.target_soc))
            try:
                sh.bash("tools/power.sh", device.address,
                        device.get_shell_prefix(),
                        device.target_soc, _fg=True)
            except Exception as e:
                print("Config power exception %s" % str(e))

            device.exec_command("mkdir -p %s" % device_bin_path)
            device.exec_command("rm -rf %s" %
                                os.path.join(device_bin_path,
                                             "interior"))
            device.exec_command("mkdir %s" %
                                os.path.join(device_bin_path,
                                             "interior"))
            device.exec_command("rm -rf %s" %
                                os.path.join(device_bin_path,
                                             "result.txt"))
github codelv / enaml-native-cli / python-for-ios / toolchain.py View on Github external
def execute(self):
        with current_directory('build'):
            if not exists('venv'):
                shprint(sh.virtualenv,'venv')
            info("Installing {} via pip".format(self.name))
            shprint(sh.bash,'-c','source venv/bin/activate && '
                                 'pip install {} --target={}'.format(self.name,self.ctx.site_packages_dir))
            info("{} installed!".format(self.name))

            #: Compile to pyo
            #: Compile pip packages to bytecode
            shprint(sh.bash,
                '-c',
                "source venv/bin/activate && env CC=/bin/false CXX=/bin/false "
                "python -O -m compileall -f {0}".format(self.ctx.site_packages_dir))

            #: Clean .dist-info etc..
        self.reduce_python_package()
github gobuild-old / gobuild3 / docker / crosscompile.py View on Github external
print 'Fetching', reponame
    fetch(reponame, tag)
    rdir = pathjoin(os.getenv('GOPATH'), 'src', args.repo)
    os.chdir(rdir) # change directory

    outjson['gobuildrc'] = open('.gobuild.yml').read() if os.path.exists('.gobuild.yml') else '# nothing'

    os_archs = [('linux','amd64'), ('linux','386'), ('linux','arm'),
            ('windows','amd64'), ('windows','386'),
            ('darwin','amd64'), ('darwin','386')]

    for goos, arch in os_archs:
        print '\033[92mBuilding for %s,%s\033[0m' %(goos, arch) # green color
        env = {}
        if goos == 'darwin':
            exportenv = str(sh.bash('-c', osxenv))
            for (key, value) in re.findall(r'export\s+([\w_]+)=([^\s]+)', exportenv):
                env[key] = value
        build(goos, arch, env=env)

    outjson['time_used'] = int(time.time())-outjson['created']
    print 'Saving state to out.json'
    print '------------ out.json -------------'
    with open(pathjoin(OUTDIR, 'out.json'), 'w') as f:
        json.dump(outjson, f)
    print json.dumps(outjson, indent=4)
github socialwifi / kubeyard / kubeyard / dependencies.py View on Github external
def is_command_available(name):
    try:
        sh.bash('which', name)
    except sh.ErrorReturnCode:
        return False
    else:
        return True
github socialwifi / kubeyard / kubeyard / commands / deploy.py View on Github external
def upload_tarred_files_with_local(self, statics_tar_process):
        statics_absolute_path = '{}/upload'.format(sh.pwd().strip())
        self._save_tar_to_volume(statics_tar_process, statics_absolute_path)
        sh.bash(
            '-c',
            " ".join([
                self.local_binary_path,
                'storage',
                'blob',
                'upload-batch',
                '--connection-string', '"{}"'.format(self.connection_string),
                '--destination', self.bucket_name,
                '--source', statics_absolute_path,
                '--destination-path', self.statics_directory,
            ]),
            _out=sys.stdout.buffer, _err=sys.stdout.buffer,
        )