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
nameargument 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_dirand load any Python modules (files ending.py) or packages (directories with a__init__.pyfile) 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
packageparameter. If this is not provided, this defaults topytiger.utils.plugins. The module name supplied inpackagemust already be known to Python (i.e. insys.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.