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


Python Configuration.sections方法代码示例

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


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

示例1: get_system_variables

# 需要导入模块: from scalarizr.libs.metaconf import Configuration [as 别名]
# 或者: from scalarizr.libs.metaconf.Configuration import sections [as 别名]
	def get_system_variables(self):
		#TESTING REQUIRED!
		conf = Configuration(self._config_format)
		conf.read(self._config_path)
		vars = {}
		for section in conf.sections('./'):
			vars[section] = conf.get(section)
		return vars
开发者ID:golovast,项目名称:scalarizr,代码行数:10,代码来源:service.py

示例2: __init__

# 需要导入模块: from scalarizr.libs.metaconf import Configuration [as 别名]
# 或者: from scalarizr.libs.metaconf.Configuration import sections [as 别名]
	def __init__(self, manifest_path):
		self._options = []
		ini = Configuration('ini')
		ini.read(manifest_path)
		try:
			self._defaults = dict(ini.items('__defaults__'))
		except NoPathError:
			self._defaults = dict()
		
		for name in ini.sections("./"):
			if name == '__defaults__':
				continue
			self._options.append(_OptionSpec.from_ini(ini, name, self._defaults))
开发者ID:golovast,项目名称:scalarizr,代码行数:15,代码来源:service.py

示例3: _manifest

# 需要导入模块: from scalarizr.libs.metaconf import Configuration [as 别名]
# 或者: from scalarizr.libs.metaconf.Configuration import sections [as 别名]
	def _manifest(self):		
		
		class HeadRequest(urllib2.Request):
			def get_method(self):
				return "HEAD"
		
		manifest_url = bus.scalr_url + '/storage/service-configuration-manifests/%s.ini' % self.behaviour	
		path = self._manifest_path

			
		url_handle = urllib2.urlopen(HeadRequest(manifest_url))
		headers = url_handle.info()
		url_last_modified = headers.getdate("Last-Modified")
		
		file_modified = tuple(time.localtime(os.path.getmtime(path))) if os.path.exists(path) else None
		
		if not file_modified or url_last_modified > file_modified:
			self._logger.debug('Fetching %s', manifest_url)
			response = urllib2.urlopen(manifest_url)
			data = response.read()
			if data:
				old_manifest = Configuration('ini')
				if os.path.exists(path):
					old_manifest.read(path)

				new_manifest = Configuration('ini')
				o = StringIO()
				o.write(data)
				o.seek(0)
				new_manifest.readfp(o)
				
				new_sections = new_manifest.sections('./')  
				old_sections = old_manifest.sections('./')

				diff_path = os.path.join(os.path.dirname(path), self.behaviour + '.incdiff')
				diff = Configuration('ini')
									
				if old_sections and old_sections != new_sections:
					#skipping diff if no previous manifest found or it is equal to the new one
					if os.path.exists(diff_path):
						diff.read(diff_path)

					sys_vars = self.get_system_variables()

					for section in new_sections:
						if section not in old_sections and sys_vars.has_key(section):
							sys_var = sys_vars[section]
							if self.definitions:
								if self.definitions.has_key(sys_var):
									sys_var = self.definitions[sys_var]
							diff.add('./%s/default-value' % section, sys_var, force=True)
							diff.write(diff_path)
				
				if os.path.exists(diff_path):
					diff.read(diff_path)
				
				for variable in diff.sections('./'):
					sys_value = diff.get('./%s/default-value' % variable)
					if sys_value and variable in new_manifest.sections('./'):
						new_manifest.set('./%s/default-value' % variable, sys_value, force=True)
				new_manifest.write(path)

		return _CnfManifest(path)
开发者ID:golovast,项目名称:scalarizr,代码行数:65,代码来源:service.py


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