Ensure that this path exists as a directory.

        This function calls :meth:`mkdir` on this path, but does not raise an
        exception if it already exists. It does raise an exception if this
        path exists but is not a directory. If the directory is created,
        *mode* is used to set the permissions of the resulting directory, with
        the important caveat that the current :func:`os.umask` is applied.

        It returns a boolean indicating if the directory was actually created.

        If *parents* is true, parent directories will be created in the same
        manner.

def ensure_dir (self, mode=0o777, parents=False):
        """Ensure that this path exists as a directory.

        This function calls :meth:`mkdir` on this path, but does not raise an
        exception if it already exists. It does raise an exception if this
        path exists but is not a directory. If the directory is created,
        *mode* is used to set the permissions of the resulting directory, with
        the important caveat that the current :func:`os.umask` is applied.

        It returns a boolean indicating if the directory was actually created.

        If *parents* is true, parent directories will be created in the same
        manner.

        """
        if parents:
            p = self.parent
            if p == self:
                return False # can never create root; avoids loop when parents=True
            p.ensure_dir (mode, True)

        made_it = False

        try:
            self.mkdir (mode)
            made_it = True
        except OSError as e:
            if e.errno == 17: # EEXIST?
                return False # that's fine
            raise # other exceptions are not fine

        if not self.is_dir ():
            import errno
            raise OSError (errno.ENOTDIR, 'Not a directory', str(self))

        return made_it