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


Python String.startsWith方法代码示例

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


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

示例1: loadProperties

# 需要导入模块: from java.lang import String [as 别名]
# 或者: from java.lang.String import startsWith [as 别名]
def loadProperties(cfg_file, extra_props):
    props = Properties()
    iterated_props = Properties()
    inherited_props = Properties()
    
    data_linage = Properties()
	
    redback_reg = redback.load_redback_registry() 
    site_home = redback_reg.getProperty('site.home') 
    global_properties = redback_reg.getProperty('global.properties')

    if global_properties:
        if site_home:
            baseFile=getBaseFile(global_properties, site_home)
            if baseFile=='':
                log.error('Global properties file does not exist: ' + global_properties)
                log.info('Suggested Fix: Update the global.properties property within redback.properties to the correct file path')
                sys.exit()
            global_properties=baseFile
        log.info('Loading global configuration from file: ' + global_properties)
        addPropertiesFromFile(props, global_properties, site_home)
    
    if cfg_file:
        addPropertiesFromFile(props, cfg_file, site_home)
    
    if extra_props:
        props.putAll(extra_props)
		
	# resolve property level inheritance and iterations
    log.debug('Attempting to resolve property level inheritance')
    enum = props.keys()
    while enum.hasMoreElements():
        key = enum.nextElement()
        value = props.getProperty(key)
        # Check for property level inheritance
        if re.search(r"\.base$", key) is not None:				
            prop_to_inherit = value
            prop_to_extend = key[:-5]
            log.debug('Inheriting the properties from the ' + prop_to_inherit + ' section in to the section ' + prop_to_extend)
            # Iterate the properties again looking for a match on properties to inherit
            enum_inner = props.keys()
            while enum_inner.hasMoreElements():
                key_inner = enum_inner.nextElement()
                value_inner = props.getProperty(key_inner)
                log.debug('Checking key_inner [' + key_inner + '] matches ' + prop_to_inherit)
                if String.startsWith(String(key_inner),String(prop_to_inherit)):
                    new_property = prop_to_extend + String.substring(key_inner, len(prop_to_inherit))					
                    # Don't override the property if it has already been defined earlier
                    if props.getProperty(new_property) is None:
                        log.debug('Setting inherited property ' + new_property + ' to value ' + value_inner)
                        inherited_props.setProperty(new_property, value_inner)
                        addDataLinage(key,cfg_file,value_inner)
            # Remove the key that defines the base, just keeps us consistant with the template behaviours
            log.debug("About to remove key " + key)
            props.remove(key)
                        
    props.putAll(inherited_props)
    
    log.debug('Attempting to resolve iterations')
    enum = props.keys()
    while enum.hasMoreElements():			
        key = enum.nextElement()
        value = props.getProperty(key)				
        # Check for property set iterations
        if re.search(r"\.iterate$", key) is not None:
            iteration_key = key            
            iteration_set = eval(value)
            prop_to_iterate = key[:-9]
            log.debug('Iterating the properties from the ' + prop_to_iterate + ' section')
            # Iterate the properties again looking for a match on properties to iterate
            enum_inner = props.keys()
            while enum_inner.hasMoreElements():
                key_inner = enum_inner.nextElement()
                value_inner = props.getProperty(key_inner)
                # if the string is part of the set but not the actual iterator then we will check it
                if String.startsWith(String(key_inner),String(prop_to_iterate)) and key_inner != iteration_key:
                    log.debug('Checking if the key [' + key_inner + '] or value = ' + value_inner + ' contains an iterator ')
                    contains_iterator = 0
                    iterated_key = String(key_inner)
                    iterated_value = String(value_inner)
					
                    if String.indexOf(String(key_inner),"%") > -1:
                        log.debug(key_inner + ' contains an iterator, replacing it')						
                        contains_iterator = 1

                    if String.indexOf(String(value_inner),"%") > -1:
                        log.debug(value_inner + ' contains an iterator, replacing it')	
                        contains_iterator = 1											
					                                       
                    for i in iteration_set:
                        iterated_key = String.replaceAll(String(key_inner),"\%",str(i))
                        iterated_value = String.replaceAll(String(value_inner),"\%",str(i))	
						
                        # Don't override the property if it has already been defined earlier
                        if props.getProperty(iterated_key) is None:
                            log.debug('Setting iterated property ' + iterated_key + ' to value ' + iterated_value)
                            iterated_props.setProperty(iterated_key, iterated_value)
                            addDataLinage(key,cfg_file,iterated_value)
					
                    # Remove the key that gets iterated, just keeps us consistant with the template behaviours
#.........这里部分代码省略.........
开发者ID:Integral-Technology-Solutions,项目名称:ConfigNOW,代码行数:103,代码来源:config_loader.py


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