def EnsureDir(self, dir_path, uid, gid, mode):
    """Make sure the specified directory exists.

    If dir doesn't exist, create it and its ancestor directories, if necessary.

    No changes are made to the ownership or permissions of a directory which
    already exists.

    Arguments:
      dir_path: The path to the dir.
      uid: user ID of the owner.
      gid: group ID of the owner.
      mode: Permissions for the dir, as an integer (e.g. 0755).

    Returns:
      True if successful, False if not.
    """

    if self.os.path.isdir(dir_path):
      return True    # We are done

    parent_dir = self.os.path.dirname(dir_path)
    if not parent_dir == dir_path:
      if not self.EnsureDir(parent_dir, uid, gid, 0755):
        return False

    try:
      self.os.mkdir(dir_path, mode)
      self.os.chown(dir_path, uid, gid)
      self.SetSELinuxContext(dir_path)
    except __HOLE__ as e:
      if self.os.path.isdir(dir_path):
        logging.warning('Could not prepare %s: %s', dir_path, e)
        return True
      logging.error('Could not create %s: %s', dir_path, e)
      return False

    return True
dataset/ETHPy150Open GoogleCloudPlatform/compute-image-packages/google-daemon/usr/share/google/google_daemon/accounts.py/Accounts.EnsureDir