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


Python Configuration.read方法代码示例

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


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

示例1: Cassandra

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

	def __init__(self):
		self._logger = logging.getLogger(__name__)
		self._initd = initdv2.lookup(SERVICE_NAME)		
		
		bus.on(reload=self.on_reload)
		self.on_reload()
		
	def on_reload(self):
		self.queryenv = bus.queryenv_service
		self.platform = bus.platform
		self.private_ip = self.platform.get_private_ip()
		self.zone = self.platform.get_avail_zone()
		
		cnf = bus.cnf 
		self.ini = cnf.rawini
		
		self.role_name = self.ini.get(config.SECT_GENERAL, config.OPT_ROLE_NAME)

		self.storage_path = self.ini.get(CNF_SECTION, OPT_STORAGE_PATH)
		self.storage_conf_path = self.ini.get(CNF_SECTION, OPT_STORAGE_CNF_PATH)

		self.data_file_directory = self.storage_path + "/datafile"
		self.commit_log_directory = self.storage_path + "/commitlog"
		
		self.cassandra_conf = Configuration('xml')
		try:
			self.cassandra_conf.read(self.storage_conf_path)
		except (OSError, MetaconfError, ParseError), e:
			self._logger.error('Cassandra storage-conf.xml is broken. %s' % e)
开发者ID:golovast,项目名称:scalarizr,代码行数:33,代码来源:cassandra.py

示例2: _test_path_option

# 需要导入模块: from scalarizr.libs.metaconf import Configuration [as 别名]
# 或者: from scalarizr.libs.metaconf.Configuration import read [as 别名]
 def _test_path_option(self, option):
     self.assertRaises(ValueError, setattr, self.cnf, option, '/not/exists')
     setattr(self.cnf, option, '/tmp')
     c = Configuration('mongodb')
     c.read(self.cnf_path)
     self.assertEqual('/tmp', c.get(option))
     self.assertEqual('/tmp', getattr(self.cnf, option))
开发者ID:AnyBucket,项目名称:scalarizr,代码行数:9,代码来源:test_mongodb.py

示例3: apply_preset

# 需要导入模块: from scalarizr.libs.metaconf import Configuration [as 别名]
# 或者: from scalarizr.libs.metaconf.Configuration import read [as 别名]
	def apply_preset(self, preset):
		conf = Configuration(self._config_format)
		conf.read(self._config_path)
		
		self._before_apply_preset()
		
		ver = self._software_version
		for opt in self._manifest:
			path = opt.name if not opt.section else '%s/%s' % (opt.section, opt.name)
			
			try:
				value = conf.get(path)
			except NoPathError:
				value = ''
			
			if opt.name in preset.settings:
				new_value = preset.settings[opt.name]
				
				# Skip unsupported
				if ver and opt.supported_from and opt.supported_from > ver:
					self._logger.debug("Skipping option '%s' supported from %s; installed %s" % 
							(opt.name, opt.supported_from, ver))
					continue
								
				if not opt.default_value:
					self._logger.debug("Option '%s' has no default value" % opt.name)
					pass		
				elif new_value == opt.default_value: 
					if value:
						self._logger.debug("Option '%s' equal to default. Removing." % opt.name)
						conf.remove(path)
					self._after_remove_option(opt)				
					continue	
				
				if self.definitions and new_value in self.definitions:
					manifest = Configuration('ini')
					if os.path.exists(self._manifest_path):
						manifest.read(self._manifest_path)
					try:
						if manifest.get('%s/type' % opt.name) == 'boolean':
							new_value = self.definitions[new_value]
					except NoPathError, e:
						pass
				
				self._logger.debug("Check that '%s' value changed:'%s'='%s'"%(opt.name, value, new_value))
					
				if new_value == value:
					self._logger.debug("Skip option '%s'. Not changed" % opt.name)
					pass
				else:
					self._logger.debug("Set option '%s' = '%s'" % (opt.name, new_value))
					self._logger.debug('Set path %s = %s', path, new_value)
					conf.set(path, new_value, force=True)
					self._after_set_option(opt, new_value)
			else:
				if value:
					self._logger.debug("Removing option '%s'. Not found in preset" % opt.name)	
					conf.remove(path)
				self._after_remove_option(opt)
开发者ID:golovast,项目名称:scalarizr,代码行数:61,代码来源:service.py

示例4: get_system_variables

# 需要导入模块: from scalarizr.libs.metaconf import Configuration [as 别名]
# 或者: from scalarizr.libs.metaconf.Configuration import read [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

示例5: _update_main_config

# 需要导入模块: from scalarizr.libs.metaconf import Configuration [as 别名]
# 或者: from scalarizr.libs.metaconf.Configuration import read [as 别名]
    def _update_main_config(self, remove_server_section=True, reload_service=True):
        config_dir = os.path.dirname(self.api.app_inc_path)
        nginx_conf_path = os.path.join(config_dir, 'nginx.conf')

        config = None
        try:
            config = Configuration('nginx')
            config.read(nginx_conf_path)
        except (Exception, BaseException), e:
            raise HandlerError('Cannot read/parse nginx main configuration file: %s' % str(e))
