當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。