本文整理匯總了Python中os.path.sep方法的典型用法代碼示例。如果您正苦於以下問題:Python path.sep方法的具體用法?Python path.sep怎麽用?Python path.sep使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類os.path
的用法示例。
在下文中一共展示了path.sep方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import sep [as 別名]
def get(self, model_directory):
""" Ensures required model is available at given location.
:param model_directory: Expected model_directory to be available.
:raise IOError: If model can not be retrieved.
"""
# Expend model directory if needed.
if not isabs(model_directory):
model_directory = join(self.DEFAULT_MODEL_PATH, model_directory)
# Download it if not exists.
model_probe = join(model_directory, self.MODEL_PROBE_PATH)
if not exists(model_probe):
if not exists(model_directory):
makedirs(model_directory)
self.download(
model_directory.split(sep)[-1],
model_directory)
self.writeProbe(model_directory)
return model_directory
示例2: create_unique_log_dir
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import sep [as 別名]
def create_unique_log_dir(config_rel_paths, log_dir_root, line_breaking_chars_pat=r'[-]', restore_dir=None):
"""
0117_1704 repr@soa3_med_8e*5_deePer_b50_noHM_C16 repr@v2_res_shallow RESTORE@path@to@restore@0115_1340
:param config_rel_paths:
:param log_dir_root:
:param line_breaking_chars_pat:
:return:
"""
if any(':' in config_rel_path for config_rel_path in config_rel_paths):
raise ValueError('":" not allowed in paths, got {}'.format(config_rel_paths))
def prep_path(p):
p = p.replace(path.sep, '@')
return re.sub(line_breaking_chars_pat, '*', p)
postfix_dir_name = ' '.join(map(prep_path, config_rel_paths))
if restore_dir:
restore_dir_root, restore_job_component = _split_log_dir(restore_dir)
restore_dir_root = restore_dir_root.replace(path.sep, '@')
restore_job_id = log_date_from_log_dir(restore_job_component)
postfix_dir_name += ' {restore_prefix}{root}@{job_id}'.format(
restore_prefix=_RESTORE_PREFIX, root=restore_dir_root, job_id=restore_job_id)
return _mkdir_threadsafe_unique(log_dir_root, datetime.now(), postfix_dir_name)
示例3: _split_log_dir
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import sep [as 別名]
def _split_log_dir(log_dir):
"""
given
some/path/to/job/dir/0101_1818 ae_config pc_config/ckpts
or
some/path/to/job/dir/0101_1818 ae_config pc_config
returns
tuple some/path/to/job/dir, 0101_1818 ae_config pc_config
"""
log_dir_root = []
job_component = None
for comp in log_dir.split(path.sep):
try:
log_date_from_log_dir(comp)
job_component = comp
break # this component is an actual log dir. stop and return components
except ValueError:
log_dir_root.append(comp)
assert job_component is not None, 'Invalid log_dir: {}'.format(log_dir)
return path.sep.join(log_dir_root), job_component
示例4: config_paths_from_log_dir
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import sep [as 別名]
def config_paths_from_log_dir(log_dir, base_dirs):
log_dir = path.basename(log_dir.strip(path.sep))
# log_dir == {now} {netconfig} {probconfig} [RESTORE@some_dir@XXXX_YYYY], get [netconfig, probconfig]
comps = log_dir.split(' ')
assert is_log_date(comps[0]), 'Invalid log_dir: {}'.format(log_dir)
comps = [c for c in comps[1:] if _RESTORE_PREFIX not in c]
assert len(comps) <= len(base_dirs), 'Expected as many config components as base dirs: {}, {}'.format(
comps, base_dirs)
def get_real_path(base, prepped_p):
p_glob = prepped_p.replace('@', path.sep)
p_glob = path.join(base, p_glob) # e.g., ae_configs/p_glob
glob_matches = glob.glob(p_glob)
# We always only replace one character with *, so filter for those.
# I.e. lr1e-5 will become lr1e*5, which will match lr1e-5 but also lr1e-4.5
glob_matches_of_same_len = [g for g in glob_matches if len(g) == len(p_glob)]
if len(glob_matches_of_same_len) != 1:
raise ValueError('Cannot find config on disk: {} (matches: {})'.format(p_glob, glob_matches_of_same_len))
return glob_matches_of_same_len[0]
return tuple(get_real_path(base_dir, comp) for base_dir, comp in zip(base_dirs, comps))
示例5: api_get_spec
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import sep [as 別名]
def api_get_spec(context, method_list):
'''Generates and Returns the spec file data
:param context: Dictionary with app, session, version and api fields
:type: ```dict```
:param method_list: List of API methods to call
:type: ```list```
:return: generated spec file
:rtype: ```basestring```
'''
_generate_documentation(context, method_list)
with open(tempfile.gettempdir() + op.sep + 'spec.yaml') as stream:
try:
spec_file = yaml.safe_load(stream)
except yaml.YAMLError as ex:
raise Exception("Please try again. Exception: {}".format(ex))
return json.dumps(spec_file)
示例6: write_temp
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import sep [as 別名]
def write_temp(self):
'''
Stores changes to the spec in a temp file.
'''
spec = {
"swagger": self.api.__getattribute__('swagger'),
"info": self.api.__getattribute__('info'),
"host": self.api.__getattribute__('host'),
"schemes": self.api.__getattribute__('schemes'),
"consumes": self.api.__getattribute__('consumes'),
"produces": self.api.__getattribute__('produces'),
"paths": self.api.__getattribute__('paths'),
"definitions": self.api.__getattribute__('definitions')
}
stream = file((tempfile.gettempdir() + op.sep + 'temp.yaml'), 'w')
for x in self.order:
yaml.dump({x: spec[x]}, stream, default_flow_style=False)
示例7: update_spec
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import sep [as 別名]
def update_spec(self):
'''
Updates the specification from the temp file.
'''
try:
os.rename(
tempfile.gettempdir() +
op.sep +
'temp.yaml',
tempfile.gettempdir() +
op.sep +
'spec.yaml')
except Exception as e:
raise Exception(
"Spec file not found, please try again."
" Exception: {}".format(e))
示例8: probably_a_local_import
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import sep [as 別名]
def probably_a_local_import(self, imp_name):
"""
Like the corresponding method in the base class, but this also
supports Cython modules.
"""
if imp_name.startswith(u"."):
# Relative imports are certainly not local imports.
return False
imp_name = imp_name.split(u".", 1)[0]
base_path = dirname(self.filename)
base_path = join(base_path, imp_name)
# If there is no __init__.py next to the file its not in a package
# so can't be a relative import.
if not exists(join(dirname(base_path), "__init__.py")):
return False
for ext in [".py", sep, ".pyc", ".so", ".sl", ".pyd", ".pyx"]:
if exists(base_path + ext):
return True
return False
示例9: test_iterator_persistence
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import sep [as 別名]
def test_iterator_persistence(self):
self._create_connector("odbc_iterator.json")
iterator_file_name = self.connector._OdbcConnector__iterator_file_name
device_id = 1 # For eval
data = {"deviceName": eval(self.config["mapping"]["device"]["name"]),
"deviceType": self.connector._OdbcConnector__connector_type,
"attributes": [],
"telemetry": [{"value": 0}]}
self.gateway.send_to_storage.assert_has_calls([call(self.connector.get_name(), data)])
self.connector.close()
sleep(1)
self.assertTrue(Path(self.CONFIG_PATH + "odbc" + path.sep + iterator_file_name).exists())
self.connector = OdbcConnector(self.gateway, self.config, "odbc")
self.connector.open()
sleep(1)
data["telemetry"] = [{"value": 5}]
self.gateway.send_to_storage.assert_has_calls([call(self.connector.get_name(), data)])
示例10: getSubdirs
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import sep [as 別名]
def getSubdirs(path, baseNamesOnly=True, excludePythonModulesDirs=True):
"""Provides a list of sub directories for the given path"""
subdirs = []
try:
path = realpath(path) + sep
for item in os.listdir(path):
candidate = path + item
if isdir(candidate):
if excludePythonModulesDirs:
modFile = candidate + sep + "__init__.py"
if exists(modFile):
continue
if baseNamesOnly:
subdirs.append(item)
else:
subdirs.append(candidate)
except:
pass
return subdirs
示例11: __matchInDir
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import sep [as 別名]
def __matchInDir(path, filters, startTime):
"""Provides the 'match' and 'too long' statuses"""
matched = False
tooLong = False
for item in listdir(path):
if time.time() - startTime > 0.1:
tooLong = True
return matched, tooLong
if isdir(path + item):
dname = path + item + sep
matched, tooLong = FindInFilesDialog.__matchInDir(dname,
filters,
startTime)
if matched or tooLong:
return matched, tooLong
continue
if FindInFilesDialog.__filterMatch(filters, path + item):
matched = True
return matched, tooLong
return matched, tooLong
示例12: __projectFiles
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import sep [as 別名]
def __projectFiles(self, filters):
"""Project files list respecting the mask"""
mainWindow = GlobalData().mainWindow
files = []
for fname in GlobalData().project.filesList:
if fname.endswith(sep):
continue
if self.__filterMatch(filters, fname):
widget = mainWindow.getWidgetForFileName(fname)
if widget is None:
# Do not check for broken symlinks
if isFileSearchable(fname, False):
files.append(ItemToSearchIn(fname, ""))
else:
if widget.getType() in \
[MainWindowTabWidgetBase.PlainTextEditor]:
files.append(ItemToSearchIn(fname,
widget.getUUID()))
QApplication.processEvents()
if self.__cancelRequest:
raise Exception("Cancel request")
return files
示例13: process_filenames
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import sep [as 別名]
def process_filenames(self, filenames):
data_list = []
categories_ids = [self.category_ids[cat] for cat in self.categories]
cat_idx = {categories_ids[i]: i for i in range(len(categories_ids))}
for name in filenames:
cat = name.split(osp.sep)[0]
if cat not in categories_ids:
continue
data = read_txt_array(osp.join(self.raw_dir, name))
pos = data[:, :3]
x = data[:, 3:6]
y = data[:, -1].type(torch.long)
data = Data(pos=pos, x=x, y=y, category=cat_idx[cat])
if self.pre_filter is not None and not self.pre_filter(data):
continue
if self.pre_transform is not None:
data = self.pre_transform(data)
data_list.append(data)
return data_list
示例14: test_orthogonalize_dense
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import sep [as 別名]
def test_orthogonalize_dense(collection):
transform.Factor(collection, 'trial_type', sep=sep)
sampling_rate = collection.sampling_rate
# Store pre-orth variables needed for tests
pg_pre = collection['trial_type/parametric gain'].to_dense(sampling_rate)
rt = collection['RT'].to_dense(sampling_rate)
# Orthogonalize and store result
transform.Orthogonalize(collection, variables='trial_type/parametric gain',
other='RT', dense=True, groupby=['run', 'subject'])
pg_post = collection['trial_type/parametric gain']
# Verify that the to_dense() calls result in identical indexing
ent_cols = ['subject', 'run']
assert pg_pre.to_df()[ent_cols].equals(rt.to_df()[ent_cols])
assert pg_post.to_df()[ent_cols].equals(rt.to_df()[ent_cols])
vals = np.c_[rt.values, pg_pre.values, pg_post.values]
df = pd.DataFrame(vals, columns=['rt', 'pre', 'post'])
groupby = rt.get_grouper(['run', 'subject'])
pre_r = df.groupby(groupby).apply(lambda x: x.corr().iloc[0, 1])
post_r = df.groupby(groupby).apply(lambda x: x.corr().iloc[0, 2])
assert (pre_r > 0.2).any()
assert (post_r < 0.0001).all()
示例15: calc_path_and_create_folders
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import sep [as 別名]
def calc_path_and_create_folders(folder, import_path, create_folder=True):
"""
calculate the path and create the needed folders
>>> calc_path_and_create_folders(folder='/somewhere/', import_path='foo.bar.BarClass', create_folder=False)
'/somewhere/foo/bar/BarClass'
:param import_path: 'foo.bar.BarClass'
:param folder: base folder where we wanna place 'foo.bar.BarClass' in.
"""
file_path = abspath(path_join(folder, import_path[:import_path.rfind(".")].replace(".", folder_seperator) + ".py"))
if create_folder:
mkdir_p(dirname(file_path))
# end if
return file_path
# end def