當前位置: 首頁>>代碼示例>>Python>>正文


Python fnmatch.filter方法代碼示例

本文整理匯總了Python中fnmatch.filter方法的典型用法代碼示例。如果您正苦於以下問題:Python fnmatch.filter方法的具體用法?Python fnmatch.filter怎麽用?Python fnmatch.filter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在fnmatch的用法示例。


在下文中一共展示了fnmatch.filter方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_taxids_by_scientific_name_wildcard

# 需要導入模塊: import fnmatch [as 別名]
# 或者: from fnmatch import filter [as 別名]
def get_taxids_by_scientific_name_wildcard(self, scientific_name):
        """
        Return all available taxid that fit the scientific name

        @attention: Several taxid might be a hit for one scientific name

        @param scientific_name: ncbi scientific name or synonym
        @type scientific_name: str

        @return: set of ncbi taxonomic identifiers
        @rtype: set[str | unicode] | None
        """
        assert isinstance(scientific_name, str)
        scientific_name = scientific_name.lower()
        matches = fnmatch.filter(self.name_to_taxids.keys(), scientific_name)
        set_of_tax_id = set()
        for match in matches:
            set_of_tax_id.update(set(self.name_to_taxids[match]))
        if len(set_of_tax_id) > 1:
            self._logger.warning(
                "Several matches '{}' found for scientific_name: '{}'".format(", ".join(matches), scientific_name))
            return set_of_tax_id
        elif len(set_of_tax_id) == 0:
            return None
        return set_of_tax_id 
開發者ID:CAMI-challenge,項目名稱:CAMISIM,代碼行數:27,代碼來源:ncbitaxonomy.py

示例2: _apply_fname_filter

# 需要導入模塊: import fnmatch [as 別名]
# 或者: from fnmatch import filter [as 別名]
def _apply_fname_filter(fnames, include, exclude):
    # todo: multi filter with *.csv|*.xls*|*.txt, split on |
    def helper(list_,filter_):
        return list(itertools.chain.from_iterable(fnmatch.filter(list_, ifilter) for ifilter in filter_.split('|')))
    if include:
        fnames = helper(fnames, include)

    if exclude:
        fnamesex = helper(fnames, exclude)
        fnames = list(set(fnames) - set(fnamesex))

    return fnames


#************************************************
# Pipe
#************************************************ 
開發者ID:d6t,項目名稱:d6tpipe,代碼行數:19,代碼來源:pipe.py

示例3: read_logs

# 需要導入模塊: import fnmatch [as 別名]
# 或者: from fnmatch import filter [as 別名]
def read_logs(self):
        self.list_logs = []
        #
        print "reading and parsing all the log files ... "
        #
        for path, dirs, files in os.walk(self.path_tracks):
            for name_file in fnmatch.filter(files, 'log.txt'):
                path_log = os.path.abspath(
                    os.path.join(path, name_file)
                )
                #
                self.list_logs.append(
                    self.parse_log(path_log)
                )
                #
            #
        #
        print "done ! "
        #
    #
    # 
開發者ID:HMEIatJHU,項目名稱:neurawkes,代碼行數:23,代碼來源:organizers.py

示例4: find_results

# 需要導入模塊: import fnmatch [as 別名]
# 或者: from fnmatch import filter [as 別名]
def find_results(location, pattern):
    """ Create list of result files and return sorted

    Args:
      location (str): directory location to search
      pattern (str): glob style search pattern for results

    Returns:
      results (list): list of file paths for results found

    """
    # Note: already checked for location existence in main()
    records = []
    for root, dirnames, filenames in walk(location):
        for filename in fnmatch.filter(filenames, pattern):
            records.append(os.path.join(root, filename))

    if len(records) == 0:
        raise IOError('Could not find results in: %s' % location)

    records.sort()

    return records 
開發者ID:ceholden,項目名稱:yatsm,代碼行數:25,代碼來源:utils.py

示例5: idl2json

# 需要導入模塊: import fnmatch [as 別名]
# 或者: from fnmatch import filter [as 別名]
def idl2json(self):
        """
        Transform all IDL files in input folder to AVRO schemas in the output folder
        :return:
        """
        parser = argparse.ArgumentParser(
            description='Converts IDL to Avro JSON schema')
        # prefixing the argument with -- means it's optional
        parser.add_argument('--input', help='Input folder containing *.avdl files')
        parser.add_argument('--output', help='Output folder for the JSON schemas')
        args = parser.parse_args(sys.argv[2:])
        logging.info('idl2schema')
        makedir(args.output)
        idls = [os.path.join(dirpath, f)
                for dirpath, dirnames, files in os.walk(args.input)
                for f in fnmatch.filter(files, "*.{}".format(IDL_EXTENSION))]

        for idl in idls:
            logging.info("Transforming: " + idl)
            idl2schemata_command = "java -jar {} idl2schemata {} {}".format(
                AVRO_TOOLS_JAR, idl, args.output
            )
            logging.info("Running: [%s]" % idl2schemata_command)
            run_command(idl2schemata_command) 