开发者ID:AnyBucket,项目名称:scalarizr,代码行数:12,代码来源:nginx.py

示例6: _https_config_exists

# 需要导入模块: from scalarizr.libs.metaconf import Configuration [as 别名]
# 或者: from scalarizr.libs.metaconf.Configuration import read [as 别名]
    def _https_config_exists(self):
        config_dir = os.path.dirname(self.api.app_inc_path)
        conf_path = os.path.join(config_dir, 'https.include')

        config = None
        try:
            config = Configuration('nginx')
            config.read(conf_path)
        except (Exception, BaseException), e:
            raise HandlerError('Cannot read/parse nginx main configuration file: %s' % str(e))
开发者ID:AnyBucket,项目名称:scalarizr,代码行数:12,代码来源:nginx.py

示例7: _test_option

# 需要导入模块: from scalarizr.libs.metaconf import Configuration [as 别名]
# 或者: from scalarizr.libs.metaconf.Configuration import read [as 别名]
    def _test_option(self, option):
        setattr(self.cnf, option, 'value')
        c = Configuration('mongodb')
        c.read(self.cnf_path)
        self.assertEqual('value', c.get(option))

        setattr(self.cnf, option, None)
        c = Configuration('mongodb')
        c.read(self.cnf_path)
        self.assertRaises(NoPathError, c.get, option)
开发者ID:AnyBucket,项目名称:scalarizr,代码行数:12,代码来源:test_mongodb.py

示例8: load

# 需要导入模块: from scalarizr.libs.metaconf import Configuration [as 别名]
# 或者: from scalarizr.libs.metaconf.Configuration import read [as 别名]
	def load(self, preset_type):
		'''
		@rtype: Preset
		@raise OSError: When cannot read preset file
		@raise MetaconfError: When experience problems with preset file parsing
		'''
		self._logger.debug('Loading %s %s preset' % (preset_type, self.service_name))
		ini = Configuration('ini')
		ini.read(self._filename(preset_type))
		
		return CnfPreset(ini.get('general/name'), dict(ini.items('settings/'))) 
开发者ID:golovast,项目名称:scalarizr,代码行数:13,代码来源:service.py

示例9: _main_config_contains_server

# 需要导入模块: from scalarizr.libs.metaconf import Configuration [as 别名]
# 或者: from scalarizr.libs.metaconf.Configuration import read [as 别名]
    def _main_config_contains_server(self):
        config_dir = os.path.dirname(self.api.app_inc_path)
        nginx_conf_path = os.path.join(config_dir, 'nginx.conf')

        config = None
        result = False
        try:
            config = Configuration('nginx')
            config.read(nginx_conf_path)
        except (Exception, BaseException), e:
            raise HandlerError('Cannot read/parse nginx main configuration file: %s' % str(e))
开发者ID:AnyBucket,项目名称:scalarizr,代码行数:13,代码来源:nginx.py

示例10: _manifest

# 需要导入模块: from scalarizr.libs.metaconf import Configuration [as 别名]
# 或者: from scalarizr.libs.metaconf.Configuration import read [as 别名]
    def _manifest(self):
        f_manifest = CnfController._manifest
        base_manifest = f_manifest.fget(self)
        path = self._manifest_path

        s = {}
        out = None

        if not self._merged_manifest:
            cmd = '%s --no-defaults --verbose SU_EXEC' % mysql_svc.MYSQLD_PATH
            out = system2('%s - mysql -s %s -c "%s"' % (SU_EXEC, BASH, cmd),
                                    shell=True, raise_exc=False, silent=True)[0]

        if out:
            raw = out.split(49*'-'+' '+24*'-')
            if raw:
                a = raw[-1].split('\n')
                if len(a) > 5:
                    b = a[1:-5]
                    for item in b:
                        c = item.split()
                        if len(c) > 1:
                            key = c[0]
                            val = ' '.join(c[1:])
                            s[key.strip()] = val.strip()

        if s:
            m_config = Configuration('ini')
            if os.path.exists(path):
                m_config.read(path)

            for variable in base_manifest:
                name = variable.name
                dv_path = './%s/default-value' % name

                try:
                    old_value =  m_config.get(dv_path)
                    if name in s:
                        new_value = s[name]
                    else:
                        name = name.replace('_','-')
                        if name in s:
                            new_value = self.definitions[s[name]] if s[name] in self.definitions else s[name]
                            if old_value != new_value and new_value != '(No default value)':
                                LOG.debug('Replacing %s default value %s with precompiled value %s',
                                                name, old_value, new_value)
                                m_config.set(path=dv_path, value=new_value, force=True)
                except NoPathError:
                    pass
            m_config.write(path)

        self._merged_manifest = _CnfManifest(path)
        return self._merged_manifest
