code: def creatauth(name, homedir):
      
  
      uid, gid = [None, None]
      # get information about user
      command = "id %s" % (name)
      data = commands.getstatusoutput(command)
  
      if data[0] > 0:
          # create new system user
          command = "useradd -g %s %s" % (sett.APACHEIIS_GROUP, name)
          #command = "useradd -g %s %s" % ("www-data",name)
          data = commands.getstatusoutput(command)
          if data[0] != 0:
              msg = "Error: Can't create user."
              sys.stderr.write(msg)
  
      # set homedir for user
      command = "usermod -d %s %s" % (homedir, name)
      data = commands.getstatusoutput(command)
  
      command = "chown %s:%s %s -R" % (name, sett.APACHEIIS_GROUP, homedir)
      data = commands.getstatusoutput(command)
  
      # get information about user
      command = "id %s" % (name)
      data = commands.getstatusoutput(command)
  
      # check new user and get uid, gid
      if data[0] > 0:
          msg = "Error: User not create."
          sys.stderr.write(msg)
      else:
          for it in data[1].split(" "):
              m = re.search('uid=([0-9]*)', it)
              try:
                  uid = m.group(1)
              except:
                  pass
  
              m = re.search('gid=([0-9]*)', it)
              try:
                  gid = m.group(1)
              except:
                  pass
  
          return {"uid": uid, "gid": gid}
      return {}
docs: Function create user in linux for group and set homedir. Function return gid and uid.