Пример #1
0
def save_env_option_setting_file(location, option_settings):
    log.info(u'Try loading option settings file from {0}'.format(location))
#    old_option_settings = load_env_option_setting_file(location, quiet = True)
    
    log.info(u'Writing environment option settings to file at "{0}".'.format(location))
    try:
        parser = SectionedConfigParser()
        
        for namespace, options in sorted(option_settings.iteritems()):
            if len(options) < 1:
                continue
            
            for option, value in sorted(options.iteritems()):
                if not _is_whitelisted_option(namespace, option):
#                    and (namespace not in old_option_settings \
#                         or option not in old_option_settings[namespace]):
                    continue
                
                if not parser.has_section(namespace):
                    parser.add_section(namespace)
                
                # Add option setting to new file
                if value is None:
                    value = u''
                parser.set(namespace, option, value)
        
        parser.write(location)
        log.debug(u'Option settings written to file include: "{0}".'.\
                  format(misc.collection_to_string(option_settings)))
       
        set_access_permission(location, True)
    except BaseException as ex:
        log.error(u'Failed to save environment option setting file, because: "{0}"'.format(ex))
        prompt.error(OptionSettingFileErrorMessage.WriteError.format(location))        
        raise    
def save_env_option_setting_file(location, option_settings):
    log.info(u'Try loading option settings file from {0}'.format(location))
#    old_option_settings = load_env_option_setting_file(location, quiet = True)
    
    log.info(u'Writing environment option settings to file at "{0}".'.format(location))
    try:
        parser = SectionedConfigParser()
        
        for namespace, options in sorted(option_settings.iteritems()):
            if len(options) < 1:
                continue
            
            for option, value in sorted(options.iteritems()):
                if not _is_whitelisted_option(namespace, option):
#                    and (namespace not in old_option_settings \
#                         or option not in old_option_settings[namespace]):
                    continue
                
                if not parser.has_section(namespace):
                    parser.add_section(namespace)
                
                # Add option setting to new file
                if value is None:
                    value = u''
                parser.set(namespace, option, value)
        
        parser.write(location)
        log.debug(u'Option settings written to file include: "{0}".'.\
                  format(misc.collection_to_string(option_settings)))
       
        set_access_permission(location, True)
    except BaseException as ex:
        log.error(u'Failed to save environment option setting file, because: "{0}"'.format(ex))
        prompt.error(OptionSettingFileErrorMessage.WriteError.format(location))        
        raise    
Пример #3
0
def save_env_option_setting_file(location, option_settings):
    log.info(u'Writing environment option settings to file at "{0}".'.format(
        location))
    try:
        parser = SectionedConfigParser()

        for namespace, options in sorted(option_settings.iteritems()):
            if len(options) < 1:
                continue

            for option, value in sorted(options.iteritems()):

                if namespace.startswith(OptionSettingContainerPrefix):
                    pass
                elif namespace.startswith(
                        OptionSettingApplicationEnvironment.Namespace):
                    if option in OptionSettingApplicationEnvironment.IgnoreOptionNames:
                        continue
                    else:
                        pass
                # Skip if option setting is on in local option setting list
                elif namespace not in LocalOptionSettings \
                    or option not in LocalOptionSettings[namespace]:
                    continue

                if not parser.has_section(namespace):
                    parser.add_section(namespace)

                if value is None:
                    value = u''
                parser.set(namespace, option, value)

        parser.write(location)
        log.debug(u'Option settings written to file include: "{0}".'.\
                  format(misc.collection_to_string(option_settings)))

        set_access_permission(location, True)
    except BaseException as ex:
        log.error(
            u'Failed to save environment option setting file, because: "{0}"'.
            format(ex))
        prompt.error(OptionSettingFileErrorMessage.WriteError.format(location))
        raise
