Ejemplo n.º 1
0
    def __init__(self, name = '', path = ''):
        """
        Creates a new Settings instance which binds properties to
        gconf using GCONF_ROOT/path/prop_name.
        """
        self._name = name
        self._path = path

        if not name:
            self._name = self.settings_name

        if not path:
            self._path = self.settings_path

        config = Runtime.get_config()
        root = config.SETTINGS_ROOT + self._path

        # our gconf client
        self._client = gconf.client_get_default()
        rootdir = root.endswith('/') and root[:-1] or root
        self._client.add_dir(rootdir, gconf.CLIENT_PRELOAD_NONE)

        # lambda to retreive our attributes which are settings
        issetting = lambda a: isinstance(getattr(self, a), Setting)
        attrs = (a for a in dir(self) if issetting(a))

        for attr in list(attrs):
            attr = getattr(self, attr)
            attr.set_client(self._client, root)
Ejemplo n.º 2
0
def get_default_filename(self, suffix = ''):
    """
    Returns what the default template name would be for a particular
    class instance.
    """
    module = self.__class__.__module__.lower()
    if module == '__main__':
        module = ''
    else:
        # trim off the app module
        module = '.'.join(module.split('.')[1:])
    klass = self.__class__.__name__.lower()
    config = Runtime.get_config()
    if hasattr(config, 'VIEW_PATH'):
        viewpath = config.VIEW_PATH
    else:
        viewpath = 'data'
    return os.path.join(viewpath,
                        module.replace('.', os.path.sep),
                        klass) + suffix