<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def SetPermissions(path, mode=None, uid=None, gid=None, mkdir=False):
 """Set the permissions and ownership of a path. Args: path: string, the path for which owner ID and group ID needs to be setup. mode: octal string, the permissions to set on the path. uid: int, the owner ID to be set for the path. gid: int, the group ID to be set for the path. mkdir: bool, True if the directory needs to be created. """

  if mkdir and not os.path.exists(path):
    os.mkdir(path, mode or 0o777)
  elif mode:
    os.chmod(path, mode)
  if uid and gid:
    os.chown(path, uid, gid)
  _SetSELinuxContext(path)