def mkdir(self, path, parents=True, raise_if_exists=False): if self.exists(path): if raise_if_exists: raise FileAlreadyExists() elif not self.isdir(path): raise NotADirectory() else: return if parents: os.makedirs(path) else: if not os.path.exists(os.path.dirname(path)): raise MissingParentDirectory() os.mkdir(path)
def mkdir(self, path, parents=True, raise_if_exists=False): if self.exists(path): if raise_if_exists: raise FileAlreadyExists() elif not self.isdir(path): raise NotADirectory() else: return if parents: try: os.makedirs(path) except OSError as err: # somebody already created the path if err.errno != errno.EEXIST: raise else: if not os.path.exists(os.path.dirname(path)): raise MissingParentDirectory() os.mkdir(path)