How to use the sh.Command 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 ansible / molecule / test / unit / lint / test_yamllint.py View on Github external
def test_execute_bakes(_patched_get_files, patched_run_command, _instance):
    _instance.execute()

    assert _instance._yamllint_command is not None

    x = [str(sh.Command('yamllint')), '-s', '--foo=bar', 'foo.yml', 'bar.yaml']
    result = str(patched_run_command.mock_calls[0][1][0]).split()

    assert sorted(x) == sorted(result)
github codelv / enaml-native / python-for-android / pythonforandroid / build.py View on Github external
if self.android_api >= 21 and self.archs[0].arch == 'armeabi':
            error('Asked to build for armeabi architecture with API '
                  '{}, but API 21 or greater does not support armeabi'.format(
                      self.android_api))
            error('You probably want to build with --arch=armeabi-v7a instead')
            exit(1)

        targets = []
        if exists(join(sdk_dir, 'tools', 'android')):
            try:
                android = sh.Command(join(sdk_dir, 'tools', 'android'))
                targets = android('list').stdout.decode('utf-8').split('\n')
            except Exception as e:
                warning("Error running 'android list': {}".format(e))
        if not targets and exists(join(sdk_dir, 'tools', 'bin', 'avdmanager')):
            avdmanager = sh.Command(join(sdk_dir, 'tools', 'bin', 'avdmanager'))
            targets = avdmanager('list', 'target').stdout.decode('utf-8').split('\n')
        if not targets:
            error('Could not find `android` or `avdmanager` binaries in '
                  'Android SDK. Exiting.')
        apis = [s for s in targets if re.match(r'^ *API level: ', s)]
        apis = [re.findall(r'[0-9]+', s) for s in apis]
        apis = [int(s[0]) for s in apis if s]
        info('Available Android APIs are ({})'.format(
            ', '.join(map(str, apis))))
        if android_api in apis:
            info(('Requested API target {} is available, '
                  'continuing.').format(android_api))
        else:
            warning(('Requested API target {} is not available, install '
                     'it with the SDK android tool.').format(android_api))
            warning('Exiting.')
github JackSlateur / backurne / src / backurne / restore.py View on Github external
def __map_vmdk(self, path):
		for vmdk in glob.glob(f'{path}/*/*-flat.vmdk'):
			vmdk_file = vmdk.split('/')[-1]
			vmdk_overlay = f'/tmp/{self.clone}-{vmdk_file}.qcow2'
			Log.debug(f'qemu-img create {vmdk_overlay} over {vmdk}')
			sh.Command('qemu-img')('create', '-f', 'qcow2', '-b', vmdk, vmdk_overlay)
			next_nbd = get_next_nbd()
			Log.debug(f'qemu-nbd {vmdk_overlay} as {next_nbd}')
			sh.Command('qemu-nbd')('--connect', next_nbd, vmdk_overlay)
			wait_dev(next_nbd)
			try:
				maps = sh.Command('kpartx')('-av', next_nbd)
				for mapped in maps:
					mapped = mapped.rstrip()
					dev = mapped.split(' ')[2]
					dev = f'/dev/mapper/{dev}'
					self.mount_dev(dev)
			except Exception:
				pass
github JackSlateur / backurne / src / backurne / restore.py View on Github external
def umount_tree(self, tree):
		for child in tree.children:
			self.umount_tree(child)
			if tree.name.fstype == 'LVM2_member':
				Log.debug(f'\t{tree.name.dev}: lvchange -an {child.name.dev}')
				sh.Command('lvchange')('-an', child.name.dev)
		if tree.name.mountpoint is not None:
			Log.debug(f'\t{tree.name.dev}: umount {tree.name.mountpoint}')
			sh.Command('umount')(tree.name.mountpoint)
			Log.debug(f'\t{tree.name.dev}: rmdir {tree.name.mountpoint}')
			os.rmdir(tree.name.mountpoint)
			return
		if tree.name.mapped is True:
			Log.debug(f'\t{tree.name.dev}: kpartx -dv {tree.name.dev}')
			sh.Command('kpartx')('-dv', tree.name.dev)
			if tree.name.qemu_nbd is not None:
				Log.debug(f'\t{tree.name.dev}: qemu-nbd --disconnect {tree.name.dev}')
				sh.Command('qemu-nbd')('--disconnect', tree.name.dev)
				Log.debug(f'\t{tree.name.dev}: rm {tree.name.qemu_nbd}')
				os.unlink(tree.name.qemu_nbd)
				return

		if tree.name.image is not None:
			Log.debug(f'\t{tree.name.dev}: rbd unmap {tree.name.image}')
			self.ceph.unmap(tree.name.dev)
			Log.debug(f'\t{tree.name.dev}: rbd rm {tree.name.image}')
			self.ceph.rm(tree.name.image)
			Log.debug(f'\t{tree.name.dev}: rbd unprotect --snap {tree.name.parent_snap} {tree.name.parent_image}')
			self.ceph.unprotect(f'{tree.name.parent_image}@{tree.name.parent_snap}')
			return
		Log.debug(f'{tree.name.dev}: Nothing to do ?')
