Class Library
Environment
--+
|
Library
- Known Subclasses:
-
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.
Method Summary |
|
add_global_resource (self,
resource,
path)
Convenience method to add a global resource. |
|
add_global_resources(self,
**kwargs)
|
|
enable_translation (self,
domain,
localedir)
Enables translation for a library |
|
set_application_domain (self,
domain)
Sets the default application domain |
Inherited from Environment |
|
add_resource (self,
resource,
path)
|
|
add_resources (self,
**kwargs)
|
|
find_resource (self,
resource,
name)
Locate a specific resource of called name of type resource |
|
get_log_level (self)
|
|
get_resource_paths (self,
resource)
|
|
get_root (self)
|
Property Summary |
Inherited from Environment |
|
epydoc |
add_global_resource(self,
resource,
path)
Convenience method to add a global resource. This is the same as
calling kiwi.environ.environ.add_resource
-
|
enable_translation(self,
domain=None,
localedir=None)
Enables translation for a library
-
- 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.
|
set_application_domain(self,
domain)
Sets the default application domain
-
- Parameters:
domain -
the domain
|