當前位置: 首頁>>代碼示例>>Python>>正文


Python os.pardir方法代碼示例

本文整理匯總了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 
開發者ID:awslabs,項目名稱:dynamic-training-with-apache-mxnet-on-aws,代碼行數:14,代碼來源:util.py

示例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 
開發者ID:insightfinder,項目名稱:InsightAgent,代碼行數:20,代碼來源:getmetrics_hadoop.py

示例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.") 
開發者ID:akzaidi,項目名稱:fine-lm,代碼行數:26,代碼來源:decoding.py

示例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 
開發者ID:aimuch,項目名稱:iAI,代碼行數:20,代碼來源:paths.py

示例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 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:23,代碼來源:server.py

示例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) 
開發者ID:nccgroup,項目名稱:ABPTTS,代碼行數:24,代碼來源:libabptts.py

示例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) 
開發者ID:pytest-dev,項目名稱:py,代碼行數:27,代碼來源:common.py

示例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') 
開發者ID:iKevinY,項目名稱:EulerPy,代碼行數:22,代碼來源:problem.py

示例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') 
開發者ID:nokia,項目名稱:moler,代碼行數:19,代碼來源:test_device_configuration.py

示例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) 
開發者ID:nokia,項目名稱:moler,代碼行數:26,代碼來源:test_device_configuration.py

示例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') 
開發者ID:nokia,項目名稱:moler,代碼行數:19,代碼來源:test_device_configuration.py

示例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 
開發者ID:nokia,項目名稱:moler,代碼行數:19,代碼來源:test_device_configuration.py

示例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) 
開發者ID:nokia,項目名稱:moler,代碼行數:18,代碼來源:test_device_configuration.py

示例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 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:23,代碼來源:gnu.py

示例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() 
開發者ID:ndee85,項目名稱:coa_tools,代碼行數:27,代碼來源:addon_updater.py


注:本文中的os.pardir方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。