def main():

    scriptName = sys.argv[0]

    specified_users = None
    #specified_ops_types = None
    specified_groups = None
    id_mapping_file = None
    
    # ---------------------------------------------------------------------
    # Check arguments
    # ---------------------------------------------------------------------   
    if len(sys.argv) < 5:
        print '\n' + scriptName + ' <PortalURL> <AdminUser> <AdminPassword> ' + \
                    '<ContentFolderPath> {UsersToPost} {GroupsToPost} {IdMappingFile}'
        print '\nWhere:'
        print '\n\t<PortalURL> (required): URL of Portal to post content (i.e. https://fully_qualified_domain_name/arcgis)'
        
        print '\n\t<AdminUser> (required): Portal user that has administrator role.'
        
        print '\n\t<AdminPassword> (required): Password for AdminUser.'
        
        print '\n\t<ContentFolderPath> (required): Folder path containing portal content to post.'
        
        print '\n\t{UsersToPost} (optional):'
        print '\t\t-By default, content for all users is posted'
        print '\t\t-Specify # placeholder character if you want to post content for all users and you are'
        print '\t\t   specifying {GroupsToPost} values'
        print '\t\t-To post content for only specific users specify comma delimited list of users, i.e. user1,user2,...'
        print '\t\t-To post content for ALL users except specific users, specify comma delimited '
        print '\t\t   list of users to exclude with "-" prefix, i.e. -user1,user2,...'
        print '\t\t-NOTE: Users names must match the "SourceUserName" values in the <ContentFolderPath>\userfile.txt file.'
 
        print '\n\t{GroupsToPost} (optional):'
        print '\t\t-To post content shared with specific portal groups specify a pipe "|" delimited list of groups using the syntax "GroupOwner:GroupTitle|GroupOwner:GroupTitle|...".'
        print '\t\t-Specify # placeholder character if you do not want to use this parameter and need to specify the {IdMappingFile} parameter value.'
        print '\t\t-NOTE: GroupOwner and GroupTitle values are case sensitive.'
        print '\t\t-NOTE: Parameter value MUST be surrounded by double-quotes.'
        
        print '\n\t{IdMappingFile} (optional): JSON file containing mapping between source and target portal item ids.'
        print '\t\t-Provides "overwrite" capability. If IdMappingFile is specified, the script will'
        print '\t\t   update any item that already exists; items that do not exist will be added.'
        
        print '\n\tNOTES:'
        print '\t\t(1) To include spaces in any of the parameter lists, surround the list with double-quotes,'
        print '\t\t i.e., "value1, value2, ..."'
        
        print '\n\t\t(2) Replacement of portal item URLs:'
        print '\t\t\t-This script will replace the host names in URLs in service, webmap and operation view items; '
        print '\t\t\t the script is hardcoded to replace the source hostname "' + source_hostname + '" with the '
        print '\t\t\t hostname of the target portal server <PortalURL>; i.e., this script assumes that the target'
        print '\t\t\t ArcGIS Server is installed on the target portal machine.'
        sys.exit(1)
    
    
    # Set variables from script parameters
    target_portal_address = sys.argv[1]
    adminuser = sys.argv[2]
    adminpassword = sys.argv[3]
    contentpath = sys.argv[4]
    if len(sys.argv) > 5:
        specified_users = sys.argv[5]
    if len(sys.argv) > 6:
        specified_groups = sys.argv[6]
        specified_groups = [group.strip() for group in specified_groups.split('|')]
    if len(sys.argv) > 7:
        id_mapping_file = sys.argv[7]
    if len(sys.argv) > 8:
        print "You entered too many script parameters."
        sys.exit(1)
        
    if DEBUG:
        print "target_portal_address: " + str(target_portal_address)
        print "adminuser: " + str(adminuser)
        print "adminpassword: " + str(adminpassword)
        print "contentpath: " + str(contentpath)
        if specified_users:
            print "specifiedUsers: " + str(specified_users)
        if specified_groups:
            print "specifiedOpsTypes: " + str(specified_groups)
        if id_mapping_file:
            print "id_mapping_file: " + str(id_mapping_file)
    
    
    # Check if specified content folder exists.
    if not val_arg_content_path(contentpath):
        print "Parameter <ContentFolderPath>: folder '" + contentpath + "' does not exist."
        sys.exit(1)
    
    # Check if specified users are valid
    users = val_arg_users(specified_users, contentpath)
    
    if DEBUG:
        print "Users to publish: " + str(users.keys())
    
    # Check if specified id mapping file exists
    if id_mapping_file:
        if not os.path.exists(id_mapping_file):
            print "Parameter {IdMappingFile}: folder '" + id_mapping_file + "' does not exist."
    
    # Extract target ArcGIS Server hostname from target portal URL;
    # NOTE: this script assumes that the ArcGIS Server is installed
    # on the same machine as Portal for ArcGIS
    new_hostname =  parse_hostname(target_portal_address)
    hostname_map = {source_hostname: new_hostname}
        
    # Publish content to target portal
    publish_portal(target_portal_address, contentpath, adminuser, adminpassword, users, hostname_map, specified_groups, id_mapping_file)
    
    os.chdir(contentpath)
dataset/ETHPy150Open Esri/ops-server-config/Publish/Portal/PortalContentPost.py/main/original