/usr/share/pyshared/configglue/app/base.py is in python-configglue 1.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | ###############################################################################
#
# configglue -- glue for your apps' configuration
#
# A library for simple, DRY configuration of applications
#
# (C) 2009--2011 by Canonical Ltd.
# by John R. Lenton <john.lenton@canonical.com>
# and Ricardo Kirkner <ricardo.kirkner@canonical.com>
#
# Released under the BSD License (see the file LICENSE)
#
# For bug reports, support, and new releases: http://launchpad.net/configglue
#
###############################################################################
import os.path
import sys
from optparse import OptionParser
from xdg.BaseDirectory import load_config_paths
from configglue.glue import configglue
from configglue.schema import (
Schema,
merge,
)
from .plugin import PluginManager
__all__ = [
'App',
]
class Config(object):
def __init__(self, app):
schemas = [app.schema] + app.plugins.schemas
self.schema = merge(*schemas)
# initialize config
config_files = self.get_config_files(app)
self.glue = configglue(self.schema, config_files, op=app.parser)
def get_config_files(self, app):
config_files = []
for path in reversed(list(load_config_paths(app.name))):
self._add_config_file(config_files, path, app.name)
for plugin in app.plugins.enabled:
self._add_config_file(config_files, path, plugin.__name__)
self._add_config_file(config_files, '.', 'local')
return config_files
def _add_config_file(self, config_files, path, name):
filename = os.path.join(path, "{0}.cfg".format(name.lower()))
if os.path.exists(filename):
config_files.append(filename)
class App(object):
schema = Schema
plugin_manager = PluginManager
def __init__(self, schema=None, plugin_manager=None, name=None,
parser=None):
# initialize app name
if name is None:
name = os.path.splitext(os.path.basename(sys.argv[0]))[0]
self.name = name
# setup plugins
if plugin_manager is None:
self.plugins = self.plugin_manager()
else:
self.plugins = plugin_manager
# setup schema
if schema is not None:
self.schema = schema
# setup option parser
if parser is None:
parser = OptionParser()
parser.add_option('--validate', dest='validate', default=False,
action='store_true', help="validate configuration")
self.parser = parser
# setup config
self.config = Config(self)
|