How to use the sh.ErrorReturnCode_1 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 Azure / azure-cli / scripts / smoke_test_install / _common.py View on Github external
def verify_tab_complete(vm):
    # TODO: Also check completion by running 'complete' and using grep to verify the output
    try:
        vm(['grep', '-q', "\"source '/usr/local/az/az.completion'\"", '~/.bashrc'])
    except sh.ErrorReturnCode_1 as e:
        raise Exception("Tab completion should be enabled but source command not found in rc file")
github ansible / molecule / test / unit / verifier / lint / test_ansible_lint.py View on Github external
def test_executes_catches_and_exits_return_code(
    patched_run_command, patched_yamllint, _instance
):
    patched_run_command.side_effect = sh.ErrorReturnCode_1(sh.ansible_lint, b'', b'')
    with pytest.raises(SystemExit) as e:
        _instance.execute()

    assert 1 == e.value.code
github projectcalico / libcalico / tests / fv / test_multi_host.py View on Github external
host1.listen(calicoctl % "profile PROF_A_C_E member add workload-A")
        host1.listen(calicoctl % "profile PROF_B member add workload-B")
        host1.listen(calicoctl % "profile PROF_A_C_E member add workload-C")

        host2.listen(calicoctl % "profile PROF_D member add workload-D")
        host2.listen(calicoctl % "profile PROF_A_C_E member add workload-E")

        # Wait for the workload networking to converge.
        sleep(1)

        host1.execute("docker exec workload-A ping -c 4 192.168.1.3")

        try:
            host1.execute("docker exec workload-A ping -c 4 192.168.1.2")
            raise
        except ErrorReturnCode_1:
            pass

        try:
            host1.execute("docker exec workload-A ping -c 4 192.168.1.4")
            raise
        except ErrorReturnCode_1:
            pass

        host1.execute("docker exec workload-A ping -c 4 192.168.1.5")
github ansible / molecule / test / unit / verifier / lint / test_yamllint.py View on Github external
def test_executes_catches_and_exits_return_code(
    patched_run_command, _patched_get_tests, _instance
):
    patched_run_command.side_effect = sh.ErrorReturnCode_1(sh.yamllint, b'', b'')
    with pytest.raises(SystemExit) as e:
        _instance.execute()

    assert 1 == e.value.code
github charlesthomas / magpie / magpie / handler / note.py View on Github external
tmp.append(line)
                f.close()
                note_contents = ''.join(tmp)

            f = open(path, 'w')
            f.write(note_contents.encode('utf8'))
            f.close()

            self.application.git.add(path)
            try:
                if note_contents == '':
                    message = 'creating %s' % path
                else:
                    message = 'updating %s' % path
                self.application.git.commit('-m', message)
            except ErrorReturnCode_1 as e:
                if 'nothing to commit' not in e.message:
                    raise
            if note_name_rename and note_name_rename != note_name:
                # rename note
                message = 'moving %s to %s' % (path, rename_path)
                # TODO: don't force; do something more graceful
                self.application.git.mv('-f', path, rename_path)
                self.application.git.commit('-m', message)
                note_enc = rename_note_enc
            self.redirect(note_enc.replace('#', '%23'))
github codelv / enaml-native-cli / python-for-android / pythonforandroid / bootstrap.py View on Github external
info('Python was loaded from CrystaX, skipping strip')
            return
        env = arch.get_env()
        strip = which('arm-linux-androideabi-strip', env['PATH'])
        if strip is None:
            warning('Can\'t find strip in PATH...')
            return
        strip = sh.Command(strip)
        filens = shprint(sh.find, join(self.dist_dir, 'private'),
                         join(self.dist_dir, 'libs'),
                         '-iname', '*.so', _env=env).stdout.decode('utf-8')
        logger.info('Stripping libraries in private dir')
        for filen in filens.split('\n'):
            try:
                strip(filen, _env=env)
            except sh.ErrorReturnCode_1:
                logger.debug('Failed to strip ' + filen)
