Make sure the directory exists, create if necessary.

def ensure_dir(self, mode=0777):
        """
        Make sure the directory exists, create if necessary.
        """
        if not self.exists() or not self.isdir():
            os.makedirs(self, mode)