config: Add read helper

This commit is contained in:
Thomas Adamcik 2013-04-13 21:06:09 +02:00
parent 917c1e4c9d
commit b655e846b1
8 changed files with 15 additions and 10 deletions

View File

@ -14,7 +14,7 @@ class Extension(ext.Extension):
def get_default_config(self):
conf_file = os.path.join(os.path.dirname(__file__), 'ext.conf')
return open(conf_file).read()
return config.read(conf_file)
def get_config_schema(self):
schema = config.ExtensionConfigSchema()

View File

@ -14,7 +14,7 @@ class Extension(ext.Extension):
def get_default_config(self):
conf_file = os.path.join(os.path.dirname(__file__), 'ext.conf')
return open(conf_file).read()
return config.read(conf_file)
def get_config_schema(self):
schema = config.ExtensionConfigSchema()

View File

@ -14,7 +14,7 @@ class Extension(ext.Extension):
def get_default_config(self):
conf_file = os.path.join(os.path.dirname(__file__), 'ext.conf')
return open(conf_file).read()
return config.read(conf_file)
def get_config_schema(self):
schema = config.ExtensionConfigSchema()

View File

@ -35,10 +35,15 @@ config_schemas['proxy']['password'] = String(optional=True, secret=True)
#config_schemas['audio.outputs'] = config.AudioOutputConfigSchema()
def read(config_file):
"""Helper to load defaults in same way across core and extensions."""
with io.open(config_file, 'rb') as filehandle:
return filehandle.read()
def load(files, overrides, extensions=None):
default_config_file = os.path.join(
os.path.dirname(__file__), 'default.conf')
defaults = [open(default_config_file).read()]
config_dir = os.path.dirname(__file__)
defaults = [read(os.path.join(config_dir, 'default.conf'))]
if extensions:
defaults.extend(e.get_default_config() for e in extensions)
return _load(files, defaults, overrides)

View File

@ -14,7 +14,7 @@ class Extension(ext.Extension):
def get_default_config(self):
conf_file = os.path.join(os.path.dirname(__file__), 'ext.conf')
return open(conf_file).read()
return config.read(conf_file)
def get_config_schema(self):
schema = config.ExtensionConfigSchema()

View File

@ -14,7 +14,7 @@ class Extension(ext.Extension):
def get_default_config(self):
conf_file = os.path.join(os.path.dirname(__file__), 'ext.conf')
return open(conf_file).read()
return config.read(conf_file)
def get_config_schema(self):
schema = config.ExtensionConfigSchema()

View File

@ -14,7 +14,7 @@ class Extension(ext.Extension):
def get_default_config(self):
conf_file = os.path.join(os.path.dirname(__file__), 'ext.conf')
return open(conf_file).read()
return config.read(conf_file)
def get_config_schema(self):
schema = config.ExtensionConfigSchema()

View File

@ -14,7 +14,7 @@ class Extension(ext.Extension):
def get_default_config(self):
conf_file = os.path.join(os.path.dirname(__file__), 'ext.conf')
return open(conf_file).read()
return config.read(conf_file)
def get_config_schema(self):
schema = config.ExtensionConfigSchema()