def publish_user_groups(portal,contentpath, userinfo, users):
    
    username = userinfo['target_username']
    password = userinfo['target_password']
    userfoldername = userinfo['username']
    
    groupfolder = os.path.join(contentpath, userfoldername, 'groups')
    groupfolders = os.listdir(groupfolder)
    
    numTotalGroupFolders = len(groupfolders)
    if numTotalGroupFolders == 0:
        print "\nUser '{}' does not own any groups.".format(username)
    else:
        print "\nCreating '{}' group(s) for user '{}'...".format(str(numTotalGroupFolders), username)
    
    groupcount = 0
    groupsprocessed = 0
    groupsFailed = ["None"] #TODO: later we append to this list, but why do we initialize
                            # list with one element with "None" string? Was this supposed to be
                            # groupsFailed = []
    for folder in groupfolders:
        groupcount = groupcount + 1
        oldGroupID = folder #was groupID = folder
        groupidfolder = os.path.join(groupfolder, folder)
        os.chdir(groupidfolder)
        group = json.load(open("group.json"))
        group_users = json.load(open("group_users.json"))
        
        # Check if group to add already exists
        groupId = getGroupID(portal, username, str(group['title']))
        
        # Create group if it doesn't exist
        if not groupId:
            print "... group '" + str(group['title']) + "'"
            groupId = portal.create_group(group,group['thumbfile'])
            # Reassign group
            portal.reassign_group(groupId, username)
        else:
            print "... group '" + str(group['title']) + "' already exists."
            
        destGroupID_GroupName[groupId] = str(group['title']) #Track new group id and group name for later use
        
        print "...... adding users to group"
        if groupId:
            originGroupToDestGroups[oldGroupID] = groupId
            groups = []
            groups.append(groupId)
            
            # Check if users are in the list we added to the portal
            users_to_invite = []
            portal_users = get_target_users(users)
            for u in map_group_users(group_users["users"], users):
                u = str(u) #dict keys are unicode, make them ascii
                if portal_users in u:
                    users_to_invite.append(u)
            
            if len(users_to_invite) != 0:
                print "......... adding the following users: " + str(users_to_invite)
                results = portal.add_group_users(users_to_invite, groups)
            else:
                print "......... no users to add."
            groupsprocessed = groupsprocessed + 1
        else:
            groupsFailed.append(groupID) #TODO: we append to this list, but don't use it anywhere.
    os.chdir(groupfolder)
    
    return originGroupToDestGroups
dataset/ETHPy150Open Esri/ops-server-config/Publish/Portal/PortalContentPost.py/publish_user_groups/swapped operands of `in`