开发者ID:AnyBucket,项目名称:scalarizr,代码行数:55,代码来源:mysql2.py

示例11: __init__

# 需要导入模块: from scalarizr.libs.metaconf import Configuration [as 别名]
# 或者: from scalarizr.libs.metaconf.Configuration import read [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

示例12: _test_numeric_option

# 需要导入模块: from scalarizr.libs.metaconf import Configuration [as 别名]
# 或者: from scalarizr.libs.metaconf.Configuration import read [as 别名]
    def _test_numeric_option(self, option):
        self.assertRaises(ValueError, setattr, self.cnf, option, 'NotNumericValue')

        setattr(self.cnf, option, 113)
        c = Configuration('mongodb')
        c.read(self.cnf_path)
        self.assertEqual('113', c.get(option))
        self.assertEqual(113, getattr(self.cnf, option))

        setattr(self.cnf, option, None)
        c = Configuration('mongodb')
        c.read(self.cnf_path)
        self.assertRaises(NoPathError, c.get, option)
开发者ID:AnyBucket,项目名称:scalarizr,代码行数:15,代码来源:test_mongodb.py

示例13: ApacheConfigManager

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

    _cnf = None
    path = None

    def __init__(self, path):
        self._cnf = Configuration("apache")
        self.path = path

    def __enter__(self):
        self._cnf.read(self.path)
        return self._cnf

    def __exit__(self, type, value, traceback):
        self._cnf.write(self.path)
开发者ID:AnyBucket,项目名称:scalarizr,代码行数:17,代码来源:apache.py

示例14: download_and_restore

# 需要导入模块: from scalarizr.libs.metaconf import Configuration [as 别名]
# 或者: from scalarizr.libs.metaconf.Configuration import read [as 别名]
    def download_and_restore(self, volume, snapshot, tranzit_path):
        # Load manifest
        clear_queue(self._writer_queue)
        clear_queue(self._download_queue)
        self._download_finished.clear()
        transfer = self._transfer_cls()
        mnf_path = transfer.download(snapshot.path, tranzit_path)
        mnf = Configuration('ini')
        mnf.read(mnf_path)

        volume.fs_created = False
        volume.mkfs(snapshot.fstype)

        remote_path = os.path.dirname(snapshot.path)
        # Get links with md5 sums
        links = [(os.path.join(remote_path, chunk[0]), chunk[1]) for chunk in mnf.items('chunks')]
        links.sort()

        # Download 2 first chunks
        for link in links[:2]:
            transfer.download(link[0], tranzit_path)
            chunk_path = os.path.join(tranzit_path, os.path.basename(link[0]))
            if self._md5sum(chunk_path) != link[1]:
                raise Exception("md5sum of chunk %s is not correct." % chunk_path)
            self._writer_queue.put(chunk_path)

        if hasattr(snapshot, 'snap_strategy') and snapshot.snap_strategy == 'data':
            restore_strategy = DataRestoreStrategy(self._logger)
        else:
            restore_strategy = DeviceRestoreStrategy(self._logger)

        writer = threading.Thread(target=restore_strategy.restore, name='writer',
                                                        args=(self._writer_queue, volume, self._download_finished))
        writer.start()

        # Add remaining files to download queue
        for link in links[2:]:
            self._download_queue.put(link)

        downloader = threading.Thread(name="Downloader", target=self._downloader,
                                                                  args=(tranzit_path,))
        downloader.start()
        downloader.join()
        writer.join()
开发者ID:notbrain,项目名称:scalarizr,代码行数:46,代码来源:eph.py

示例15: _test_bool_option

# 需要导入模块: from scalarizr.libs.metaconf import Configuration [as 别名]
# 或者: from scalarizr.libs.metaconf.Configuration import read [as 别名]
    def _test_bool_option(self, option):
        self.assertRaises(ValueError, setattr, self.cnf, option, 'NotBoolValue')

        setattr(self.cnf, option, True)
        c = Configuration('mongodb')
        c.read(self.cnf_path)
        self.assertEqual('true', c.get(option))
        self.assertEqual(True, getattr(self.cnf, option))

        setattr(self.cnf, option, False)
        c = Configuration('mongodb')
        c.read(self.cnf_path)
        self.assertEqual('false', c.get(option))
        self.assertEqual(False, getattr(self.cnf, option))

        setattr(self.cnf, option, None)
        c = Configuration('mongodb')
        c.read(self.cnf_path)
        self.assertRaises(NoPathError, c.get, option)

        c.set(option, 'NotBool', force=True)
        c.write(self.cnf_path)
        self.assertRaises(ValueError, getattr, self.cnf, option)
开发者ID:AnyBucket,项目名称:scalarizr,代码行数:25,代码来源:test_mongodb.py


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