本文整理匯總了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