本文整理汇总了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
示例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
#************************************************
示例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 ! "
#
#
#
示例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
示例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)
示例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)
示例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)
示例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])
]
示例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)
示例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
示例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)
示例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))
示例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)
示例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
]
示例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)