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


Python Validator.validate_area_for_migration方法代码示例

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


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

示例1: __init__

# 需要导入模块: from validator import Validator [as 别名]
# 或者: from validator.Validator import validate_area_for_migration [as 别名]
class BaseMigrator:
    def __init__(self,):
        self.migration_environment = MigrationEnvironment()
        mashery_api_config = self.migration_environment.configuration

        # Logging: had to move to this class since i don't understand python enough;
        # for some reason i couldn't get python to emit the logs to different files;
        # should be re-factored at some point
        
        # turn off info from http requests library
        logging.getLogger('requests').setLevel(logging.ERROR)
        # set a format which is simpler for console use
        formatter1 = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
        # define a Handler which writes INFO messages or higher to the sys.stderr
        streamHandler = logging.StreamHandler()
        streamHandler.setLevel(logging.ERROR)
        streamHandler.setFormatter(formatter1)
        logging.getLogger('').addHandler(streamHandler)  

        formatter2 = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
        l1 = logging.getLogger(self.__class__.__name__)
        fileHandler1 = logging.FileHandler(mashery_api_config['migration']['log_location']  + 'package_migrator.log', mode='a')
        fileHandler1.setLevel(logging.INFO)
        fileHandler1.setFormatter(formatter2)
        l1.addHandler(fileHandler1)
        l1.setLevel(logging.INFO)        
        l1 = logging.getLogger(self.__class__.__name__)

        l2 = logging.getLogger(self.__class__.__name__ + 'Transactions')
        fileHandler2 = logging.FileHandler(mashery_api_config['migration']['log_location']  + 'package_migrator_transactions.log', mode='a')
        fileHandler2.setLevel(logging.INFO)
        fileHandler2.setFormatter(formatter2)
        l2.addHandler(fileHandler2)
        l2.setLevel(logging.INFO)
        l2 = logging.getLogger(self.__class__.__name__ + 'Transactions')

        self.base = Base(mashery_api_config['mashery_api']['protocol'], mashery_api_config['mashery_api']['hostname'], mashery_api_config['mashery_area']['id'], mashery_api_config['mashery_api']['apikey'], mashery_api_config['mashery_api']['secret'], l2)

        self.validator = Validator(l1)

        self.logger = l1

    def update_object_with_required_attributes(self, object_to_update, missing_properties):
        for missing_property in missing_properties:
            if missing_property['field'] == 'uri':
                object_to_update[missing_property['field']] = 'http://www.example.com'
            else:
                object_to_update[missing_property['field']] = 'default'
        
        return object_to_update
    
    def confirm_ready(self):
        print '================================================'
        print 'Area ID= ' + str(self.migration_environment.configuration['mashery_area']['id'])
        print 'Area Name= ' + self.migration_environment.configuration['mashery_area']['name']
        print 'API Hostname/Environment= ' + self.migration_environment.configuration['mashery_api']['hostname']
        print ' '
        print 'Backup Location= ' + self.migration_environment.configuration['migration']['backup_location']
        print 'Log Location= ' + self.migration_environment.configuration['migration']['log_location']
        print 'Key Input File= ' + self.migration_environment.configuration['migration']['key_input_file']
        print ' '
        print '================================================'

        proceed = raw_input('Proceed? (y/n)')
        if proceed == 'y':
            return True
            
        return False

    def ready_for_migration(self):
        # fetch area config
        try:
            area = self.base.area_fetch()
        except ValueError as err:
            self.logger.error('Error fetching data: %s', json.dumps(err.args))
            return

        # fetch keys in area, to see if there are any existing
        # memberless or applicationless ones
        try:
            keys = self.base.fetch('keys', '*, member, application, service, developer_class', '')
        except ValueError as err:
            self.logger.error('Error fetching data: %s', json.dumps(err.args))
            return

        applications = self.transform_keys_map_to_applications_map(keys)

        area_validation_data = self.validator.validate_area_for_migration(area, applications, keys)

        self.logger.info('ready_for_migration: %s', json.dumps(area_validation_data))

        return area_validation_data['ready_for_migration']

    def transform_keys_map_to_applications_map(self, keys):
        applications = {}

        for key in keys:
            app_id = 0
            if (key['application'] != None):
                app_id = key['application']['id']
#.........这里部分代码省略.........
开发者ID:cheryl-mashery,项目名称:masheryapi,代码行数:103,代码来源:base_migrator.py


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