当前位置: 首页>>代码示例>>Python>>正文


Python Portal.delete_item方法代码示例

本文整理汇总了Python中portalpy.Portal.delete_item方法的典型用法代码示例。如果您正苦于以下问题:Python Portal.delete_item方法的具体用法?Python Portal.delete_item怎么用?Python Portal.delete_item使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在portalpy.Portal的用法示例。


在下文中一共展示了Portal.delete_item方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from portalpy import Portal [as 别名]
# 或者: from portalpy.Portal import delete_item [as 别名]
def main():
    exit_err_code = 1
    
    # Print/get script arguments
    results = print_args()
    if not results:
        sys.exit(exit_err_code)
    portal_address, adminuser, password, delete_option = results
    
    total_success = True
    title_break_count = 150
    section_break_count = 100
    
    print '=' * title_break_count
    print 'Find Hosted Services'
    print '=' * title_break_count
    
    try:
        file_name = 'hosted_service_item_mapping.json'
        if os.path.exists(file_name):
            os.remove(file_name)
                
        portal = Portal(portal_address, adminuser, password)
        
        print '\n{}'.format('-' * section_break_count)
        print '- Searching for hosted service items...'
        hosted_service_items = get_hosted_service_items(portal)
        
        print '- Found {} hosted service items:'.format(len(hosted_service_items))
        for hosted_service_item in hosted_service_items:
            print format_item_info(hosted_service_item)
        
        print '\n{}'.format('-' * section_break_count)
        print '- Searching for orphaned hosted service items...'
        o_hosted_service_items = get_orphaned_hosted_service_items(portal)
        
        print '- Found {} orphaned hosted service items:'.format(len(o_hosted_service_items))
        for o_hosted_service_item in o_hosted_service_items:
            print format_item_info(o_hosted_service_item)
        
        print '\n{}'.format('-' * section_break_count)
        print '- Map orphaned hosted service item to hosted service item...'
        item_mapping = create_search_replace_id_map(portal)
        if len(item_mapping) == 0:
            print 'No orphaned service items to map.'
            
        if len(item_mapping) > 0:
            for hosted_service_item in hosted_service_items:
                orphanedID = 'NOT FOUND'
                for id_map in item_mapping:
                    if hosted_service_item['id'] == id_map[replace_key]:
                        orphanedID = id_map[search_key]
                print format_item_info(hosted_service_item) + \
                                ' ***[OrphanedID: {}]'.format(orphanedID)
            
            print '\nNOTE: item mapping info written to file "{}" in directory: {}'.format(file_name, os.getcwd())
            json.dump(item_mapping, open(file_name,'w'))
        
        if len(o_hosted_service_items) > 0 and delete_option:
            print '\n{}'.format('-' * section_break_count)
            print '- You selected to delete orphaned hosted service items.'
            print '  Will delete the following items...'
            
            for o_hosted_service_item in o_hosted_service_items:
                print format_item_info(o_hosted_service_item)
        
            user_response = raw_input("\nDo you want to continue with the delete? Enter 'y' to continue: ")
    
            if validate_user_repsonse_yesno(user_response):
                for o_hosted_service_item in o_hosted_service_items:
                    print 'Deleting...'
                    print '\t{}'.format(format_item_info(o_hosted_service_item))
                    resp = portal.delete_item(o_hosted_service_item['id'])
                    print resp
                
    except:
        total_success = False
        
        # Get the traceback object
        tb = sys.exc_info()[2]
        tbinfo = traceback.format_tb(tb)[0]
     
        # Concatenate information together concerning the error 
        # into a message string
        pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + \
                "\nError Info:\n" + str(sys.exc_info()[1])
        
        # Print Python error messages for use in Python / Python Window
        print
        print "***** ERROR ENCOUNTERED *****"
        print pymsg + "\n"
        
    finally:
        print '\nDone.'
        if total_success:
            sys.exit(0)
        else:
            sys.exit(exit_err_code)