開發者ID:genomicsengland,項目名稱:GelReportModels,代碼行數:26,代碼來源:conversion_tools.py

示例6: idl2avpr

# 需要導入模塊: import fnmatch [as 別名]
# 或者: from fnmatch import filter [as 別名]
def idl2avpr(self):
        """
        Transform all IDL files in input folder to AVPRs in the output folder
        :return:
        """
        parser = argparse.ArgumentParser(
            description='Converts IDL to AVPR')
        # prefixing the argument with -- means it's optional
        parser.add_argument('--input', help='Input folder containing *.avdl files')
        parser.add_argument('--output', help='Output folder for the AVPRs')
        args = parser.parse_args(sys.argv[2:])
        logging.info('idl2avpr')
        makedir(args.output)
        idls = [os.path.join(dirpath, f)
                for dirpath, dirnames, files in os.walk(args.input)
                for f in fnmatch.filter(files, "*.{}".format(IDL_EXTENSION))]
        for idl in idls:
            logging.info("Transforming: " + idl)
            file_name = os.path.basename(idl).replace(IDL_EXTENSION, AVPR_EXTENSION)
            idl2avpr_command = "java -jar {} idl {} {}/{}".format(
                AVRO_TOOLS_JAR, idl, args.output, file_name
            )
            logging.info("Running: [%s]" % idl2avpr_command)
            run_command(idl2avpr_command) 
開發者ID:genomicsengland,項目名稱:GelReportModels,代碼行數:26,代碼來源:conversion_tools.py

示例7: json2java

# 需要導入模塊: import fnmatch [as 別名]
# 或者: from fnmatch import filter [as 別名]
def json2java(self):
        """
        Transform all JSON Avro schemas in a given folder to Java source code.
        :return:
        """
        parser = argparse.ArgumentParser(
            description='Generates Java source code from Avro schemas')
        # NOT prefixing the argument with -- means it's not optional
        parser.add_argument('--input', help='Input folder containing *.avdl files')
        parser.add_argument('--output', help='Output folder for the Java source code')
        args = parser.parse_args(sys.argv[2:])
        logging.info('json2java')
        makedir(args.output)
        jsons = [os.path.join(dirpath, f)
                for dirpath, dirnames, files in os.walk(args.input)
                for f in fnmatch.filter(files, "*.{}".format(JSON_EXTENSION))]
        for json in jsons:
            logging.info("Transforming: " + json)
            idl2avpr_command = "java -jar {} compile -string schema {} {}".format(
                AVRO_TOOLS_JAR, json, args.output
            )
            logging.info("Running: [%s]" % idl2avpr_command)
            run_command(idl2avpr_command) 
開發者ID:genomicsengland,項目名稱:GelReportModels,代碼行數:25,代碼來源:conversion_tools.py

示例8: exclude_data_files

# 需要導入模塊: import fnmatch [as 別名]
# 或者: from fnmatch import filter [as 別名]
def exclude_data_files(self, package, src_dir, files):
        """Filter filenames for package's data files in 'src_dir'"""
        globs = (
            self.exclude_package_data.get('', [])
            + self.exclude_package_data.get(package, [])
        )
        bad = set(
            item
            for pattern in globs
            for item in fnmatch.filter(
                files,
                os.path.join(src_dir, convert_path(pattern)),
            )
        )
        seen = collections.defaultdict(itertools.count)
        return [
            fn
            for fn in files
            if fn not in bad
            # ditch dupes
            and not next(seen[fn])
        ] 
開發者ID:jpush,項目名稱:jbox,代碼行數:24,代碼來源:build_py.py

示例9: update

# 需要導入模塊: import fnmatch [as 別名]
# 或者: from fnmatch import filter [as 別名]
def update(path, data, dryrun=False, remote=False, gradle=False, interact=False):
    global is_dryrun
    is_dryrun = dryrun
    global check_remote
    check_remote = remote
    global check_gradle
    check_gradle = gradle
    global is_interact
    is_interact = interact

    for file in filter(path, "build.gradle"):
        parse_dependency(file, data)

    if check_gradle:
        gradle_version = andle.gradle.load()
        for file in filter(path, "gradle-wrapper.properties"):
            parse_gradle(file, gradle_version) 
開發者ID:Jintin,項目名稱:andle,代碼行數:19,代碼來源:android.py

示例10: get_images_count_recursive