github kivy / python-for-android / pythonforandroid / recipes / libx264 / __init__.py View on Github external
def build_arch(self, arch):
        with current_directory(self.get_build_dir(arch.arch)):
            env = self.get_recipe_env(arch)
            if 'arm64' in arch.arch:
                cross_prefix = 'aarch64-linux-android-'
            else:
                cross_prefix = 'arm-linux-androideabi-'
            configure = sh.Command('./configure')
            shprint(configure,
                    '--cross-prefix={}'.format(cross_prefix),
                    '--host=arm-linux',
                    '--disable-asm',
                    '--disable-cli',
                    '--enable-pic',
                    '--disable-shared',
                    '--enable-static',
                    '--prefix={}'.format(realpath('.')),
                    _env=env)
            shprint(sh.make, '-j', str(cpu_count()), _env=env)
            shprint(sh.make, 'install', _env=env)
github Bystroushaak / tinySelf / compile.py View on Github external
if debug:
        args["lldebug"] = True
        args["lldebug0"] = True

    if quit_pdb:
        args["batch"] = True

    rpython_path = "rpython"
    if "RPYTHON_PATH" in os.environ:
        rpython_path = os.path.join(
            os.environ["RPYTHON_PATH"],
            "rpython"
        )

    try:
        rpython = sh.Command(rpython_path)
    except sh.CommandNotFound:
        raise ValueError(
            "rpython not found!\n\nPut it into $PATH or use $RPYTHON_PATH env "
            "variable to specify it."
        )

    try:
        rpython(args, target_path, _fg=True)
    except sh.ErrorReturnCode_1:
        pass
github lbryio / lbry-android / p4a / pythonforandroid / recipes / libtorrent / __init__.py View on Github external
'libtorrent-link=shared',
            'runtime-link=shared',
            'encryption={}'.format('on' if encryption == 'openssl' else 'off'),
            'crypto=' + encryption
        ]
        crypto_folder = 'encryption-off'
        if encryption == 'openssl':
            crypto_folder = 'crypto-openssl'
            build_args.extend(['openssl-lib=' + env['OPENSSL_BUILD_PATH'],
                               'openssl-include=' + env['OPENSSL_INCLUDE']
                               ])
        build_args.append('release')

        # Compile libtorrent with boost libraries and python bindings
        with current_directory(join(build_dir, 'bindings/python')):
            b2 = sh.Command(join(env['BOOST_ROOT'], 'b2'))
            shprint(b2, *build_args, _env=env)

        # Copy only the boost shared libraries into the libs folder. Because
        # boost build two boost_python libraries, we force to search the lib
        # into the corresponding build path.
        b2_build_dir = 'build/clang-linux-arm/release/{encryption}/' \
                       'lt-visibility-hidden/'.format(encryption=crypto_folder)
        boost_libs_dir = join(env['BOOST_BUILD_PATH'], 'bin.v2/libs')
        for boost_lib in listdir(boost_libs_dir):
            lib_path = get_lib_from(join(boost_libs_dir, boost_lib, b2_build_dir))
            if lib_path:
                lib_name = basename(lib_path)
                shutil.copyfile(lib_path, join(ctx_libs_dir, lib_name))

        # Copy libtorrent shared libraries into the right places
        system_libtorrent = get_lib_from(join(build_dir, 'bin'))
github lbryio / lbry-android / p4a / pythonforandroid / recipes / freetype / __init__.py View on Github external
def build_arch(self, arch):
        env = self.get_recipe_env(arch)

        harfbuzz_recipe = Recipe.get_recipe('harfbuzz', self.ctx)
        env['LDFLAGS'] = ' '.join(
            [env['LDFLAGS'],
             '-L{}'.format(join(harfbuzz_recipe.get_build_dir(arch.arch),
                                'src', '.libs'))])

        with current_directory(self.get_build_dir(arch.arch)):
            configure = sh.Command('./configure')
            shprint(configure,
                    '--host=arm-linux-androideabi',
                    '--prefix={}'.format(realpath('.')),
                    '--without-zlib',
                    '--with-png=no',
                    '--disable-shared',
                    _env=env)
            shprint(sh.make, '-j5', _env=env)

            shprint(sh.cp, 'objs/.libs/libfreetype.a', self.ctx.libs_dir)
github codelv / enaml-native-cli / python-for-android / pythonforandroid / recipe.py View on Github external
def install_hostpython_package(self, arch):
        env = self.get_hostrecipe_env(arch)
        real_hostpython = sh.Command(self.real_hostpython_location)
        if ('python2crystax' in self.ctx.recipe_build_order or
            'python3crystax' in self.ctx.recipe_build_order):
            shprint(real_hostpython, 'setup.py', 'install', '-O2',
                    _env=env, *self.setup_extra_args)
            return
        shprint(real_hostpython, 'setup.py', 'install', '-O2',
                '--root={}'.format(dirname(self.real_hostpython_location)),
                '--install-lib=Lib/site-packages',
                _env=env, *self.setup_extra_args)
github kivy / python-for-android / pythonforandroid / recipes / libcurl / __init__.py View on Github external
def build_arch(self, arch):
        env = self.get_recipe_env(arch)

        openssl_recipe = self.get_recipe('openssl', self.ctx)
        openssl_dir = openssl_recipe.get_build_dir(arch.arch)

        env['LDFLAGS'] += openssl_recipe.link_dirs_flags(arch)
        env['LIBS'] = env.get('LIBS', '') + openssl_recipe.link_libs_flags()

        with current_directory(self.get_build_dir(arch.arch)):
            dst_dir = join(self.get_build_dir(arch.arch), 'dist')
            shprint(
                sh.Command('./configure'),
                '--host=arm-linux-androideabi',
                '--enable-shared',
                '--with-ssl={}'.format(openssl_dir),
                '--prefix={}'.format(dst_dir),
                _env=env)
            shprint(sh.make, '-j', str(cpu_count()), _env=env)
            shprint(sh.make, 'install', _env=env)