everest.resources.io

Input/Output operations on resources.

class everest.resources.io.ConnectedResourcesSerializer(content_type, dependency_graph=None)[source]

Bases: object

Serializer for a graph of connected resources.

__init__(content_type, dependency_graph=None)[source]
Parameters:
  • content_type (object implementing everest.interfaces.IMime.) – MIME content type to use for representations
  • dependency_graph – graph determining which resource connections to follow when the graph of connected resources for a given resource is built.
__weakref__

list of weak references to the object (if defined)

to_files(resource, directory)[source]

Dumps the given resource and all resources linked to it into a set of representation files in the given directory.

to_strings(resource)[source]

Dumps the all resources reachable from the given resource to a map of string representations using the specified content_type (defaults to CSV).

Returns:dictionary mapping resource member classes to string representations
to_zipfile(resource, zipfile)[source]

Dumps the given resource and all resources linked to it into the given ZIP file.

class everest.resources.io.ResourceGraph[source]

Bases: pygraph.classes.digraph.digraph

Specialized digraph for resource instances.

Nodes are resources, edges represent relationships between resources. Since resources are wrapper objects generated on the fly, the presence of a resource in the graph is determined by its underlying entity, using the entity class and its ID as a key.

everest.resources.io.build_resource_dependency_graph(resource_classes, include_backrefs=False)[source]

Builds a graph of dependencies among the given resource classes.

The dependency graph is a directed graph with member resource classes as nodes. An edge between two nodes represents a member or collection attribute.

Parameters:
  • resource_classes (sequence of registered resources.) – resource classes to determine interdependencies of.
  • include_backrefs (bool) – flag indicating if dependencies introduced by back-references (e.g., a child resource referencing its parent) should be included in the dependency graph.
everest.resources.io.build_resource_graph(resource, dependency_graph=None)[source]

Traverses the graph of resources that is reachable from the given resource.

If a resource dependency graph is given, links to other resources are only followed if the dependency graph has an edge connecting the two corresponding resource classes; otherwise, a default graph is built which ignores all direct cyclic resource references.

Resource :a thelma.resources.MemberResource instance.
Returns:a ResourceGraph instance representing the graph of resources reachable from the given resource.
everest.resources.io.dump_resource(resource, stream, content_type=None)[source]

Dumps the given resource to the given stream using the specified MIME content type (defaults to CSV).

everest.resources.io.dump_resource_to_files(resource, content_type=None, directory=None)[source]

Convenience function. See thelma.resources.io.ConnectedResourcesSerializer.to_files() for details.

If no directory is given, the current working directory is used. The given context type defaults to CSV.

everest.resources.io.dump_resource_to_zipfile(resource, zipfile, content_type=None)[source]

Convenience function. See thelma.resources.io.ConnectedResourcesSerializer.to_zipfile() for details.

The given context type defaults to CSV.

everest.resources.io.find_connected_resources(resource, dependency_graph=None)[source]

Collects all resources connected to the given resource and returns a dictionary mapping member resource classes to new collections containing the members found.

everest.resources.io.load_collection_from_file(collection, filename, content_type=None, resolve_urls=True)[source]

Loads resources from the specified file into the given collection resource.

If no content type is provided, an attempt is made to look up the extension of the given filename in the MIME content type registry.

everest.resources.io.load_collection_from_stream(collection, stream, content_type, resolve_urls=True)[source]

Loads resources from the given stream into the given collection resource.

everest.resources.io.load_collection_from_url(collection, url, content_type=None, resolve_urls=True)[source]

Loads a collection resource of the given registered resource type from a representation contained in the given URL.

Returns:collection resource
everest.resources.io.load_collections_from_zipfile(collections, zipfile, resolve_urls=True)[source]

Loads resources contained in the given ZIP archive into each of the given collections.

The ZIP file is expected to contain a list of file names obtained with the get_collection_filename() function, each pointing to a file of zipped collection resource data.

Parameters:
  • collections – sequence of collection resources
  • zipfile (str) – ZIP file name
  • resolve_urls (bool) – Flag indicating if URLs should be resolved during loading.

Project Versions

Previous topic

everest.resources.interfaces

Next topic

everest.resources.kinds

This Page