loader

DataLoader.loader

File handler to support different file extensions. Uses reflectometry’s registry utility.

The default readers are found in the ‘readers’ sub-module and registered by default at initialization time.

To add a new default reader, one must register it in the register_readers method found in readers/__init__.py.

A utility method (find_plugins) is available to inspect a directory (for instance, a user plug-in directory) and look for new readers/writers.

class DataLoader.loader.Loader

Bases: object

Utility class to use the Registry as a singleton.

associate_file_reader(ext, loader)

Append a reader object to readers

Parameters:
  • ext – file extension [string]
  • module – reader object
associate_file_type(ext, module)

Look into a module to find whether it contains a Reader class. If so, append it to readers and (potentially) to the list of writers for the given extension

Parameters:
  • ext – file extension [string]
  • module – module object
find_plugins(dir)

Find plugins in a given directory

Parameters:dir – directory to look into to find new readers/writers
get_wildcards()
load(file, format=None)

Load a file

Parameters:
  • file – file name (path)
  • format – specified format to use (optional)
Returns:

DataInfo object

save(file, data, format)

Save a DataInfo object to file :param file: file name (path) :param data: DataInfo object :param format: format to write the data in

class DataLoader.loader.Registry

Bases: data_util.registry.ExtensionRegistry

Registry class for file format extensions. Readers and writers are supported.

associate_file_reader(ext, loader)

Append a reader object to readers

Parameters:
  • ext – file extension [string]
  • module – reader object
associate_file_type(ext, module)

Look into a module to find whether it contains a Reader class. If so, APPEND it to readers and (potentially) to the list of writers for the given extension

Parameters:
  • ext – file extension [string]
  • module – module object
extensions()

Return a sorted list of registered extensions.

find_plugins(dir)

Find readers in a given directory. This method can be used to inspect user plug-in directories to find new readers/writers.

Parameters:dir – directory to search into
Returns:number of readers found
formats()

Return a sorted list of the registered formats.

load(path, format=None)

Call the loader for the file type of path.

Parameters:
  • path – file path
  • format – explicit extension, to force the use of a particular reader

Defaults to the ascii (multi-column) reader if no reader was registered for the file’s extension.

lookup(path)

Return the loader associated with the file type of path.

Raises ValueError if file type is not known.

lookup_writers(path)
Returns:the loader associated with the file type of path.
Raises ValueError:
 if file type is not known.
save(path, data, format=None)

Call the writer for the file type of path.

Raises ValueError if no writer is available. Raises KeyError if format is not available.

May raise a writer-defined exception if writer fails.

Table Of Contents

Previous topic

data_info

Next topic

manipulations

This Page