本文整理匯總了Python中os.path.isabs方法的典型用法代碼示例。如果您正苦於以下問題:Python path.isabs方法的具體用法?Python path.isabs怎麽用?Python path.isabs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類os.path
的用法示例。
在下文中一共展示了path.isabs方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import isabs [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: _move
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import isabs [as 別名]
def _move(self, path):
if path == self.path:
return
files = self.get_marked() or self.get_selected()
if not isabs(path):
path = join(self.path, path)
if not isdir(path):
sublime.error_message('Not a valid directory: {}'.format(path))
return
# Move all items into the target directory. If the target directory was also selected,
# ignore it.
files = self.get_marked() or self.get_selected()
path = normpath(path)
for filename in files:
fqn = normpath(join(self.path, filename))
if fqn != path:
shutil.move(fqn, path)
self.view.run_command('dired_refresh')
示例3: send2trash
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import isabs [as 別名]
def send2trash(path):
if not isinstance(path, text_type):
path = text_type(path, 'mbcs')
if not op.isabs(path):
path = op.abspath(path)
fileop = SHFILEOPSTRUCTW()
fileop.hwnd = 0
fileop.wFunc = FO_DELETE
fileop.pFrom = LPCWSTR(path + '\0')
fileop.pTo = None
fileop.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT
fileop.fAnyOperationsAborted = 0
fileop.hNameMappings = 0
fileop.lpszProgressTitle = None
result = SHFileOperationW(byref(fileop))
if result:
msg = "Couldn't perform operation. Error code: %d" % result
raise OSError(msg)
示例4: remove_local_modules_from_sys
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import isabs [as 別名]
def remove_local_modules_from_sys(testdir):
"""remove all modules from cache that come from `testdir`
This is used to avoid strange side-effects when using the
testall() mode of pytest.
For instance, if we run pytest on this tree::
A/test/test_utils.py
B/test/test_utils.py
we **have** to clean sys.modules to make sure the correct test_utils
module is ran in B
"""
for modname, mod in list(sys.modules.items()):
if mod is None:
continue
if not hasattr(mod, '__file__'):
# this is the case of some built-in modules like sys, imp, marshal
continue
modfile = mod.__file__
# if modfile is not an asbolute path, it was probably loaded locally
# during the tests
if not osp.isabs(modfile) or modfile.startswith(testdir):
del sys.modules[modname]
示例5: __init__
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import isabs [as 別名]
def __init__(self, root):
"""
Initializes the sandbox.
:param root: Root path of the sandbox.
The sandbox makes sure that the folder paths it exposes as properties are created.
"""
if not isabs(root):
raise ValueError("Only an absolute path is allowed for 'root")
self._root = root
safe_mkdir(self.bin)
safe_mkdir(self.lib)
safe_mkdir(self.var)
safe_mkdir(self.mysql_var)
safe_mkdir(self.mysql_data_dir)
safe_mkdir(self.mysql_tmp_dir)
safe_mkdir(self.mysql_log_dir)
示例6: __sanitize
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import isabs [as 別名]
def __sanitize(self, pathname):
"""
Makes sure the given pathname lies within the plugin folder.
Also makes it an absolute pathname.
.. warning: Internally used by GoLismero, do not call!
"""
# Absolute pathnames are not allowed.
if path.isabs(pathname):
msg = "Absolute pathnames are not allowed: %r"
raise ValueError(msg % pathname)
# Turn the pathname into a local pathname within the plugin folder.
pathname = path.join(self.plugin_path, pathname)
pathname = path.abspath(pathname)
if not pathname.startswith(self.plugin_path):
msg = "Pathname may not be outside the plugin folder: %r"
raise ValueError(msg % self.plugin_path)
# Return the sanitized pathname.
return pathname
#--------------------------------------------------------------------------
示例7: _get_credentials_path
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import isabs [as 別名]
def _get_credentials_path(self):
recommended_path = path.expanduser('~') + '/.aws/credentials'
creds_path = ""
if not self.non_interactive:
while not path.isabs(creds_path):
creds_path = Prompt(
message="Enter absolute path to AWS credentials file [" + Color.green(recommended_path) + "]: ",
default=recommended_path).run()
else:
if self.creds_path:
if path.isabs(self.creds_path):
creds_path = self.creds_path
else:
creds_path = recommended_path
make_dirs(path.dirname(creds_path))
return creds_path
示例8: canonical_path
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import isabs [as 別名]
def canonical_path(input_path, folder=''):
"""Return a canonical path of the file.
Args:
input_path (str): path to convert.
folder (str, optional): parent folder.
Returns:
str: canonical path
"""
if not input_path:
return None
input_path = path.expanduser(input_path)
if not path.isabs(input_path):
input_path = path.join(folder, input_path)
normpath = path.normpath(input_path)
if path.exists(normpath):
return path.realpath(normpath)
return normpath
示例9: __get_cmake_deps
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import isabs [as 別名]
def __get_cmake_deps(deps_file):
"""Parse dependencies from Makefile.cmake.
Args:
deps_file (str): Full path to Makefile.cmake file.
Returns:
str[]: List of full paths to dependency files.
"""
folder = path.dirname(path.dirname(deps_file))
deps = []
with open(deps_file, 'r') as f:
content = f.read()
found = CMakeFile._DEP_REGEX.findall(content)
for dep in found:
if not path.isabs(dep):
dep = path.join(folder, dep)
deps.append(dep)
return deps
示例10: load_catalog
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import isabs [as 別名]
def load_catalog(self, catalog_path, ignore_missing=True):
catalog = path.abspath(catalog_path)
catalog_dir = path.dirname(catalog)
with open(catalog, 'r') as catalog_file:
catalog_entries = json.load(catalog_file)
for entry in AlignmentStatistics.progress(catalog_entries, desc='Reading catalog'):
aligned_path = entry['aligned']
if not path.isabs(aligned_path):
aligned_path = path.join(catalog_dir, aligned_path)
if path.isfile(aligned_path):
self.load_aligned(aligned_path)
else:
if ignore_missing:
continue
else:
fail('Problem loading catalog "{}": Missing referenced alignment file "{}"'
.format(catalog_path, aligned_path))
示例11: test
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import isabs [as 別名]
def test():
filename = p.relpath(
p.join(TEST_PROJECT, "another_library", "foo.vhd"),
str(it.project.root_dir),
)
it.assertFalse(p.isabs(filename))
diagnostics = it.project.getMessagesByPath(Path(filename))
it.assertIn(
ObjectIsNeverUsed(
filename=Path(p.join(TEST_PROJECT, "another_library", "foo.vhd")),
line_number=28,
column_number=11,
object_type="signal",
object_name="neat_signal",
),
diagnostics,
)
示例12: timid_relpath
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import isabs [as 別名]
def timid_relpath(arg):
"""convert an argument to a relative path, carefully"""
# TODO-TEST: unit tests
from os.path import isabs, relpath, sep
if isabs(arg):
result = relpath(arg)
if result.count(sep) + 1 < arg.count(sep):
return result
return arg
示例13: __init__
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import isabs [as 別名]
def __init__(self, app):
self._app = app
self._root_dir = config.get("root_dir")
if not self._root_dir:
log.error("FileClient init: root_dir config not set")
raise HTTPInternalServerError()
if not pp.isdir(self._root_dir):
log.error("FileClient init: root folder does not exist")
raise HTTPInternalServerError()
if not pp.isabs(self._root_dir):
log.error("FileClient init: root dir most have absolute path")
raise HTTPInternalServerError()
示例14: _validateBucket
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import isabs [as 別名]
def _validateBucket(self, bucket):
if not bucket or pp.isabs(bucket) or pp.dirname(bucket):
msg = "invalid bucket name"
log.warn(msg)
raise HTTPBadRequest(reason=msg)
示例15: _validateKey
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import isabs [as 別名]
def _validateKey(self, key):
if not key or pp.isabs(key):
msg = "invalid key name"
log.warn(msg)
raise HTTPBadRequest(reason=msg)