本文整理汇总了Python中scalarizr.libs.metaconf.Configuration.get_list方法的典型用法代码示例。如果您正苦于以下问题:Python Configuration.get_list方法的具体用法?Python Configuration.get_list怎么用?Python Configuration.get_list使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scalarizr.libs.metaconf.Configuration
的用法示例。
在下文中一共展示了Configuration.get_list方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BaseRedisConfig
# 需要导入模块: from scalarizr.libs.metaconf import Configuration [as 别名]
# 或者: from scalarizr.libs.metaconf.Configuration import get_list [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))