Python os 模块,O_DIRECTORY 实例源码

我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用os.O_DIRECTORY

项目:transfert    作者:rbernand    | 项目源码 | 文件源码
def mkdir(self, name=None):
        if name is None:
            os.makedirs(self.url.path, exist_ok=True)
            return self
        else:
            fd = os.open(self.url.path, os.O_DIRECTORY)
            os.mkdir(name, dir_fd=fd)
            os.close(fd)
            return self.join(name)
项目:deb-python-kafka    作者:openstack    | 项目源码 | 文件源码
def render_template(cls, source_file, target_file, binding):
        log.info('Rendering %s from template %s', target_file, source_file)
        with open(source_file, "r") as handle:
            template = handle.read()
            assert len(template) > 0, 'Empty template %s' % source_file
        with open(target_file, "w") as handle:
            handle.write(template.format(**binding))
            handle.flush()
            os.fsync(handle)

        # fsync directory for durability
        # https://blog.gocept.com/2013/07/15/reliable-file-updates-with-python/
        dirfd = os.open(os.path.dirname(target_file), os.O_DIRECTORY)
        os.fsync(dirfd)
        os.close(dirfd)