Executors

module: rspub.core.executors

Events and base classes for execution

class rspub.core.executors.ExecutorEvent[source]

Bases: enum.Enum

Events fired by Executors

There are information events (inform) and confirmation events (confirm). If an Observer overrides the method confirm() and returns False on a confirm event, an ObserverInterruptException is raised.

All events are broadcast in the format:

[inform][confirm](source, event, **kwargs)

where source is the calling instance, event is the relevant event and **kwargs hold relevant information about the event.

rejected_file = 1

1 inform File rejected by resource gate

2 inform File search was started

created_resource = 3

3 inform The metadata for a resource was created

completed_document = 10

10 inform A sitemap document was completed

found_changes = 20

20 inform Resources that changed were found

execution_start = 30

30 inform Execution of resource synchronization started

execution_end = 31

31 inform Execution of resource synchronization did end

clear_metadata_directory = 100

100 confirm Files in metadata directory will be erased

class rspub.core.executors.SitemapData(resource_count=0, ordinal=0, uri=None, path=None, capability_name=None, document_saved=False)[source]

Bases: object

Holds metadata about sitemaps

__init__(resource_count=0, ordinal=0, uri=None, path=None, capability_name=None, document_saved=False)[source]

Initialization

Parameters:
  • resource_count (int) – the amount of records in the sitemap
  • ordinal (int) – the ordinal number as reflected in the sitemap filename and url
  • uri (str) – the url of the sitemap
  • path (str) – the local path of the sitemap
  • capability_name (str) – the capability of the sitemap
  • document_saved (bool) – True if the sitemap was saved to disk, False otherwise
class rspub.core.executors.Executor(rs_parameters: rspub.core.rs_paras.RsParameters = None)[source]

Bases: rspub.util.observe.Observable

Abstract base class for ResourceSync execution

There are 6 build steps that concrete subclasses may override (or 7 if they want to completely take over the execution). Two steps are mandatory for subclasses to implement: generate_rs_documents() and create_index(). Steps create_capabilitylist() and update_resource_sync() are not abstract - they can safely be done by this Executor.

__init__(rs_parameters: rspub.core.rs_paras.RsParameters = None)[source]

Initialization

If no RsParameters were given will construct new RsParameters from configuration found under current_configuration_name().

Parameters:rs_parametersRsParameters for execution
resource_gate()[source]

Construct or return the resource gate

Returns:resource gate
execute(filenames: <built-in function iter>)[source]

build step 0 Publish ResourceSync documents

Publish ResourceSync documents under conditions of current RsParameters.

Parameters:filenames – iter of filenames and/or directories to scan
Returns:list of SitemapData of generated sitemaps
prepare_metadata_dir()[source]

build step 1 Does nothing

Subclasses that want to prepare metadata directory before generating new documents may override.

generate_rs_documents(filenames: <built-in function iter>) → [<class 'rspub.core.executors.SitemapData'>][source]

build step 2 Raises NotImplementedError

Subclasses must walk resources found in filenames and, if appropriate, generate sitemaps and produce sitemap data.

Parameters:filenames – list of filenames and/or directories to scan
Returns:list of SitemapData of generated sitemaps
post_process_documents(sitemap_data_iter: <built-in function iter>)[source]

build step 3 Does nothing

Subclasses that want to post proces the documents in metadata directory may override.

Parameters:sitemap_data_iter – iter over SitemapData of sitemaps generated in build step 2
create_index(sitemap_data_iter: <built-in function iter>)[source]

build step 4 Raises NotImplementedError

Subclasses must create sitemap indexes if appropriate.

Parameters:sitemap_data_iter – iter over SitemapData of sitemaps generated in build step 2
create_capabilitylist() → rspub.core.executors.SitemapData[source]

build step 5 Create a new capabilitylist over sitemaps found in metadata directory

Returns:SitemapData over the newly created capabilitylist
update_resource_sync(capabilitylist_data)[source]

build step 6 Update description with newly created capabilitylist

Parameters:capabilitylist_dataSitemapData over the newly created capabilitylist
Returns:SitemapData over updated description
clear_metadata_dir()[source]
resource_generator() → <built-in function iter>[source]
walk_directories(*directories) → [<class 'str'>][source]
find_ordinal(capability)[source]
format_ordinal(ordinal)[source]
finish_sitemap(ordinal, sitemap, doc_start=None, doc_end=None) → rspub.core.executors.SitemapData[source]
current_rel_up_for(sitemap)[source]
update_rel_index(index_url, path, sitemap_instance)[source]
save_sitemap(sitemap, path)[source]
read_sitemap(path, sitemap_instance)[source]