Python os.O_DIRECTORY() Examples

The following are code examples for showing how to use os.O_DIRECTORY(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the ones you don't like. You can also save this page to your account.

Example 1
Project: transfert   Author: rbernand   File: file.py    (MIT License) View Source Project 5 votes vote down vote up
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) 
Example 2
Project: deb-python-kafka   Author: openstack   File: fixtures.py    (license) View Source Project 5 votes vote down vote up
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)