Class k.e.Library(Environment):

Part of kiwi.environ

known subclasses: kiwi.environ.Application

A Library is a local environment object, it's a subclass of the Environment class. It's used by libraries and applications (through the Application class)

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.
Function__init__
Creates a new library, this is usually called in __init__.py in a
Function_check_translationUndocumented
Functionenable_translation
Enables translation for a library
Functionset_application_domain
Sets the default application domain
Functionadd_global_resource
Convenience method to add a global resource.
Functionadd_global_resourcesUndocumented
def __init__(self, name, root='..', dirname=None):
Creates a new library, this is usually called in __init__.py in a toplevel package. All resources will be relative to the root directory.
def _check_translation(self, domain, directory):
Undocumented
def enable_translation(self, domain=None, localedir=None):
Enables translation for a library
def set_application_domain(self, domain):
Sets the default application domain
def add_global_resource(self, resource, path):
Convenience method to add a global resource. This is the same as calling kiwi.environ.environ.add_resource
def add_global_resources(self, **kwargs):
Undocumented