本文整理汇总了Python中os.pardir方法的典型用法代码示例。如果您正苦于以下问题:Python os.pardir方法的具体用法?Python os.pardir怎么用?Python os.pardir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os
的用法示例。
在下文中一共展示了os.pardir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_mxnet_root
# 需要导入模块: import os [as 别名]
# 或者: from os import pardir [as 别名]
def get_mxnet_root() -> str:
curpath = os.path.abspath(os.path.dirname(__file__))
def is_mxnet_root(path: str) -> bool:
return os.path.exists(os.path.join(path, ".mxnet_root"))
while not is_mxnet_root(curpath):
parent = os.path.abspath(os.path.join(curpath, os.pardir))
if parent == curpath:
raise RuntimeError("Got to the root and couldn't find a parent folder with .mxnet_root")
curpath = parent
return curpath
示例2: get_reporting_config_vars
# 需要导入模块: import os [as 别名]
# 或者: from os import pardir [as 别名]
def get_reporting_config_vars():
reporting_config = {}
with open(os.path.abspath(os.path.join(__file__, os.pardir, os.pardir, "reporting_config.json")), 'r') as f:
config = json.load(f)
reporting_interval_string = config['reporting_interval']
if reporting_interval_string[-1:] == 's':
reporting_interval = float(config['reporting_interval'][:-1])
reporting_config['reporting_interval'] = float(reporting_interval / 60.0)
else:
reporting_config['reporting_interval'] = int(config['reporting_interval'])
reporting_config['keep_file_days'] = int(config['keep_file_days'])
reporting_config['prev_endtime'] = config['prev_endtime']
reporting_config['deltaFields'] = config['delta_fields']
reporting_config['keep_file_days'] = int(config['keep_file_days'])
reporting_config['prev_endtime'] = config['prev_endtime']
reporting_config['deltaFields'] = config['delta_fields']
return reporting_config
示例3: run_postdecode_hooks
# 需要导入模块: import os [as 别名]
# 或者: from os import pardir [as 别名]
def run_postdecode_hooks(decode_hook_args):
"""Run hooks after decodes have run."""
hooks = decode_hook_args.problem.decode_hooks
if not hooks:
return
global_step = latest_checkpoint_step(decode_hook_args.estimator.model_dir)
if global_step is None:
tf.logging.info(
"Skipping decode hooks because no checkpoint yet available.")
return
tf.logging.info("Running decode hooks.")
parent_dir = os.path.join(decode_hook_args.output_dirs[0], os.pardir)
final_dir = os.path.join(parent_dir, "decode")
summary_writer = tf.summary.FileWriter(final_dir)
for hook in hooks:
# Isolate each hook in case it creates TF ops
with tf.Graph().as_default():
summaries = hook(decode_hook_args)
if summaries:
summary = tf.Summary(value=list(summaries))
summary_writer.add_summary(summary, global_step)
summary_writer.close()
tf.logging.info("Decode hooks done.")
示例4: __init__
# 需要导入模块: import os [as 别名]
# 或者: from os import pardir [as 别名]
def __init__(self):
self._SAMPLE_ROOT = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
os.pardir
)
self._FLATTEN_CONCAT_PLUGIN_PATH = os.path.join(
self._SAMPLE_ROOT,
'build',
'libflattenconcat.so'
)
self._WORKSPACE_DIR_PATH = os.path.join(
self._SAMPLE_ROOT,
'workspace'
)
self._VOC_DIR_PATH = \
os.path.join(self._SAMPLE_ROOT, 'VOCdevkit', 'VOC2007')
# User configurable paths
示例5: translate_path
# 需要导入模块: import os [as 别名]
# 或者: from os import pardir [as 别名]
def translate_path(self, path):
"""Translate a /-separated PATH to the local filename syntax.
Components that mean special things to the local file system
(e.g. drive or directory names) are ignored. (XXX They should
probably be diagnosed.)
"""
# abandon query parameters
path = path.split('?',1)[0]
path = path.split('#',1)[0]
path = posixpath.normpath(urllib_parse.unquote(path))
words = path.split('/')
words = filter(None, words)
path = os.getcwd()
for word in words:
drive, word = os.path.splitdrive(word)
head, word = os.path.split(word)
if word in (os.curdir, os.pardir): continue
path = os.path.join(path, word)
return path
示例6: ZipDir
# 需要导入模块: import os [as 别名]
# 或者: from os import pardir [as 别名]
def ZipDir(sourceDirectory, outputFilePath, outputHandler):
currentDir = os.getcwd()
try:
os.chdir(sourceDirectory)
#relroot = os.path.abspath(os.path.join(sourceDirectory, os.pardir))
relroot = os.path.abspath(os.path.join(sourceDirectory))
#with zipfile.ZipFile(outputFilePath, "w", zipfile.ZIP_DEFLATED) as zip:
with zipfile.ZipFile(outputFilePath, "w") as zip:
for root, dirs, files in os.walk(sourceDirectory):
# add directory (needed for empty dirs)
# this is commented out because Tomcat 8 will reject WAR files with "./" in them.
#zip.write(root, os.path.relpath(root, relroot))
for file in files:
filename = os.path.join(root, file)
if os.path.isfile(filename): # regular files only
arcname = os.path.join(os.path.relpath(root, relroot), file)
zip.write(filename, arcname)
return True
except Exception as e:
outputHandler.outputMessage('Error creating zip file "%s" from directory "%s" - %s' % (outputFilePath, sourceDirectory, e))
return False
os.chdir(currentDir)
示例7: bestrelpath
# 需要导入模块: import os [as 别名]
# 或者: from os import pardir [as 别名]
def bestrelpath(self, dest):
""" return a string which is a relative path from self
(assumed to be a directory) to dest such that
self.join(bestrelpath) == dest and if not such
path can be determined return dest.
"""
try:
if self == dest:
return os.curdir
base = self.common(dest)
if not base: # can be the case on windows
return str(dest)
self2base = self.relto(base)
reldest = dest.relto(base)
if self2base:
n = self2base.count(self.sep) + 1
else:
n = 0
l = [os.pardir] * n
if reldest:
l.append(reldest)
target = dest.sep.join(l)
return target
except AttributeError:
return str(dest)
示例8: copy_resources
# 需要导入模块: import os [as 别名]
# 或者: from os import pardir [as 别名]
def copy_resources(self):
"""Copies the relevant resources to a resources subdirectory"""
if not os.path.isdir('resources'):
os.mkdir('resources')
resource_dir = os.path.join(os.getcwd(), 'resources', '')
copied_resources = []
for resource in self.resources:
src = os.path.join(EULER_DATA, 'resources', resource)
if os.path.isfile(src):
shutil.copy(src, resource_dir)
copied_resources.append(resource)
if copied_resources:
copied = ', '.join(copied_resources)
path = os.path.relpath(resource_dir, os.pardir)
msg = "Copied {} to {}.".format(copied, path)
click.secho(msg, fg='green')
示例9: test_can_clone_device
# 需要导入模块: import os [as 别名]
# 或者: from os import pardir [as 别名]
def test_can_clone_device(moler_config, device_factory):
conn_config = os.path.join(os.path.dirname(__file__), os.pardir, "resources", "device_config.yml")
moler_config.load_config(config=conn_config, config_type='yaml')
device_org_name = 'UNIX_LOCAL'
device_cloned_name = 'CLONED_UNIX_LOCAL1'
device_org = device_factory.get_device(name=device_org_name)
assert device_org is not None
device_cloned = device_factory.get_cloned_device(source_device=device_org, new_name=device_cloned_name)
assert device_cloned is not None
assert device_org != device_cloned
assert device_org.io_connection != device_cloned.io_connection
assert device_org.io_connection.moler_connection != device_cloned.io_connection.moler_connection
assert device_org.io_connection.name != device_cloned.io_connection.name
device_cached_cloned = device_factory.get_cloned_device(source_device=device_org, new_name=device_cloned_name)
assert device_cloned == device_cached_cloned
device_cached_cloned.goto_state('UNIX_LOCAL')
示例10: test_clone_device_from_cloned_device
# 需要导入模块: import os [as 别名]
# 或者: from os import pardir [as 别名]
def test_clone_device_from_cloned_device(moler_config, device_factory):
conn_config = os.path.join(os.path.dirname(__file__), os.pardir, "resources", "device_config.yml")
moler_config.load_config(config=conn_config, config_type='yaml')
device_org_name = 'UNIX_LOCAL'
device_cloned_name = 'UNIX_LOCAL_CLONED'
device_recloned_name = 'UNIX_LOCAL_RECLONED'
device_org = device_factory.get_device(name=device_org_name)
assert device_org is not None
device_cloned = device_factory.get_cloned_device(source_device=device_org, new_name=device_cloned_name)
device_recloned = device_factory.get_cloned_device(source_device=device_cloned, new_name=device_recloned_name)
assert device_cloned != device_recloned
assert device_cloned != device_org
assert device_recloned != device_org
device_cloned.remove()
device_recloned.remove()
with pytest.raises(KeyError):
device_factory.get_device(name=device_cloned_name)
with pytest.raises(KeyError):
device_factory.get_device(name=device_recloned_name)
with pytest.raises(KeyError): # Cannot clone forgotten device.
device_factory.get_cloned_device(source_device=device_cloned_name, new_name=device_recloned_name)
with pytest.raises(KeyError): # Cannot clone even passed reference to forgotten device.
device_factory.get_cloned_device(source_device=device_cloned, new_name=device_recloned_name)
示例11: test_can_clone_device_via_name
# 需要导入模块: import os [as 别名]
# 或者: from os import pardir [as 别名]
def test_can_clone_device_via_name(moler_config, device_factory):
conn_config = os.path.join(os.path.dirname(__file__), os.pardir, "resources", "device_config.yml")
moler_config.load_config(config=conn_config, config_type='yaml')
device_org_name = 'UNIX_LOCAL'
device_cloned_name = 'CLONED_UNIX_LOCAL2'
device_org = device_factory.get_device(name=device_org_name)
assert device_org is not None
device_cloned = device_factory.get_cloned_device(source_device=device_org_name, new_name=device_cloned_name)
assert device_cloned is not None
assert device_org != device_cloned
assert device_org.io_connection != device_cloned.io_connection
assert device_org.io_connection.moler_connection != device_cloned.io_connection.moler_connection
assert device_org.io_connection.name != device_cloned.io_connection.name
device_cached_cloned = device_factory.get_cloned_device(source_device=device_org, new_name=device_cloned_name)
assert device_cloned == device_cached_cloned
device_cached_cloned.goto_state('UNIX_LOCAL')
示例12: test_can_clone_device_via_yaml
# 需要导入模块: import os [as 别名]
# 或者: from os import pardir [as 别名]
def test_can_clone_device_via_yaml(moler_config, device_factory):
conn_config = os.path.join(os.path.dirname(__file__), os.pardir, "resources", "device_config.yml")
moler_config.load_config(config=conn_config, config_type='yaml')
device_org_name = 'UNIX_LOCAL'
device_cloned_name = 'UNIX_LOCAL_CLONED_VIA_YAML'
device_org = device_factory.get_device(name=device_org_name)
assert device_org is not None
device_cloned = device_factory.get_device(name=device_cloned_name)
assert device_cloned is not None
assert type(device_org) is type(device_cloned)
assert device_org != device_cloned
assert device_org.io_connection != device_cloned.io_connection
assert device_org.io_connection.moler_connection != device_cloned.io_connection.moler_connection
assert device_org.io_connection.name != device_cloned.io_connection.name
device_cached_cloned = device_factory.get_cloned_device(source_device=device_org, new_name=device_cloned_name)
assert device_cloned == device_cached_cloned
示例13: test_can_select_neighbour_devices_loaded_from_config_file_
# 需要导入模块: import os [as 别名]
# 或者: from os import pardir [as 别名]
def test_can_select_neighbour_devices_loaded_from_config_file_(moler_config, device_factory):
conn_config = os.path.join(os.path.dirname(__file__), os.pardir, "resources", "device_config.yml")
moler_config.load_config(config=conn_config, config_type='yaml')
device_factory.create_all_devices()
unix_local = device_factory.get_device(name='UNIX_LOCAL', establish_connection=False)
import moler.device.scpi
import moler.device.unixlocal
neighbours = unix_local.get_neighbour_devices(device_type=moler.device.scpi.Scpi)
assert 1 == len(neighbours)
assert isinstance(neighbours[0], moler.device.scpi.Scpi)
assert unix_local in neighbours[0].get_neighbour_devices(device_type=None)
assert unix_local in neighbours[0].get_neighbour_devices(device_type=moler.device.unixlocal.UnixLocal)
assert unix_local in device_factory.get_devices_by_type(device_type=None)
assert unix_local in device_factory.get_devices_by_type(device_type=moler.device.unixlocal.UnixLocal)
unix_local.goto_state(state=unix_local.initial_state)
示例14: get_library_dirs
# 需要导入模块: import os [as 别名]
# 或者: from os import pardir [as 别名]
def get_library_dirs(self):
opt = []
if sys.platform[:5] != 'linux':
d = self.get_libgcc_dir()
if d:
# if windows and not cygwin, libg2c lies in a different folder
if sys.platform == 'win32' and not d.startswith('/usr/lib'):
d = os.path.normpath(d)
path = os.path.join(d, "lib%s.a" % self.g2c)
if not os.path.exists(path):
root = os.path.join(d, *((os.pardir, ) * 4))
d2 = os.path.abspath(os.path.join(root, 'lib'))
path = os.path.join(d2, "lib%s.a" % self.g2c)
if os.path.exists(path):
opt.append(d2)
opt.append(d)
# For Macports / Linux, libgfortran and libgcc are not co-located
lib_gfortran_dir = self.get_libgfortran_dir()
if lib_gfortran_dir:
opt.append(lib_gfortran_dir)
return opt
示例15: create_backup
# 需要导入模块: import os [as 别名]
# 或者: from os import pardir [as 别名]
def create_backup(self):
if self._verbose: print("Backing up current addon folder")
local = os.path.join(self._updater_path,"backup")
tempdest = os.path.join(self._addon_root,
os.pardir,
self._addon+"_updater_backup_temp")
if os.path.isdir(local) == True:
shutil.rmtree(local)
if self._verbose: print("Backup destination path: ",local)
# make the copy
if self._backup_ignore_patterns != None:
shutil.copytree(
self._addon_root,tempdest,
ignore=shutil.ignore_patterns(*self._backup_ignore_patterns))
else:
shutil.copytree(self._addon_root,tempdest)
shutil.move(tempdest,local)
# save the date for future ref
now = datetime.now()
self._json["backup_date"] = "{m}-{d}-{yr}".format(
m=now.strftime("%B"),d=now.day,yr=now.year)
self.save_updater_json()