# 需要導入模塊: import fnmatch [as 別名]
# 或者: from fnmatch import filter [as 別名]
def get_images_count_recursive(path):
    matches = []
    score_iou = []
    # logging.debug('path {}'.format(path))
    for root, dirnames, filenames in sorted(os.walk(path)):
        for filename in sorted(fnmatch.filter(filenames, '*.jpg')):
            # logging.debug('filename {}'.format(filename))
            matches.append(os.path.join(root, filename))
            score_iou.append(filename.split('_')[-1].replace('.jpg',''))

    # logging.debug('matches {}'.format(matches))

    images_count = len(matches)
    return score_iou, images_count

# nb_train_samples = 2000
# nb_validation_samples = 800 
開發者ID:abhishekrana,項目名稱:DeepFashion,代碼行數:19,代碼來源:train_multi_v2.py

示例11: find_data_files

# 需要導入模塊: import fnmatch [as 別名]
# 或者: from fnmatch import filter [as 別名]
def find_data_files(self, package, src_dir):
        """Return filenames for package's data files in 'src_dir'"""
        patterns = self._get_platform_patterns(
            self.package_data,
            package,
            src_dir,
        )
        globs_expanded = map(glob, patterns)
        # flatten the expanded globs into an iterable of matches
        globs_matches = itertools.chain.from_iterable(globs_expanded)
        glob_files = filter(os.path.isfile, globs_matches)
        files = itertools.chain(
            self.manifest_files.get(package, []),
            glob_files,
        )
        return self.exclude_data_files(package, src_dir, files) 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:18,代碼來源:build_py.py

示例12: exclude_data_files

# 需要導入模塊: import fnmatch [as 別名]
# 或者: from fnmatch import filter [as 別名]
def exclude_data_files(self, package, src_dir, files):
        """Filter filenames for package's data files in 'src_dir'"""
        files = list(files)
        patterns = self._get_platform_patterns(
            self.exclude_package_data,
            package,
            src_dir,
        )
        match_groups = (
            fnmatch.filter(files, pattern)
            for pattern in patterns
        )
        # flatten the groups of matches into an iterable of matches
        matches = itertools.chain.from_iterable(match_groups)
        bad = set(matches)
        keepers = (
            fn
            for fn in files
            if fn not in bad
        )
        # ditch dupes
        return list(_unique_everseen(keepers)) 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:24,代碼來源:build_py.py

示例13: walk

# 需要導入模塊: import fnmatch [as 別名]
# 或者: from fnmatch import filter [as 別名]
def walk(self, func, arg):
        """
        Walk this directory tree by calling the specified function
        for each directory in the tree.

        This behaves like the os.path.walk() function, but for in-memory
        Node.FS.Dir objects.  The function takes the same arguments as
        the functions passed to os.path.walk():

                func(arg, dirname, fnames)

        Except that "dirname" will actually be the directory *Node*,
        not the string.  The '.' and '..' entries are excluded from
        fnames.  The fnames list may be modified in-place to filter the
        subdirectories visited or otherwise impose a specific order.
        The "arg" argument is always passed to func() and may be used
        in any way (or ignored, passing None is common).
        """
        entries = self.entries
        names = list(entries.keys())
        names.remove('.')
        names.remove('..')
        func(arg, self, names)
        for dirname in [n for n in names if isinstance(entries[n], Dir)]:
            entries[dirname].walk(func, arg) 
開發者ID:Autodesk,項目名稱:arnold-usd,代碼行數:27,代碼來源:FS.py

示例14: exclude_data_files

# 需要導入模塊: import fnmatch [as 別名]
# 或者: from fnmatch import filter [as 別名]
def exclude_data_files(self, package, src_dir, files):
        """Filter filenames for package's data files in 'src_dir'"""
        globs = (self.exclude_package_data.get('', [])
                 + self.exclude_package_data.get(package, []))
        bad = []
        for pattern in globs:
            bad.extend(
                fnmatch.filter(
                    files, os.path.join(src_dir, convert_path(pattern))
                )
            )
        bad = dict.fromkeys(bad)
        seen = {}
        return [
            f for f in files if f not in bad
                and f not in seen and seen.setdefault(f,1)  # ditch dupes
        ] 
開發者ID:MayOneUS,項目名稱:pledgeservice,代碼行數:19,代碼來源:build_py.py

示例15: pytest_generate_tests

# 需要導入模塊: import fnmatch [as 別名]
# 或者: from fnmatch import filter [as 別名]
def pytest_generate_tests(metafunc):
    if 'scenario' in metafunc.fixturenames:
        scenarios = {}
        for root, dirnames, filenames in os.walk('tests/scenarios'):
            for filename in fnmatch.filter(filenames, '*.yml'):
                filepath = os.path.join(root, filename)
                scenarios.update(yaml.load(io.open(filepath, encoding='utf-8')) or {})
        params = []
        for name in sorted(scenarios):
            params.append([name, scenarios[name]])
        metafunc.parametrize('name, scenario', params) 
開發者ID:frictionlessdata,項目名稱:goodtables-py,代碼行數:13,代碼來源:conftest.py


注:本文中的fnmatch.filter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。