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


Python Configuration.comment方法代码示例

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


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

示例1: BaseRedisConfig

# 需要导入模块: from scalarizr.libs.metaconf import Configuration [as 别名]
# 或者: from scalarizr.libs.metaconf.Configuration import comment [as 别名]
class BaseRedisConfig(BaseConfig):

	config_type = 'redis'


	def set(self, option, value, append=False):
		if not self.data:
			self.data = Configuration(self.config_type)
			if os.path.exists(self.path):
				self.data.read(self.path)
		if value:
			if append:
				self.data.add(option, str(value))
			else:
				self.data.set(option,str(value), force=True)
		else:
			self.data.comment(option)
		if self.autosave:
			self.save_data()
			self.data = None


	def set_sequential_option(self, option, seq):
		is_typle = type(seq) is tuple
		try:
			assert seq is None or is_typle
		except AssertionError:
			raise ValueError('%s must be a sequence (got %s instead)' % (option, seq))
		self.set(option, ' '.join(map(str,seq)) if is_typle else None)


	def get_sequential_option(self, option):
		raw = self.get(option)
		return raw.split() if raw else ()


	def get_list(self, option):
		if not self.data:
			self.data =  Configuration(self.config_type)
			if os.path.exists(self.path):
				self.data.read(self.path)
		try:
			value = self.data.get_list(option)
		except NoPathError:
			try:
				value = getattr(self, option+'_default')
			except AttributeError:
				value = ()
		if self.autosave:
			self.data = None
		return value


	def get_dict_option(self, option):
		raw = self.get_list(option)
		d = {}
		for raw_value in raw:
			k,v = raw_value.split()
			if k and v:
				d[k] = v
		return d


	def set_dict_option(self, option, d):
		try:
			assert d is None or type(d)==dict
			#cleaning up
			#TODO: make clean process smarter using indexes
			for i in self.get_list(option):
				self.set(option+'[0]', None)

			#adding multiple entries
			for k,v in d.items():
				val = ' '.join(map(str,'%s %s'%(k,v)))
				self.set(option, val, append=True)
		except ValueError:
			raise ValueError('%s must be a sequence (got %s instead)' % (option, d))
开发者ID:golovast,项目名称:scalarizr,代码行数:79,代码来源:redis.py

示例2: except

# 需要导入模块: from scalarizr.libs.metaconf import Configuration [as 别名]
# 或者: from scalarizr.libs.metaconf.Configuration import comment [as 别名]
                config.read(os.path.join(bus.share_path, "nginx/server.tpl"))

        if disttool.is_debian_based():
        # Comment /etc/nginx/sites-enabled/*
            try:
                i = config.get_list('http/include').index('/etc/nginx/sites-enabled/*')
                config.comment('http/include[%d]' % (i+1))
                self._logger.debug('comment site-enabled include')
            except (ValueError, IndexError):
                self._logger.debug('site-enabled include already commented')
        elif disttool.is_redhat_based():
            def_host_path = '/etc/nginx/conf.d/default.conf'
            if os.path.exists(def_host_path):
                default_host = Configuration('nginx')
                default_host.read(def_host_path)
                default_host.comment('server')
                default_host.write(def_host_path)

        if dump == self._dump_config(config):
            self._logger.debug("Main nginx config wasn`t changed")
        else:
            # Write new nginx.conf
            shutil.copy(nginx_conf_path, nginx_conf_path + '.bak')
            config.write(nginx_conf_path)
            if reload_service:
                self.api._reload_service()

    def _insert_iptables_rules(self, *args, **kwargs):
        if iptables.enabled():
            iptables.FIREWALL.ensure([
                    {"jump": "ACCEPT", "protocol": "tcp", "match": "tcp", "dport": "80"},
开发者ID:AnyBucket,项目名称:scalarizr,代码行数:33,代码来源:nginx.py

示例3: BaseConfig

# 需要导入模块: from scalarizr.libs.metaconf import Configuration [as 别名]
# 或者: from scalarizr.libs.metaconf.Configuration import comment [as 别名]
class BaseConfig(object):
	'''
	Parent class for object representations of postgresql.conf and recovery.conf which fortunately both have similar syntax
	'''
	
	autosave = None
	path = None
	data = None
	config_name = None
	config_type = None
	comment_empty = False
	
	def __init__(self, path, autosave=True):
		self._logger = logging.getLogger(__name__)
		self.autosave = autosave
		self.path = path
		
	@classmethod
	def find(cls, config_dir):
		return cls(os.path.join(config_dir.path, cls.config_name))
		
	def set(self, option, value):
		if not self.data:
			self.data = Configuration(self.config_type)
			if os.path.exists(self.path):
				self.data.read(self.path)
		if value:
			self.data.set(option,str(value), force=True)
		elif self.comment_empty: 
			self.data.comment(option)
		if self.autosave:
			self.save_data()
			self.data = None
			
	def set_path_type_option(self, option, path):
		if not os.path.exists(path):
			raise ValueError('%s %s does not exist' % (option, path))
		self.set(option, path)		
		
	def set_numeric_option(self, option, number):
		try:
			assert number is None or type(number) is int
		except AssertionError:
			raise ValueError('%s must be a number (got %s instead)' % (option, number))
		
		is_numeric = type(number) is int
		self.set(option, str(number) if is_numeric else None)

					
	def get(self, option):
		if not self.data:
			self.data =  Configuration(self.config_type)
			if os.path.exists(self.path):
				self.data.read(self.path)	
		try:
			value = self.data.get(option)	
		except NoPathError:
			try:
				value = getattr(self, option+'_default')
			except AttributeError:
				value = None
		if self.autosave:
			self.data = None
		return value
	
	def get_numeric_option(self, option):
		value = self.get(option)
		try:
			assert value is None or int(value)
		except AssertionError:
			raise ValueError('%s must be a number (got %s instead)' % (option, type(value)))
		return value if value is None else int(value)
	
	def save_data(self):
		if self.data:
			self.data.write(self.path)			
开发者ID:golovast,项目名称:scalarizr,代码行数:78,代码来源:__init__.py


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