本文整理汇总了Python中os.path.realpath方法的典型用法代码示例。如果您正苦于以下问题:Python path.realpath方法的具体用法?Python path.realpath怎么用?Python path.realpath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os.path
的用法示例。
在下文中一共展示了path.realpath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_rp_stripper
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import realpath [as 别名]
def get_rp_stripper(strip_path):
""" Return function to strip ``realpath`` of `strip_path` from string
Parameters
----------
strip_path : str
path to strip from beginning of strings. Processed to ``strip_prefix``
by ``realpath(strip_path) + os.path.sep``.
Returns
-------
stripper : func
function such that ``stripper(a_string)`` will strip ``strip_prefix``
from ``a_string`` if present, otherwise pass ``a_string`` unmodified
"""
return get_prefix_stripper(realpath(strip_path) + os.path.sep)
示例2: realpath
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import realpath [as 别名]
def realpath(self, spec, key):
"""
Resolve and update the path key in the spec with its realpath,
based on the working directory.
"""
if key not in spec:
# do nothing for now
return
if not spec[key]:
logger.warning(
"cannot resolve realpath of '%s' as it is not defined", key)
return
check = realpath(join(spec.get(WORKING_DIR, ''), spec[key]))
if check != spec[key]:
spec[key] = check
logger.warning(
"realpath of '%s' resolved to '%s', spec is updated",
key, check
)
return check
# Setup related methods
示例3: test_toolchain_standard_not_implemented
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import realpath [as 别名]
def test_toolchain_standard_not_implemented(self):
spec = Spec()
with self.assertRaises(NotImplementedError):
self.toolchain(spec)
with self.assertRaises(NotImplementedError):
self.toolchain.assemble(spec)
with self.assertRaises(NotImplementedError):
self.toolchain.link(spec)
# Check that the build_dir is set on the spec based on tempfile
self.assertTrue(spec['build_dir'].startswith(
realpath(tempfile.gettempdir())))
# Also that it got deleted properly.
self.assertFalse(exists(spec['build_dir']))
示例4: find_system_jdks
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import realpath [as 别名]
def find_system_jdks():
"""
Returns a set of valid JDK directories by searching standard locations.
"""
bases = [
'/Library/Java/JavaVirtualMachines',
'/usr/lib/jvm',
'/usr/java',
'/usr/jdk/instances',
r'C:\Program Files\Java'
]
jdks = set()
for base in bases:
if isdir(base):
for n in os.listdir(base):
jdk = join(base, n)
mac_jdk = join(jdk, 'Contents', 'Home')
if isdir(mac_jdk):
jdk = mac_jdk
if is_valid_jdk(jdk):
jdks.add(realpath(jdk))
return jdks
示例5: _expand_dirs_to_files
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import realpath [as 别名]
def _expand_dirs_to_files(files_or_dirs, recursive=False):
files = []
files_or_dirs = _ensure_list(files_or_dirs)
for file_or_dir in files_or_dirs:
file_or_dir = op.realpath(file_or_dir)
if op.isdir(file_or_dir):
# Skip dirnames starting with '.'
if _to_skip(file_or_dir):
continue
# Recursively visit the directories and add the files.
if recursive:
files.extend(_expand_dirs_to_files([op.join(file_or_dir, file)
for file in os.listdir(file_or_dir)],
recursive=recursive))
else:
files.extend([op.join(file_or_dir, file)
for file in os.listdir(file_or_dir)])
elif '*' in file_or_dir:
files.extend(glob.glob(file_or_dir))
else:
files.append(file_or_dir)
return files
示例6: getSubdirs
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import realpath [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
示例7: getParameters
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import realpath [as 别名]
def getParameters(self):
"""Provides a dictionary with the search parameters"""
parameters = {'term': self.findCombo.currentText(),
'case': self.caseCheckBox.isChecked(),
'whole': self.wordCheckBox.isChecked(),
'regexp': self.regexpCheckBox.isChecked()}
if self.projectRButton.isChecked():
parameters['in-project'] = True
parameters['in-opened'] = False
parameters['in-dir'] = ''
elif self.openFilesRButton.isChecked():
parameters['in-project'] = False
parameters['in-opened'] = True
parameters['in-dir'] = ''
else:
parameters['in-project'] = False
parameters['in-opened'] = False
parameters['in-dir'] = realpath(
self.dirEditCombo.currentText().strip())
parameters['file-filter'] = self.filterCombo.currentText().strip()
return parameters
示例8: get_dataset
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import realpath [as 别名]
def get_dataset(num_points):
name = 'ModelNet10'
path = osp.join(osp.dirname(osp.realpath(__file__)), '..', 'data', name)
pre_transform = T.NormalizeScale()
transform = T.SamplePoints(num_points)
train_dataset = ModelNet(
path,
name='10',
train=True,
transform=transform,
pre_transform=pre_transform)
test_dataset = ModelNet(
path,
name='10',
train=False,
transform=transform,
pre_transform=pre_transform)
return train_dataset, test_dataset
示例9: _check_if_pyc
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import realpath [as 别名]
def _check_if_pyc(fname):
"""Return True if the extension is .pyc, False if .py
and None if otherwise"""
from imp import find_module
from os.path import realpath, dirname, basename, splitext
# Normalize the file-path for the find_module()
filepath = realpath(fname)
dirpath = dirname(filepath)
module_name = splitext(basename(filepath))[0]
# Validate and fetch
try:
fileobj, fullpath, (_, _, pytype) = find_module(module_name, [dirpath])
except ImportError:
raise IOError("Cannot find config file. "
"Path maybe incorrect! : {0}".format(filepath))
return pytype, fileobj, fullpath
示例10: bro_server
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import realpath [as 别名]
def bro_server(bro_file, interface="eth0", bro_path="/usr/local/bro/bin/bro"):
u""" 跑bro服务进程 """
# 获取绝对路径
bro_file = path.realpath(bro_file)
http_file = "/usr/local/bro/share/bro/base/protocols/http/main.bro"
bro_scripts = ' '.join([bro_file, http_file])
cmd = "sudo {bro_path} -C -b -i {interface} {bro_scripts}"
cmd = cmd.format(bro_path=bro_path,
interface=interface,
bro_scripts=bro_scripts)
msg = "the cmd is: %s" % cmd
logging.info(msg)
# change pwd to /tmp
tmp_dir = path.join(path.dirname(path.realpath(__file__)), '../../tmp/')
chdir(tmp_dir)
result = run(cmd)
logging.info(result.__dict__)
示例11: _setup_logger
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import realpath [as 别名]
def _setup_logger(cls, log_file=None):
formatter = logging.Formatter(
fmt="%(asctime)s %(levelname)-8s %(message)s", datefmt="%Y-%m-%d %H:%M:%S"
)
screen_handler = logging.StreamHandler(stream=sys.stdout)
screen_handler.setFormatter(formatter)
logger = logging.getLogger(cls.__name__)
logger.setLevel(logging.DEBUG)
logger.addHandler(screen_handler)
if log_file:
file_handler = logging.FileHandler(realpath(log_file), mode="w")
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
return logger
示例12: _get_settings_helper
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import realpath [as 别名]
def _get_settings_helper(self):
main_dir = path.dirname(path.realpath(__file__))
main_dir = path.realpath(path.join(main_dir, '..', '..'))
default_filepath = path.join(main_dir, 'default_settings.yml')
user_filepath = path.join(main_dir, 'settings.yml')
args = self._get_args()
if args.settings_path:
user_filepath = args.settings_path
# open the default file and get version information
with open(default_filepath) as default_filestream:
default_filesettings = yaml.load(default_filestream)
# FIXME: not used
current_version = default_filesettings['version'].split('.') # flake8: noqa
if path.exists(user_filepath):
filepath = user_filepath
else:
filepath = default_filepath
with open(filepath) as setting_file:
self.settings = yaml.load(setting_file, _OrderedLoader)
return SpecialDict(**self.settings)
示例13: ProcessFlags
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import realpath [as 别名]
def ProcessFlags(env, flags):
for f in flags:
if f:
env.MergeFlags(str(f))
# fix relative CPPPATH
for i, p in enumerate(env.get("CPPPATH", [])):
if isdir(p):
env['CPPPATH'][i] = realpath(p)
# Cancel any previous definition of name, either built in or
# provided with a -D option // Issue #191
undefines = [u for u in env.get("CCFLAGS", []) if u.startswith("-U")]
if undefines:
for undef in undefines:
env['CCFLAGS'].remove(undef)
env.Append(_CPPDEFFLAGS=" %s" % " ".join(undefines))
示例14: resolve_rpath
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import realpath [as 别名]
def resolve_rpath(lib_path, rpaths):
""" Return `lib_path` with its `@rpath` resolved
If the `lib_path` doesn't have `@rpath` then it's returned as is.
If `lib_path` has `@rpath` then returns the first `rpaths`/`lib_path`
combination found. If the library can't be found in `rpaths` then a
detailed warning is printed and `lib_path` is returned as is.
Parameters
----------
lib_path : str
The path to a library file, which may or may not start with `@rpath`.
rpaths : sequence of str
A sequence of search paths, usually gotten from a call to `get_rpaths`.
Returns
-------
lib_path : str
A str with the resolved libraries realpath.
"""
if not lib_path.startswith('@rpath/'):
return lib_path
lib_rpath = lib_path.split('/', 1)[1]
for rpath in rpaths:
rpath_lib = realpath(pjoin(rpath, lib_rpath))
if os.path.exists(rpath_lib):
return rpath_lib
warnings.warn(
"Couldn't find {0} on paths:\n\t{1}".format(
lib_path,
'\n\t'.join(realpath(path) for path in rpaths),
)
)
return lib_path
示例15: wheel_libs
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import realpath [as 别名]
def wheel_libs(wheel_fname, filt_func=None):
""" Return analysis of library dependencies with a Python wheel
Use this routine for a dump of the dependency tree.
Parameters
----------
wheel_fname : str
Filename of wheel
filt_func : None or callable, optional
If None, inspect all files for library dependencies. If callable,
accepts filename as argument, returns True if we should inspect the
file, False otherwise.
Returns
-------
lib_dict : dict
dictionary with (key, value) pairs of (``libpath``,
``dependings_dict``). ``libpath`` is library being depended on,
relative to wheel root path if within wheel tree. ``dependings_dict``
is (key, value) of (``depending_lib_path``, ``install_name``). Again,
``depending_lib_path`` is library relative to wheel root path, if
within wheel tree.
"""
with TemporaryDirectory() as tmpdir:
zip2dir(wheel_fname, tmpdir)
lib_dict = tree_libs(tmpdir, filt_func)
return stripped_lib_dict(lib_dict, realpath(tmpdir) + os.path.sep)