当前位置: 首页>>代码示例>>Python>>正文


Python os.O_DIRECTORY属性代码示例

本文整理汇总了Python中os.O_DIRECTORY属性的典型用法代码示例。如果您正苦于以下问题:Python os.O_DIRECTORY属性的具体用法?Python os.O_DIRECTORY怎么用?Python os.O_DIRECTORY使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在os的用法示例。


在下文中一共展示了os.O_DIRECTORY属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: close

# 需要导入模块: import os [as 别名]
# 或者: from os import O_DIRECTORY [as 别名]
def close(self):
        if self.state == 2:
            if dry_run:
                logger.info("dry run config transaction can be found in {}".format(self.temp_path))
            else:
                logger.info("closing config transaction")
                shutil.move(self.temp_path, self.path)
                # sync
                dirfd = os.open(self.dir, os.O_DIRECTORY)
                os.fsync(dirfd)
                os.close(dirfd)
                os.system('sync')

        else:
            logger.warn("closing config transaction with no edits")
        self.set_state_idle() 
开发者ID:KanoComputing,项目名称:kano-settings,代码行数:18,代码来源:boot_config.py

示例2: fsync_dir

# 需要导入模块: import os [as 别名]
# 或者: from os import O_DIRECTORY [as 别名]
def fsync_dir(dir_path):
    """
    Execute fsync on a directory ensuring it is synced to disk

    :param str dir_path: The directory to sync
    :raise OSError: If fail opening the directory
    """
    dir_fd = os.open(dir_path, os.O_DIRECTORY)
    try:
        os.fsync(dir_fd)
    except OSError as e:
        # On some filesystem doing a fsync on a directory
        # raises an EINVAL error. Ignoring it is usually safe.
        if e.errno != errno.EINVAL:
            raise
    finally:
        os.close(dir_fd) 
开发者ID:2ndquadrant-it,项目名称:barman,代码行数:19,代码来源:utils.py

示例3: device

# 需要导入模块: import os [as 别名]
# 或者: from os import O_DIRECTORY [as 别名]
def device(self, filename, offset=None, sizelimit=None):
        req = {}
        fds = []

        fd = os.open(filename, os.O_RDWR)
        dir_fd = os.open("/dev", os.O_DIRECTORY)

        fds.append(fd)
        req["fd"] = 0
        fds.append(dir_fd)
        req["dir_fd"] = 1

        if offset:
            req["offset"] = offset
        if sizelimit:
            req["sizelimit"] = sizelimit

        self.client.send(req, fds=fds)
        os.close(dir_fd)
        os.close(fd)

        payload, _, _ = self.client.recv()
        path = os.path.join("/dev", payload["devname"])
        try:
            yield path
        finally:
            os.unlink(path) 
开发者ID:osbuild,项目名称:osbuild,代码行数:29,代码来源:remoteloop.py

示例4: __init__

# 需要导入模块: import os [as 别名]
# 或者: from os import O_DIRECTORY [as 别名]
def __init__(self, minor, dir_fd=None):
        """
        Parameters
        ----------
        minor
            the minor number of the underlying device
        dir_fd : int, optional
            A directory file descriptor to a filesystem containing the
            underlying device node, or None to use /dev (default is None)

        Raises
        ------
        UnexpectedDevice
            If the file in the expected device node location is not the
            expected device node
        """

        self.devname = f"loop{minor}"
        self.minor = minor

        with contextlib.ExitStack() as stack:
            if not dir_fd:
                dir_fd = os.open("/dev", os.O_DIRECTORY)
                stack.callback(lambda: os.close(dir_fd))
            self.fd = os.open(self.devname, os.O_RDWR, dir_fd=dir_fd)

        info = os.stat(self.fd)
        if ((not stat.S_ISBLK(info.st_mode)) or
                (not os.major(info.st_rdev) == self.LOOP_MAJOR) or
                (not os.minor(info.st_rdev) == minor)):
            raise UnexpectedDevice(minor, info.st_rdev, info.st_mode) 
开发者ID:osbuild,项目名称:osbuild,代码行数:33,代码来源:loop.py

示例5: _open

# 需要导入模块: import os [as 别名]
# 或者: from os import O_DIRECTORY [as 别名]
def _open(self):
        """Open the directory and return the file descriptor"""
        with self.read() as path:
            fd = os.open(path, os.O_DIRECTORY)
            try:
                yield fd
            finally:
                os.close(fd) 
开发者ID:osbuild,项目名称:osbuild,代码行数:10,代码来源:objectstore.py

示例6: test_helpers_readlink_dirfd

# 需要导入模块: import os [as 别名]
# 或者: from os import O_DIRECTORY [as 别名]
def test_helpers_readlink_dirfd(tmp_path):
    origin = tmp_path / 'parent' / 'original.txt'
    origin.parent.mkdir(parents=True, exist_ok=True)
    with origin.open('w') as f:
        f.write("Original")
    slink = tmp_path / "target" / "link"
    slink.parent.mkdir(parents=True, exist_ok=True)
    target = pathlib.Path('../parent/original.txt')
    slink.symlink_to(target, False)
    dirfd = os.open(str(origin.parent), os.O_RDONLY | os.O_DIRECTORY)
    assert py7zr.helpers.readlink(slink, dir_fd=dirfd) == target
    os.close(dirfd) 
开发者ID:miurahr,项目名称:py7zr,代码行数:14,代码来源:test_unit.py

示例7: _open_directory

# 需要导入模块: import os [as 别名]
# 或者: from os import O_DIRECTORY [as 别名]
def _open_directory(self, path):
		return self.exitstack.enter_context(
			FileDescriptor(path, os.O_PATH | os.O_DIRECTORY | os.O_CLOEXEC)) 
开发者ID:davidfoerster,项目名称:aptsources-cleanup,代码行数:5,代码来源:zip.py

示例8: __init__

# 需要导入模块: import os [as 别名]
# 或者: from os import O_DIRECTORY [as 别名]
def __init__(self, mountpoint):
        self.fd = os.open(mountpoint, os.O_DIRECTORY) 
开发者ID:DataDog,项目名称:integrations-core,代码行数:4,代码来源:btrfs.py


注:本文中的os.O_DIRECTORY属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。