Part of kiwi.environ View In Hierarchy
Known subclasses: kiwi.environ.Application
It provides a way to manage local resources, which should only be seen in the current context.
Libraries are usually instantiated in __init__.py in the topmost package in your library, an example usage is kiwi itself which does:
>>> from kiwi.environ import Library >>> lib = Library('kiwi') >>> if lib.uninstalled: >>> lib.add_global_resource('glade', 'glade') >>> lib.add_global_resource('pixmap', 'pixmaps')
which is combined with the following class in setup.py:
>>> from kiwi.dist import InstallLib >>> class InstallLib(TemplateInstallLib): >>> name = 'kiwi' >>> global_resources = dict(glade='$datadir/glade', >>> pixmap='$datadir/pixmaps') >>> >>> setup(..., >>> data_files=[('share/kiwi/glade', >>> listfiles('glade', '*.glade')), >>> ('share/kiwi/pixmaps', >>> listfiles('pixmaps', '*.png')), >>> cmdclass=dict(install_lib=InstallLib))
It may seems like a bit of work, but this is everything that's needed for kiwi to figure out how to load resources when installed and when running in an uninstalled mode, eg directly from the source tree. To locate a pixmap called kiwi.png the following is enough:
>>> from kiwi.environ import environ >>> environ.find_resource('pixmap', 'kiwi.png') '/usr/share/kiwi/pixmaps/kiwi.png' # installed mode
Which will lookup the resource kiwi.png in the domain pixmap, which points to $datadir/pixmaps (eg $prefix/share/kiwi/pixmaps) when running in installed mode and from $builddir/pixmaps otherwise.
Method | __init__ | Creates a new library, this is usually called in __init__.py in a |
Method | enable_translation | Enables translation for a library |
Method | set_application_domain | Sets the default application domain |
Method | add_global_resource | Convenience method to add a global resource. |
Method | add_global_resources | Undocumented |
Method | _check_translation | Undocumented |
Inherited from Environment:
Method | get_root | Undocumented |
Method | get_log_level | Undocumented |
Method | get_resource_paths | Undocumented |
Method | add_resource | Undocumented |
Method | add_resources | Undocumented |
Method | find_resource | Locate a specific resource of called name of type resource |
Method | _add_extensions | Undocumented |
Method | _add_resource_variable | Add resources from an environment variable |
Method | _get_epydoc | Undocumented |
Parameters | name | name of the library |
root | root directory | |
dirname |
Parameters | domain | optional, if not specified name sent to constructor will be used |
localedir | directory to get locales from when running in uninstalled mode. If not specified a directory called 'locale' in the root will be used. |
Parameters | domain | the domain |