Previous topic

Parameters

Next topic

The soclib builder module

This Page

Metadata providers

Entry point of metadata providers is a class inheriting from soclib_desc.metadata_file.MetadataFile. This class will be instanciated once per found metadata file, and must return modules when asked for.

class soclib_desc.metadata_file.MetadataFile(path)

The API to implement to create a new metadata provider is “extensions” and “get_modules”:

See .sd file format for an example of such class.

extensions

A class attribute containing a list of handled extensions.

get_modules()

This parses and retrives all modules defined in the file.

Returns:a list of modules defined in the handled file.

Here is complete API for this class, for reference. These methods are already implemented, no need to define them in metadata providers.

__init__(path)

Create a new parser for the given file path.

Parameters:path – path to a file
path

The full path of file.

Handling of contained data:

doForModules(callback)

Calls the given callback for each module

Information about pertinence of data:

isOutdated()

Returns whether the in-memory cache of this file is outdated. This is based of file modification time.

Returns:Whether memory cache is stale

Loading of data:

rehashIfNecessary()

This may rehash the cached file, if necessary (modification).

rehash()

Unconditionnaly reloads a description.

cleanup()

Call cleanup() for each module in this file.

Here are the class methods of soclib_desc.metadata_file.MetadataFile. They are able to find the correct subclass of soclib_desc.metadata_file.MetadataFile able to handle a given file.

classmethod init_parsers(parsers)

Gets all the parser classes and append them to medata providers.

Parameters:parsers – a list of strings containing names of Python subclasses of this one.
classmethod handle(filename)

Try to find the metadata provider matching the given filename, if found, initialize it. If not found, raise a ValueError exception.

Parameters:filename – file to handle
Returns:a soclib_desc.metadata_file.MetadataFile subclass object
Raises :ValueError if file is unhandled
classmethod filename_regexp()

Retrieves a regexp matching filenames of all currently handled files.

Returns:a Python re object