class documentation

class ResourceManager(object):

View In Hierarchy

This class manages a list of search paths and helps to find and open application-bound resources (files).
Parameters
basedefault value for add_path calls.
openercallable used to open resources.
cachemodecontrols which lookups are cached. One of 'all', 'found' or 'none'.
Method add​_path Add a new path to the list of search paths. Return False if the path does not exist.
Method lookup Search for a resource and return an absolute file path, or None.
Method open Find a resource and return a file object, or raise IOError.
Instance Variable cache Undocumented
Instance Variable path Undocumented
Method __init__ Undocumented
Method __iter__ Iterate over all existing files in all registered paths.
Instance Variable base Undocumented
Instance Variable cachemode Undocumented
Instance Variable opener Undocumented
def add_path(self, path, base=None, index=None, create=False):

Add a new path to the list of search paths. Return False if the path does not exist.

The base parameter makes it easy to reference files installed along with a python module or package:

res.add_path('./resources/', __file__)
Parameters
pathThe new search path. Relative paths are turned into an absolute and normalized form. If the path looks like a file (not ending in /), the filename is stripped off.
basePath used to absolutize relative search paths. Defaults to base which defaults to os.getcwd().
indexPosition within the list of search paths. Defaults to last index (appends to the list).
createUndocumented
def lookup(self, name):

Search for a resource and return an absolute file path, or None.

The path list is searched in order. The first match is returend. Symlinks are followed. The result is cached to speed up future lookups.

def open(self, name, mode='r', *args, **kwargs):
Find a resource and return a file object, or raise IOError.
cache: dict =

Undocumented

path: list =

Undocumented

def __init__(self, base='./', opener=open, cachemode='all'):

Undocumented

def __iter__(self):
Iterate over all existing files in all registered paths.
base =

Undocumented

cachemode =

Undocumented

opener =

Undocumented