Utilities

Functionality without a better home is kept in pytiger.utils.

pytiger.utils.decorators – decorator functions

class pytiger.utils.decorators.cached_property(func, name=None)[source]

New in version 1.0.0.

Decorator that converts a method with a single self argument into a property cached on the instance.

Optional name argument allows you to make cached properties of other methods. (e.g. url = cached_property(get_absolute_url, name=’url’) )

pytiger.utils.filesystem – filesystem utilities

A collection of useful file system utilities

pytiger.utils.filesystem.get_file_age(filename)[source]

Returns age of file in seconds

Parameters:filename (str) – file to inspect

New in version 1.0.0.

pytiger.utils.filesystem.touch(filename, create_dirs=False, timestamp=None)[source]

Opens and closes filename, similarly to touch(1). If filename is a nested path and create_dirs is true, all intermediate directories will be created.

Parameters:
  • filename (str) – path to the file to touch
  • create_dirs (bool) – create all parent directories if necessary
  • timestamp (int) – UNIX timestamp for mtime and atime

New in version 1.0.0.

pytiger.utils.plugins – simple plugin loader

A simple plugin loading mechanism

pytiger.utils.plugins.load(plugin_dir, package='pytiger.utils.plugins')[source]

Load Python modules and packages from a directory.

This function will list the contents of plugin_dir and load any Python modules (files ending .py) or packages (directories with a __init__.py file) found within it. Sub-directories are not searched. Modules are compiled as they are loaded, if necessary.

Plugins are loaded within a package name as supplied to this function in the optional package parameter. If this is not provided, this defaults to pytiger.utils.plugins. The module name supplied in package must already be known to Python (i.e. in sys.modules).

The function returns a list of python module objects, one per loaded module or package.

Parameters:
  • plugin_dir (str) – The path to the directory to load plugins from.
  • package (str) – Python package to load the plugins into.

New in version 1.1.0.