开发者ID:Esri,项目名称:ops-server-config,代码行数:100,代码来源:FindOrphanedHostedServices.py

示例2: main

# 需要导入模块: from portalpy import Portal [as 别名]
# 或者: from portalpy.Portal import delete_item [as 别名]

#.........这里部分代码省略.........
                    continue
                    
                if servicePortalItems:
                    print '\n\t- Associated portal items...'
                    for servicePortalItem in servicePortalItems:
                        
                        orig_id = servicePortalItem['itemID']
                        
                        # Get service search string
                        serviceSearchStr = getServiceSearchString(service, servicePortalItem)
                        print '\n\t   - ' + serviceSearchStr + ': original item id = ' + orig_id
                        
                        # Get new portal item id
                        new_id = findPortalItemID(server, serviceSearchStr, portal_url_items)
                        
                        if new_id:
                            if (new_id <> orig_id):
                                numIDsFoundForService = numIDsFoundForService + 1
                                servicePortalItem['itemID'] = new_id
                                portalItemIDsToDelete.append(orig_id)
                                print '\t\tFound new item id - ' + new_id
                            else:
                                print '\t\tItem IDs match, not processing.'
                        else:
                            print '\n\t**** WARNING: new item id not found.'
                    
                    servicePortalProps['portalItems'] = servicePortalItems
                    info['portalProperties'] = servicePortalProps
                    
                    if doUpdateService:
                        print '\n\n\t- Updating portal item information stored within service JSON (service will be restarted automatically)...'
                        
                        if numIDsFoundForService == 0:
                            print '\n\t**** WARNING: there were no new ids found for this service so there is no need to update the service JSON info.'
                            continue
                        
                        success, status = editServiceInfo(server, port, adminuser, password, folder, serviceNameType, info)
                        if success:
                            print '\t\tDone.'
                        else:
                            totalSuccess = False
                            print '**** ERROR: Update of service was not successful.'
                            print 'status: ' + str(status)
                
     
        if doDeleteItems:
            print
            #print '=' * 100
            print '\n\n-Deleting portal items that were remapped to original portal item...'
            
            if len(portalItemIDsToDelete) == 0:
                print '\n**** ERROR: No portal items to delete; which means there were no portal items '
                print '\t     owned by ' + portal.logged_in_user()['username'] + ' that were remapped to original portal item.\n'
            
            # Get list of all portal ids so we can verify that the portal item exists before we delete
            portal_items = portal.search(['id'])
            time.sleep(5)
            
            for portalItemID in portalItemIDsToDelete:
                time.sleep(2)
                itemFound = False
                print '  -Deleting id ' + portalItemID + '...'
                
                # Delete if item exists
                for portal_item in portal_items:
                    if portal_item['id'] == portalItemID:
                        itemFound = True
                        results = portal.delete_item(portalItemID, portal.logged_in_user()['username'])
                        if results:
                            print '\tDone.'
                        else:
                            totalSuccess = False
                            print '**** ERROR: Deletion of service was not successful.'
                if not itemFound:
                    print '\tItem ' + portalItemID + ' does not exist. Skipping...'
                    
    except:
        totalSuccess = False
        
        # Get the traceback object
        tb = sys.exc_info()[2]
        tbinfo = traceback.format_tb(tb)[0]
     
        # Concatenate information together concerning the error into a message string
        pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
     
        # Print Python error messages for use in Python / Python Window
        print
        print "***** ERROR ENCOUNTERED *****"
        print pymsg + "\n"
        
    finally:
        print
        print
        if totalSuccess:
            print "Remap of portal item ids on services was completed successfully."
            sys.exit(0)
        else:
            print "ERROR: Remap of portal item ids on services was _NOT_ completed successfully."
            sys.exit(1)
开发者ID:ACueva,项目名称:ops-server-config,代码行数:104,代码来源:RemapIDsOnServices.py


注:本文中的portalpy.Portal.delete_item方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。