本文整理汇总了Python中glob.iglob方法的典型用法代码示例。如果您正苦于以下问题:Python glob.iglob方法的具体用法?Python glob.iglob怎么用?Python glob.iglob使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类glob
的用法示例。
在下文中一共展示了glob.iglob方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check
# 需要导入模块: import glob [as 别名]
# 或者: from glob import iglob [as 别名]
def check(self):
"""
Check that the service is running and consistent with pid file(s).
Returns True or False.
"""
# Set of pids (strings) where the command string matches what we are
# looking for.
detected_pids = set()
# Set of pids (strings) that are both running processes and found in
# pid files.
consistent_pids = set()
# Search for running processes that match our command string.
for proc in psutil.process_iter():
try:
if self.cmdstring in proc.name():
detected_pids.add(str(proc.pid))
# We could also get psutil.ZombieProcess or
# psutil.AccessDenied. We want those to be logged.
except psutil.NoSuchProcess:
pass
# Search for pid file(s) and check consistency.
for pidfile in self.pidfiles:
for path in glob.iglob(pidfile):
with open(path, 'r') as source:
pid = source.read().strip()
if pid in detected_pids:
consistent_pids.add(pid)
else:
# Delete the stale pid file.
os.remove(path)
return len(consistent_pids) > 0
示例2: get_vf_num_by_pci_address
# 需要导入模块: import glob [as 别名]
# 或者: from glob import iglob [as 别名]
def get_vf_num_by_pci_address(pci_addr):
"""Get the VF number based on a VF's pci address
A VF is associated with an VF number, which ip link command uses to
configure it. This number can be obtained from the PCI device filesystem.
"""
VIRTFN_RE = re.compile(r"virtfn(\d+)")
virtfns_path = "/sys/bus/pci/devices/%s/physfn/virtfn*" % (pci_addr)
vf_num = None
try:
for vf_path in glob.iglob(virtfns_path):
if re.search(pci_addr, os.readlink(vf_path)):
t = VIRTFN_RE.search(vf_path)
vf_num = t.group(1)
break
except Exception:
pass
if vf_num is None:
raise exception.PciDeviceNotFoundById(id=pci_addr)
return vf_num
示例3: load_plugin
# 需要导入模块: import glob [as 别名]
# 或者: from glob import iglob [as 别名]
def load_plugin(self, _, rtp: str):
self.update_rtp(rtp)
for d in rtp.split(','):
for vs in glob.iglob(path.join(d, 'ncm2-plugin/*.vim')):
if vs in self._loaded_plugins:
continue
self._loaded_plugins[vs] = True
logger.info('send vimscript plugin %s', vs)
self.notify('ncm2#_load_vimscript', vs)
for py in glob.iglob(path.join(d, 'ncm2-plugin/*.py')):
if py in self._loaded_plugins:
continue
self._loaded_plugins[py] = True
logger.info('send python plugin %s', py)
# async_call to get multiple exceptions properly printed
self.nvim.async_call(partial(self.load_python, _, py))
dts = glob.glob(path.join(d, 'pythonx/ncm2_subscope_detector/*.py')) + \
glob.glob(path.join(d, 'python3/ncm2_subscope_detector/*.py'))
self.load_subscope_detectors(dts)
self.notify('ncm2#_au_plugin')
示例4: __init__
# 需要导入模块: import glob [as 别名]
# 或者: from glob import iglob [as 别名]
def __init__(self, path, field, subsample=None, **kwargs):
fields = [(x, field) for x in self.fields]
examples = []
labels = {'neg': 'negative', 'pos': 'positive'}
question = 'Is this review negative or positive?'
cache_name = os.path.join(os.path.dirname(path), '.cache', os.path.basename(path), str(subsample))
if os.path.exists(cache_name):
print(f'Loading cached data from {cache_name}')
examples = torch.load(cache_name)
else:
for label in ['pos', 'neg']:
for fname in glob.iglob(os.path.join(path, label, '*.txt')):
with open(fname, 'r') as f:
context = f.readline()
answer = labels[label]
context_question = get_context_question(context, question)
examples.append(data.Example.fromlist([context, question, answer, CONTEXT_SPECIAL, QUESTION_SPECIAL, context_question], fields))
if subsample is not None and len(examples) > subsample:
break
os.makedirs(os.path.dirname(cache_name), exist_ok=True)
print(f'Caching data to {cache_name}')
torch.save(examples, cache_name)
super(imdb.IMDb, self).__init__(examples, fields, **kwargs)
示例5: __init__
# 需要导入模块: import glob [as 别名]
# 或者: from glob import iglob [as 别名]
def __init__(self, path, text_field, label_field, **kwargs):
"""Create an IMDB dataset instance given a path and fields.
Arguments:
path: Path to the dataset's highest level directory
text_field: The field that will be used for text data.
label_field: The field that will be used for label data.
Remaining keyword arguments: Passed to the constructor of
data.Dataset.
"""
fields = [('text', text_field), ('label', label_field)]
examples = []
for label in ['pos', 'neg']:
for fname in glob.iglob(os.path.join(path, label, '*.txt')):
with open(fname, 'r') as f:
text = f.readline()
examples.append(data.Example.fromlist([text, label], fields))
super(IMDb, self).__init__(examples, fields, **kwargs)
示例6: clean
# 需要导入模块: import glob [as 别名]
# 或者: from glob import iglob [as 别名]
def clean(path):
for f_xml in glob.iglob(os.path.join(path, '*.xml')):
print(f_xml)
f_txt = os.path.splitext(f_xml)[0]
with io.open(f_txt, mode='w', encoding='utf-8') as fd_txt:
root = ET.parse(f_xml).getroot()[0]
for doc in root.findall('doc'):
for e in doc.findall('seg'):
fd_txt.write(e.text.strip() + '\n')
xml_tags = ['<url', '<keywords', '<talkid', '<description',
'<reviewer', '<translator', '<title', '<speaker']
for f_orig in glob.iglob(os.path.join(path, 'train.tags*')):
print(f_orig)
f_txt = f_orig.replace('.tags', '')
with io.open(f_txt, mode='w', encoding='utf-8') as fd_txt, \
io.open(f_orig, mode='r', encoding='utf-8') as fd_orig:
for l in fd_orig:
if not any(tag in l for tag in xml_tags):
fd_txt.write(l.strip() + '\n')
示例7: __init__
# 需要导入模块: import glob [as 别名]
# 或者: from glob import iglob [as 别名]
def __init__(self, in_dir, transform):
super(ISSTestDataset, self).__init__()
self.in_dir = in_dir
self.transform = transform
# Find all images
self._images = []
for img_path in chain(
*(glob.iglob(path.join(self.in_dir, '**', ext), recursive=True) for ext in ISSTestDataset._EXTENSIONS)):
_, name_with_ext = path.split(img_path)
idx, _ = path.splitext(name_with_ext)
with Image.open(img_path) as img_raw:
size = (img_raw.size[1], img_raw.size[0])
self._images.append({
"idx": idx,
"path": img_path,
"size": size,
})
示例8: read_all
# 需要导入模块: import glob [as 别名]
# 或者: from glob import iglob [as 别名]
def read_all(pattern='data/lightbulb-*.csv'):
"""Read all of the CSVs in a directory matching the filename pattern
as TimeSeries.
"""
result = []
for filename in glob.iglob(pattern):
print('reading', filename, file=sys.stderr)
ts = traces.TimeSeries.from_csv(
filename,
time_column=0,
time_transform=parse_iso_datetime,
value_column=1,
value_transform=int,
default=0,
)
ts.compact()
result.append(ts)
return result
示例9: _migrate_get_earliest_version
# 需要导入模块: import glob [as 别名]
# 或者: from glob import iglob [as 别名]
def _migrate_get_earliest_version():
versions_glob = os.path.join(MIGRATE_REPO, 'versions', '???_*.py')
versions = []
for path in glob.iglob(versions_glob):
filename = os.path.basename(path)
prefix = filename.split('_', 1)[0]
try:
version = int(prefix)
except ValueError:
pass
versions.append(version)
versions.sort()
return versions[0]
### Git
示例10: _get_matching_files
# 需要导入模块: import glob [as 别名]
# 或者: from glob import iglob [as 别名]
def _get_matching_files(self, path, regex, start, end,):
"""Yield files that matches the search conditions.
Args:
path: Path to the directory that contains the files that should be
checked.
regex: A regular expression that should match the filename.
start: Datetime that defines the start of a time interval.
end: Datetime that defines the end of a time interval. The time
coverage of the file should overlap with this interval.
Yields:
A FileInfo object with the file path and time coverage
"""
for filename in glob.iglob(os.path.join(path, "*")):
if regex.match(filename):
file_info = self.get_info(filename)
# Test whether the file is overlapping the interval between
# start and end date.
if IntervalTree.interval_overlaps(
file_info.times, (start, end))\
and not self.is_excluded(file_info):
yield file_info
示例11: convert
# 需要导入模块: import glob [as 别名]
# 或者: from glob import iglob [as 别名]
def convert(installers, dest_dir, verbose):
require_pkgresources('wheel convert')
# Only support wheel convert if pkg_resources is present
from ..wininst2wheel import bdist_wininst2wheel
from ..egg2wheel import egg2wheel
for pat in installers:
for installer in iglob(pat):
if os.path.splitext(installer)[1] == '.egg':
conv = egg2wheel
else:
conv = bdist_wininst2wheel
if verbose:
sys.stdout.write("{0}... ".format(installer))
sys.stdout.flush()
conv(installer, dest_dir)
if verbose:
sys.stdout.write("OK\n")
示例12: distribution_cost
# 需要导入模块: import glob [as 别名]
# 或者: from glob import iglob [as 别名]
def distribution_cost(
dcop_files: List[str], distribution_file, algo, target
):
logger.debug(f"analyse file {dcop_files}")
dcop = load_dcop_from_file(dcop_files)
path_glob = os.path.abspath(os.path.expanduser(distribution_file))
distribution_files = sorted(glob.iglob(path_glob))
for distribution_file in distribution_files:
try:
cost, comm, hosting = single_distrib_costs(
dcop, distribution_file, algo
)
csv_writer = csv.writer(target)
csv_writer.writerow([dcop_files[0], distribution_file, cost, hosting, comm])
except:
pass
return target
示例13: input_files_glob
# 需要导入模块: import glob [as 别名]
# 或者: from glob import iglob [as 别名]
def input_files_glob(path_glob: str) -> List[str]:
"""
Find files matching a glob expression.
Parameters
----------
path_glob: str
unix style glob expression (e.g. '/home/user/foo/bar*.json')
Returns
-------
"""
path_glob = os.path.abspath(os.path.expanduser(path_glob))
logger.debug("Looking for files in %s", path_glob)
return list(glob.iglob(path_glob))
示例14: main
# 需要导入模块: import glob [as 别名]
# 或者: from glob import iglob [as 别名]
def main(args):
assert args.valid_percent >= 0 and args.valid_percent <= 1.
dir_path = os.path.realpath(args.root)
search_path = os.path.join(dir_path, '**/*.' + args.ext)
rand = random.Random(args.seed)
with open(os.path.join(args.dest, 'train.tsv'), 'w') as train_f, open(
os.path.join(args.dest, 'valid.tsv'), 'w') as valid_f:
print(dir_path, file=train_f)
print(dir_path, file=valid_f)
for fname in glob.iglob(search_path, recursive=True):
file_path = os.path.realpath(fname)
if args.path_must_contain and args.path_must_contain not in file_path:
continue
frames = soundfile.info(fname).frames
dest = train_f if rand.random() > args.valid_percent else valid_f
print('{}\t{}'.format(os.path.relpath(file_path, dir_path), frames), file=dest)
示例15: get_mq_yaml_configs
# 需要导入模块: import glob [as 别名]
# 或者: from glob import iglob [as 别名]
def get_mq_yaml_configs():
"""MQ aucr yaml config file from each plugin."""
mq_yaml_dict_config = {}
tasks_mq_list = []
reports_mq_list = []
analysis_mq_list = []
for filename in glob.iglob('aucr_app/plugins/**/mqtasks.yml', recursive=True):
mq_tasks = YamlInfo(filename, "none", "none")
run = mq_tasks.get()
if "tasks" in run:
tasks_mq_list.append(run["tasks"])
if "reports" in run:
reports_mq_list.append(run["reports"])
if "analysis" in run:
analysis_mq_list.append(run["analysis"])
mq_yaml_dict_config["tasks"] = tasks_mq_list
mq_yaml_dict_config["reports"] = reports_mq_list
mq_yaml_dict_config["analysis"] = analysis_mq_list
return mq_yaml_dict_config