How to use the sh.find 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 kivy / python-for-android / pythonforandroid / bootstraps / sdl2_gradle / __init__.py View on Github external
else:  # Python *is* loaded from crystax
                ndk_dir = self.ctx.ndk_dir
                py_recipe = self.ctx.python_recipe
                python_dir = join(ndk_dir, 'sources', 'python',
                                  py_recipe.version, 'libs', arch.arch)
                shprint(sh.cp, '-r', join(python_dir,
                                          'stdlib.zip'), crystax_python_dir)
                shprint(sh.cp, '-r', join(python_dir,
                                          'modules'), crystax_python_dir)
                shprint(sh.cp, '-r', self.ctx.get_python_install_dir(),
                        join(crystax_python_dir, 'site-packages'))

                info('Renaming .so files to reflect cross-compile')
                site_packages_dir = join(crystax_python_dir, "site-packages")
                find_ret = shprint(
                    sh.find, site_packages_dir, '-iname', '*.so')
                filenames = find_ret.stdout.decode('utf-8').split('\n')[:-1]
                for filename in filenames:
                    parts = filename.split('.')
                    if len(parts) <= 2:
                        continue
                    shprint(sh.mv, filename, filename.split('.')[0] + '.so')
                site_packages_dir = join(abspath(curdir),
                                         site_packages_dir)
            if 'sqlite3' not in self.ctx.recipe_build_order:
                with open('blacklist.txt', 'a') as fileh:
                    fileh.write('\nsqlite3/*\nlib-dynload/_sqlite3.so\n')

        self.strip_libraries(arch)
        self.fry_eggs(site_packages_dir)
        super(SDL2GradleBootstrap, self).run_distribute()
github codelv / enaml-native-cli / python-for-android / pythonforandroid / bootstraps / enaml / __init__.py View on Github external
# shprint(sh.rm, '-rf', 'lib-dynload/_testcapi.so')

            else:  # Python *is* loaded from crystax
                ndk_dir = self.ctx.ndk_dir
                py_recipe = self.ctx.python_recipe
                python_dir = join(ndk_dir, 'sources', 'python', py_recipe.version,
                                  'libs', arch.arch)
                if not exists('python'):
                    shprint(sh.mkdir, '-p', 'python')
                shprint(sh.cp, '-r', join(python_dir, 'stdlib.zip'), 'python/')
                shprint(sh.cp, '-r', join(python_dir, 'modules'), 'python/modules')
                shprint(sh.cp, '-r', self.ctx.get_python_install_dir(), 'python/site-packages')

                info('Renaming .so files to reflect cross-compile')
                site_packages_dir = 'python/site-packages'
                filens = shprint(sh.find, site_packages_dir, '-iname', '*.so').stdout.decode(
                    'utf-8').split('\n')[:-1]
                for filen in filens:
                    parts = filen.split('.')
                    if len(parts) <= 2:
                        continue
                    shprint(sh.mv, filen, filen.split('.')[0] + '.so')
                site_packages_dir = join(abspath(curdir),
                                         site_packages_dir)


        self.strip_libraries(arch)
        self.fry_eggs(site_packages_dir)
        super(PlainBootstrap, self).run_distribute()
github lbryio / lbry-android / p4a / pythonforandroid / bootstrap.py View on Github external
def strip_libraries(self, arch):
        info('Stripping libraries')
        if self.ctx.python_recipe.from_crystax:
            info('Python was loaded from CrystaX, skipping strip')
            return
        env = arch.get_env()
        tokens = shlex.split(env['STRIP'])
        strip = sh.Command(tokens[0])
        if len(tokens) > 1:
            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 kivy / kivy-ios / recipes / python3 / __init__.py View on Github external
# cleanup pkgconfig and compiled lib
            os.chdir(join(self.ctx.dist_dir, "root", "python3", "lib"))
            sh.rm("-rf", "pkgconfig")
            sh.rm("-f", "libpython3.7m.a")

            # cleanup python libraries
            os.chdir(join(
                self.ctx.dist_dir, "root", "python3", "lib", "python3.7"))
            sh.rm("-rf", "wsgiref", "curses", "idlelib", "lib2to3",
                  "ensurepip", "turtledemo", "lib-dynload", "venv",
                  "pydoc_data")
            sh.find(".", "-path", "*/test*/*", "-delete")
            sh.find(".", "-name", "*.exe", "-type", "f", "-delete")
            sh.find(".", "-name", "test*", "-type", "d", "-delete")
            sh.find(".", "-iname", "*.pyc", "-delete")
            sh.find(".", "-path", "*/__pycache__/*", "-delete")
            sh.find(".", "-name", "__pycache__", "-type", "d", "-delete")

            # now precompile to Python bytecode
            hostpython = sh.Command(self.ctx.hostpython)
            shprint(hostpython, "-m", "compileall", "-f", "-b")
            # sh.find(".", "-iname", "*.py", "-delete")

            # some pycache are recreated after compileall
            sh.find(".", "-path", "*/__pycache__/*", "-delete")
            sh.find(".", "-name", "__pycache__", "-type", "d", "-delete")

            # create the lib zip
            logger.info("Create a python3.7.zip")
            sh.mv("config-3.7m-darwin", "..")
            sh.mv("site-packages", "..")
