code: def check_dir(self, dirname):
          
          try:
              os.makedirs(dirname)
              dir_stat = os.stat(dirname)
              print("Created the directory: %s, stat: %s" % (dirname, dir_stat))
              if not dir_stat.st_uid == self.uid:
                  os.chown(dirname, self.uid, self.gid)
                  os.chmod(dirname, 0o775)
                  dir_stat = os.stat(dirname)
                  print("Changed directory ownership and permissions: %s, stat: %s"
                        % (dirname, dir_stat))
  
              self.pre_log.append(("DEBUG",
                                   "Daemon '%s' directory %s checking... "
                                   "User uid: %s, directory stat: %s."
                                   % (self.name, dirname, os.getuid(), dir_stat)))
  
              self.pre_log.append(("INFO",
                                   "Daemon '%s' directory %s did not exist, I created it. "
                                   "I set ownership for this directory to %s:%s."
                                   % (self.name, dirname, self.user, self.group)))
          except OSError as exp:
              if exp.errno == errno.EEXIST and os.path.isdir(dirname):
                  # Directory still exists...
                  pass
              else:
                  self.pre_log.append(("ERROR",
                                       "Daemon directory '%s' did not exist, "
                                       "and I could not create. Exception: %s"
                                       % (dirname, exp)))
                  self.exit_on_error("Daemon directory '%s' did not exist, "
                                     "and I could not create.'. Exception: %s"
                                     % (dirname, exp), exit_code=3)
docs: Check and create directory
  
          :param dirname: file name
          :type dirname; str
  
          :return: None