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


Python Configuration.getConfigValue方法代码示例

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


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

示例1: __init__

# 需要导入模块: from Configuration import Configuration [as 别名]
# 或者: from Configuration.Configuration import getConfigValue [as 别名]
class DaemonDDNS:
	def __init__(self,config): 
		self.config = config
		self.stdin_path = '/dev/null'
		self.stdout_path = '/dev/null'
		self.stderr_path = '/dev/null'
		self.pidfile_path =  '/var/run/ddnsDaemon.pid'
		self.pidfile_timeout = 5
		self.running = 0
	
	def reloadConfigFile(self, signum, frame):
		old_configuration = self.config
		try:
			# Instance new configuration object
			self.config = Configuration() 
			
			# Set new log level
			log_level = self.config.getConfigValue('log_level')
			if not (log_level.isdigit()):
				log_level = eval('logging.'+log_level)
			
			logger.setLevel(log_level)
			
			logger.info("Config reloaded correctly"); 
		except Exception as e:
			self.config = old_configuration
			logger.error("Error reloading configuration " + str(e))
			logger.info("Damemon keeps working with previous configuration")
	
	def run(self):
		logger.info("ddnsDaemon started!")
		self.running = 1
		
		# Signal control for config reload
		signal.signal(signal.SIGHUP, self.reloadConfigFile)
		
		# Instance public ip getter
		try:
			module = __import__('Publicip')
			class_ = getattr(module, self.config.getConfigValue('ip_service'))
			self.public_ip = class_()
		except Exception as e:
			self.running = 0
			logger.error("Error loading ip getter for " 
			     + self.config.getConfigValue('ip_service')
			     + ". ddnsDaemon finished!")
			sys.exit(1)
	
		while True:
			current_ip = self.public_ip.getIp()
			
			for zone_data in self.config.getConfigValue('zones'):
				for zone in zone_data['zones']:
					ips = self.getZone(zone_data['domain'], zone['zone'], zone['type'])
					
					if len(ips):
						logger.debug(zone['zone']
							+'.'+zone_data['domain']
							+ ' has ips: ' + ','.join(ips))
					else:
						logger.warning(zone['zone']+'.'+zone_data['domain']
							+ ' is not defined on your dns client.') 
					
					if current_ip in ips:
						logger.debug('No updates needed')
					else:
						logger.debug('Updating zone '+ zone['zone']
							+'.'+zone_data['domain'] + '...')
						zone_update_data= { 'zone': zone['zone'], 'domain': zone_data['domain'],
							'type': zone['type'], 'ip': current_ip}
						try:
							zone_updater = ZoneUpdateRunner(zone_data['service'])
							zone_updater.instance()
							response = zone_updater.launchUpdate(zone_update_data,
								(self.config.getConfigValue('services'))[zone_data['service']])
							logger.debug("Response from " + zone_data['service'] + " updater: " + response)
						except Exception as e:
							logger.error("Error updating '"+ zone_update_data['zone'] +'.'+zone_update_data['domain']
								+"' using " + zone_data['service']  + " service: " + str(e))
						
			
			sleep_time = self.config.getConfigValue('time_sleep')
			logger.debug('Sleeping for ' + str(sleep_time) + ' seconds...')
			for x in range(1, int(sleep_time)):
				time.sleep(1)

	def getZone(self,domain,zone,ztype):
		zone_resolution = []
		query_zone = zone +'.'+domain
		answers = []
		
		#try:
		#	answers = dns.resolver.query(query_zone, ztype)
		#except Exception as e:
		#	if not len(str(e)):
		#		logger.debug("Zone not defined in your conection's dns server")
		#	else:
		#		logger.error("Error getting zones: " + str(e)) 
		#		
		#
#.........这里部分代码省略.........
开发者ID:vrdominguez,项目名称:ddns-daemon,代码行数:103,代码来源:ddnsDaemon.py

示例2: str

# 需要导入模块: from Configuration import Configuration [as 别名]
# 或者: from Configuration.Configuration import getConfigValue [as 别名]
				logger.debug("Zone not defined in your conection's dns server")
			else:
				logger.error("Error getting zones: " + str(e)) 
                for addr in answers:
                        zone_resolution.append(addr[4][0])
		
		return zone_resolution
	
	def __del__(self):
		if self.running:
			self.running = 0
			logger.info('Daemon finished')

# Get log_level configuration
config = Configuration()
log_level = config.getConfigValue('log_level')
if not (int(log_level)):
	log_level = eval('logging.'+log_level)

# Logs configuration
logger = logging.getLogger("ddnsDaemon")
logger.setLevel(log_level)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s", "%Y-%m-%d %H:%M:%S")
handler = logging.FileHandler('/var/log/ddnsDaemon.log')
handler.setFormatter(formatter)
logger.addHandler(handler)

# Daemon launch
ddns_daemon_app = DaemonDDNS(config)
ddns_daemon_runner = runner.DaemonRunner(ddns_daemon_app)
ddns_daemon_runner.daemon_context.files_preserve=[handler.stream] # Keep log file opened
开发者ID:vrdominguez,项目名称:ddns-daemon,代码行数:33,代码来源:ddnsDaemon.py


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