github lbryio / lbry-android / p4a / pythonforandroid / bootstrap.py View on Github external
strip = strip.bake(tokens[1:])

        libs_dir = join(self.dist_dir, '_python_bundle',
                        '_python_bundle', 'modules')
        if self.ctx.python_recipe.name == 'python2legacy':
            libs_dir = join(self.dist_dir, 'private')
        filens = shprint(sh.find, libs_dir, join(self.dist_dir, 'libs'),
                         '-iname', '*.so', _env=env).stdout.decode('utf-8')

        logger.info('Stripping libraries in private dir')
        for filen in filens.split('\n'):
            if not filen:
                continue  # skip the last ''
            try:
                strip(filen, _env=env)
            except sh.ErrorReturnCode_1:
                logger.debug('Failed to strip ' + filen)
github ansible / molecule / molecule / commands.py View on Github external
if os.path.isdir(role):
                msg = 'The directory {} already exists. Cannot create new role.'
                utilities.logger.error(msg.format(role))
                sys.exit(1)

            role_path = os.path.join(os.curdir, role)

            utilities.print_info("Initializing role {}...".format(role))

            try:
                if self.molecule._args['--offline']:
                    sh.ansible_galaxy('init', '--offline', role)
                else:
                    sh.ansible_galaxy('init', role)
            except (subprocess.CalledProcessError, sh.ErrorReturnCode_1) as e:
                utilities.logger.error('ERROR: {}'.format(e))
                sys.exit(e.returncode)

            self.clean_meta_main(role_path)

        env = jinja2.Environment(
            loader=jinja2.PackageLoader('molecule', 'templates'),
            keep_trailing_newline=True)

        t_molecule = env.get_template(self.molecule._config.config['molecule'][
            'init']['templates']['molecule'])
        t_playbook = env.get_template(self.molecule._config.config['molecule'][
            'init']['templates']['playbook'])
        t_test_default = env.get_template(self.molecule._config.config[
            'molecule']['init']['templates']['test_default'])
github XiaoMi / mace / tools / device.py View on Github external
def push(self, src_path, dst_path):
        mace_check(os.path.exists(src_path), "Device",
                   '{} not found'.format(src_path))
        six.print_("Push %s to %s" % (src_path, dst_path))
        if self.system == SystemType.android:
            sh_commands.adb_push(src_path, dst_path, self.address)
        elif self.system == SystemType.arm_linux:
            try:
                sh.scp(src_path, '{}@{}:{}'.format(self.username,
                                                   self.address,
                                                   dst_path))
            except sh.ErrorReturnCode_1 as e:
                six.print_('Push Failed !', e, file=sys.stderr)
                raise e
github lbryio / lbry-android / p4a / pythonforandroid / recipe.py View on Github external
info('Cythonizing anything necessary in {}'.format(self.name))

        env = self.get_recipe_env(arch)

        with current_directory(self.get_build_dir(arch.arch)):
            hostpython = sh.Command(self.ctx.hostpython)
            shprint(hostpython, '-c', 'import sys; print(sys.path)', _env=env)
            debug('cwd is {}'.format(realpath(curdir)))
            info('Trying first build of {} to get cython files: this is '
                 'expected to fail'.format(self.name))

            manually_cythonise = False
            try:
                shprint(hostpython, 'setup.py', 'build_ext', '-v', _env=env,
                        *self.setup_extra_args)
            except sh.ErrorReturnCode_1:
                print()
                info('{} first build failed (as expected)'.format(self.name))
                manually_cythonise = True

            if manually_cythonise:
                self.cythonize_build(env=env)
                shprint(hostpython, 'setup.py', 'build_ext', '-v', _env=env,
                        _tail=20, _critical=True, *self.setup_extra_args)
            else:
                info('First build appeared to complete correctly, skipping manual'
                     'cythonising.')

            self.strip_object_files(arch, env)