Пример #4
0
def save_env_option_setting_file(location, option_settings):
    log.info('Writing environment option settings to file at "{0}".'.format(location))
    try:
        parser = SectionedConfigParser()
        
        for namespace, options in sorted(option_settings.items()):
            if len(options) < 1:
                continue
            
            for option, value in sorted(options.items()):

                if namespace.startswith(OptionSettingContainerPrefix):
                    pass
                elif namespace.startswith(OptionSettingApplicationEnvironment.Namespace):
                    if option in OptionSettingApplicationEnvironment.IgnoreOptionNames:
                        continue
                    else:
                        pass
                # Skip if option setting is on in local option setting list
                elif namespace not in LocalOptionSettings \
                    or option not in LocalOptionSettings[namespace]:
                    continue

                if not parser.has_section(namespace):
                    parser.add_section(namespace)
                
                if value is None:
                    value = ''
                parser.set(namespace, option, value)
        
        parser.write(location)
        log.debug('Option settings written to file include: "{0}".'.\
                  format(misc.collection_to_string(option_settings)))
       
        set_access_permission(location, True)
    except BaseException as ex:
        log.error('Failed to save environment option setting file, because: "{0}"'.format(ex))
        prompt.error(OptionSettingFileErrorMessage.WriteError.format(location))        
        raise    
        
Пример #5
0
def save_eb_config_file(location, parameter_pool, quiet = False):
    log.info(u'Writing EB configuration to file: "{0}".'.format(location))
    try:
        parser = SectionedConfigParser()
        parser.add_section(EbConfigFile.RootSectionName)    # Make root section the first

        # add known session
        for section_name, (condition, keys) in EbConfigFile.KnownSections.iteritems():
            if parameter_pool.has(condition) and parameter_pool.get_value(condition):
                log.debug(u'Create section "{0}" in config file.'.format(section_name))
                parser.add_section(section_name)
                for key in sorted(keys):
                    if parameter_pool.has(key):
                        value = parameter_pool.get_value(key)
                        if key in ConfigFileParameters:
                            _, to_file = ConfigFileParameters[key]
                            if to_file is not None:
                                value = to_file(value)
                        parser.set(section_name, key, value)

        # add branch mapping sections
        if parameter_pool.has(ParameterName.BranchMapping)\
            and len(parameter_pool.get_value(ParameterName.BranchMapping)) > 0:
            log.debug(u'Create section "{0}" in config file.'.format(EbConfigFile.BranchSectionName))
            parser.add_section(EbConfigFile.BranchSectionName)
            branch_map = parameter_pool.get_value(ParameterName.BranchMapping)
            for key in sorted(branch_map.keys()):
                parser.set(EbConfigFile.BranchSectionName, key, branch_map[key])

        # add branch environment sections
        if parameter_pool.has(ParameterName.Branches)\
            and len(parameter_pool.get_value(ParameterName.Branches)) > 0:
            branches = parameter_pool.get_value(ParameterName.Branches)
            for branch_name in sorted(branches.keys()):
                section_name = EbConfigFile.BranchSectionPrefix + branch_name
                log.debug(u'Create section "{0}" in config file.'.format(section_name))
                parser.add_section(section_name)
                branch = branches[branch_name]
                for key in sorted(EbConfigFile.BranchSectionKeys):
                    if key in branch:
                        value = branch[key]
                        if key in ConfigFileParameters:
                            _, to_file = ConfigFileParameters[key]
                            if to_file is not None:
                                value = to_file(value)
                        parser.set(section_name, key, value)
            
        # add else
        if parameter_pool.has(ParameterName.ConfigFileExtra): 
            extra_config = parameter_pool.get_value(ParameterName.ConfigFileExtra) 
            for section, pairs in sorted(extra_config.iteritems(), key=operator.itemgetter(0)):
                if not parser.has_section(section):
                    log.debug(u'Create section "{0}" in config file.'.format(section))
                    parser.add_section(section)
                for key, value in pairs.iteritems():
                    parser.set(section, key, value)

        parser.write(location)
        log.info(u'Finished writing EB configuration file.')
        
    except BaseException as ex:
        log.error(u'Failed to save EB configuration file, because: "{0}"'.format(ex))
        prompt.error(ConfigFileErrorMessage.WriteError.format(location))        
        raise