def publish_portal(portaladdress,contentpath,adminuser,adminpassword, users, hostname_map, specified_groups, id_mapping_file):
    os.chdir(contentpath)
    
    portal_properties = json.load(open("portal_properties.json"))
    portaladmin = Portal(portaladdress, adminuser, adminpassword)
    
    print_script_header(portaladmin, portal_processing, users, specified_groups)

    # Create Portal log folder for this portal
    portalLogPath = os.path.join(contentpath, portalLogFolder, get_servername_from_url(portaladmin.url))
    makeFolder(portalLogPath)
    
    # ------------------------------------------------------------------------
    # Get info about the groups on disk to filter items based on group membership
    # ------------------------------------------------------------------------
    # Get the groups on disk
    grps_on_disk = get_groups_on_disk(contentpath)
    
    # Validate that each specified group is valid
    if specified_groups:
        invalid_specified_groups = []
        for specified_group in specified_groups:
            found = False
            for grp in grps_on_disk.itervalues():
                if specified_group == grp:
                    found = True
            if not found:
               invalid_specified_groups.append(specified_group)
               
        if len(invalid_specified_groups) > 0:
            print '\n***ERROR: the following specified groups do not exist; NOTE: group owner and group title must match exactly including case:\n'
            print invalid_specified_groups
            return
    
    # ------------------------------------------------------------------------
    # Create users
    # ------------------------------------------------------------------------
    print titleBreak
    print 'Create users...\n'
   
    # Only create users if this is not an online organization
    if portaladmin.properties()['id'] == '0123456789ABCDEF': # All portals have this id.
        for username, userinfo in users.iteritems():
           create_user(portaladmin, contentpath, userinfo)
    else:
        print '\tThis is an online organization. Users must already have been created.'

    # ------------------------------------------------------------------------
    # Create user folders
    # ------------------------------------------------------------------------
    print '\n'+ titleBreak
    print 'Create user folders...\n'
    
    for username, userinfo in users.iteritems():
       print '\nUser: ' + userinfo['target_username']
       create_user_folders(portaladmin, contentpath, userinfo)

    # ------------------------------------------------------------------------
    # Create groups and add users to groups
    # ------------------------------------------------------------------------
    print "\n" + titleBreak
    print "Creating groups ...\n"
    
    oldGrpID_newGrpID = {}
    for username, userinfo in users.iteritems():
        newGroups = publish_user_groups(portaladmin, contentpath, userinfo, users)
        
        for key,val in newGroups.iteritems():
            oldGrpID_newGrpID[key] = {'id': val}
    
    # ------------------------------------------------------------------------
    # Publish Items and Update their sharing info
    # ------------------------------------------------------------------------
    print "\n" + titleBreak
    print "Publishing items and setting sharing ..."
    print titleBreak
    
    for username, userinfo in users.iteritems():
        
        username = userinfo['target_username']
        password = userinfo['target_password']
        userfoldername = userinfo['username']
        
        # ---------------------------------------
        # Publish all the users' items
        # ---------------------------------------
        usercontentpath = os.path.join(contentpath, userfoldername)
        
        newItems, origItemSourceIDs = publish_user_items(portaladmin, username, usercontentpath, source_hostname,
                                new_hostname, new_port, specified_groups, id_mapping_file, grps_on_disk)
        
        # Dump info about new items to JSON to use for resetting IDs of related items
        dump_newItem_info(newItems, origItemSourceIDs, os.path.join(portalLogPath, username))
        
        # ---------------------------------------
        # Share the users' items with the
        # appropriate groups
        # ---------------------------------------
        userItemsPath = os.path.join(contentpath, userfoldername, "items")
        share_items(portaladmin, userItemsPath, newItems, origItemSourceIDs, originGroupToDestGroups)
    
    
    # Dump info about all items (old, new ids) into json
    os.chdir(portalLogPath)
    json.dump(origIDToNewID, open('oldID_newID.json','w'))
    json.dump(oldGrpID_newGrpID, open('oldGrpID_newGrpID.json', 'w'))

    # ------------------------------------------------------------------------
    # Post publishing processing: Update URLs and item ids
    # ------------------------------------------------------------------------
    print "\n" + titleBreak
    print "Update URLs and Item IDs..."
    print titleBreak + "\n"
    
    # Add the group ids to the dictionary of old/new ids
    origIDToNewID.update(oldGrpID_newGrpID)
    
    update_post_publish(portaladmin, hostname_map, origIDToNewID)

    # Comment out: this functionality is now available out of the box
    # # ------------------------------------------------------------------------
    # # Share items in default web apps template and default gallery
    # # ------------------------------------------------------------------------    
    # # Share the items in the default web apps template and
    # # default gallery template built-in group with the
    # # 'OpsServer' user 'AFMI Web Application Templates' and
    # # 'AFMI Gallery Templates'
    # print "\n" + sectionBreak
    # print "Share the items in the default web apps and gallery template groups..."
    # group_owner = 'OpsServer'
    # if users.get(group_owner):
    #     share_templates(portaladdress, users[group_owner]['target_username'], users[group_owner]['target_password'])
    # else:
    #     print "-Skipping...user {} was not created. Can perform same operation through portal 'Edit Settings'.".format(group_owner)

    print "\nDONE: Finished posting content to portal."
dataset/ETHPy150Open Esri/ops-server-config/Publish/Portal/PortalContentPost.py/publish_portal/original