github codelv / enaml-native / python-for-ios / toolchain.py View on Github external
def reduce_python_package(self):
        with current_directory(self.ctx.site_packages_dir):
            #shprint(sh.find,'.','-type','f','-name','*.py','-delete')
            shprint(sh.find,'.','-type','f','-name','*.pyc','-delete')
            #shprint(sh.find,'.','-type','f','-name','*.pyo','-delete') #: Use pyo
            for p in [
                'enaml/qt',
                'tornado/test',
                '*.egg-info',
                '*.dist-info',
                'tests',
                'usr',
            ]:
                try:
                    sh.rm('-R', *glob.glob(p))
                except:
                    pass
github hbc / projects / kraft_wgs / scripts / annotate.py View on Github external
def main(config_file):
    # load yaml config file
    with open(config_file) as in_handle:
        config = yaml.load(in_handle)

    # setup logging
    setup_logging(config)
    from bipy.log import logger
    # start cluster
    start_cluster(config)
    from bipy.cluster import view

    found = sh.find(config["dir"]["data"], "-name", "Variations")
    var_dirs = [str(x).strip() for x in found]
    logger.info("Var_dirs: %s" % (var_dirs))
    in_dirs = map(os.path.dirname, var_dirs)
    logger.info("in_dirs: %s" % (in_dirs))
    # XXX for testing only load 3
    #curr_files = in_dirs[0:5]
    curr_files = in_dirs


    # run the illumina fixer
    logger.info("Running illumina fixer on %s." % (curr_files))
    illf_class = STAGE_LOOKUP.get("illumina_fixer")
    illf = illf_class(config)
    curr_files = view.map(illf, curr_files)

    # sort the vcf files
github kivy / kivy-ios / recipes / python3 / __init__.py View on Github external
sh.rm("makesetup")
            sh.rm("install-sh")

            # cleanup pkgconfig and compiled lib
            os.chdir(join(self.ctx.dist_dir, "root", "python3", "lib"))
            sh.rm("-rf", "pkgconfig")
            sh.rm("-f", "libpython3.7m.a")

            # cleanup python libraries
            os.chdir(join(
                self.ctx.dist_dir, "root", "python3", "lib", "python3.7"))
            sh.rm("-rf", "wsgiref", "curses", "idlelib", "lib2to3",
                  "ensurepip", "turtledemo", "lib-dynload", "venv",
                  "pydoc_data")
            sh.find(".", "-path", "*/test*/*", "-delete")
            sh.find(".", "-name", "*.exe", "-type", "f", "-delete")
            sh.find(".", "-name", "test*", "-type", "d", "-delete")
            sh.find(".", "-iname", "*.pyc", "-delete")
            sh.find(".", "-path", "*/__pycache__/*", "-delete")
            sh.find(".", "-name", "__pycache__", "-type", "d", "-delete")

            # now precompile to Python bytecode
            hostpython = sh.Command(self.ctx.hostpython)
            shprint(hostpython, "-m", "compileall", "-f", "-b")
            # sh.find(".", "-iname", "*.py", "-delete")

            # some pycache are recreated after compileall
            sh.find(".", "-path", "*/__pycache__/*", "-delete")
            sh.find(".", "-name", "__pycache__", "-type", "d", "-delete")

            # create the lib zip
            logger.info("Create a python3.7.zip")
github mobile-insight / mobileinsight-mobile / recipes / mobileinsight / __init__.py View on Github external
app_setup  = join(self.get_build_dir(arch.arch), 'setup.py')

            if not exists(app_mk):
                shprint(sh.cp, join(self.get_recipe_dir(), 'Application.mk'), app_mk)
            if not exists(app_setup):
                shprint(sh.cp, join(self.get_recipe_dir(), 'setup.py'), app_setup)

            shprint(hostpython, 'setup.py', 'build_ext', '-v', _env = env, _tail = 10, _critical = True)
            shprint(hostpython, 'setup.py', 'install',  '-O2', _env = env, _tail = 10, _critical = True)

            build_lib = glob.glob('./build/lib*')
            assert len(build_lib) == 1
            warning('MI2 -- stripping mobileinsight')

            # shprint(sh.find, build_lib[0], '-name', '*.o', '-exec', env['STRIP'], '{}', ';', _tail = 20, _critical = True)
            shprint(sh.find, build_lib[0], '-name', '*.so', '-exec', env['STRIP'], '{}', ';', _tail = 20, _critical = True)

        try:
            warning('copying GNU STL shared lib to {libs_dir}/{arch}'.format(
                    libs_dir          = self.ctx.libs_dir,
                    arch              = arch))
            shprint(sh.cp,
                '{ndk_dir}/sources/cxx-stl/gnu-libstdc++/{toolchain_version}/libs/{arch}/libgnustl_shared.so'.format(
                    ndk_dir           = self.ctx.ndk_dir,
                    toolchain_version = self.toolchain_version,
                    arch              = arch),
                '{libs_dir}/{arch}'.format(
                    libs_dir          = self.ctx.libs_dir,
                    arch              = arch))
        except:
            warning('failed to copy GNU STL shared lib!!')
github XiaoMi / mace / tools / sh_commands.py View on Github external
def find_asan_rt_library(abi, asan_rt_path=''):
    if not asan_rt_path:
        find_path = os.environ['ANDROID_NDK_HOME']
        candidates = split_stdout(sh.find(find_path, "-name",
                                          asan_rt_library_names(abi)))
        if len(candidates) == 0:
            common.MaceLogger.error(
                "Toolchain",
                "Can't find AddressSanitizer runtime library in %s" %
                find_path)
        elif len(candidates) > 1:
            common.MaceLogger.info(
                "More than one AddressSanitizer runtime library, use the 1st")
        return candidates[0]
    return "%s/%s" % (asan_rt_path, asan_rt_library_names(abi))