Internal API

Configuration

press.config

press.config.configure(settings=None)[source]

Configure the pyramid.configure.Configurator object

See also

See also Configuration for environment variables, defaults and required settings.

press.logging.includeme(config)[source]

Configure logging for the application

See also

See also Logging for information on how to configure logging.

Tasks

Implementation of the Celery framework within a Pyramid application.

Use the task decorator provided by this module where the Celery documentation says to use @app.task. It is used to register a function as a task without making the celery application a global object.

class press.tasks.PyramidAwareTask[source]

A Pyramid aware version of celery.task.Task. This sets up the pyramid application within the thread, thus allowing pyramid.threadlocal functions to work as expected. Task execution also provides a :class:pyramid.request.Request as the first argument to each task. This allows for easy access to the component registry.

after_return(status, retval, task_id, args, kwargs, einfo)[source]

Handler called after the task returns.

Arguments:

status (str): Current task state. retval (Any): Task return value/exception. task_id (str): Unique id of the task. args (Tuple): Original arguments for the task. kwargs (Dict): Original keyword arguments for the task. einfo (~billiard.einfo.ExceptionInfo): Exception information.

Returns:

None: The return value of this handler is ignored.

press.tasks.task(**kwargs)[source]

A function task decorator used in place of @celery_app.task.

See also

See also Asynchronous Tasks for usage information and Celery Asynchronous Tasks for information on how to configure the queuing service.

Publishing

Events

class press.events.LegacyPublicationStarted(models, request)[source]

Happens when a legacy publication has started

Parameters
  • models (sequence) – a sequence of litezip models to be published

  • request (pyramid.request.Request) – the request object

class press.events.LegacyPublicationFinished(ids, request)[source]

Happens when a legacy publication has finished

Parameters
  • ids (sequence of tuples containing the module and a sequence of the major and minor version) – a pairing of moduleid and major & minor version

  • request (pyramid.request.Request) – the request object

press.publishing

press.publishing.discover_content_dir(dir)[source]

Given an expanded litezip directory path, discover the name of the contents directory within it.

Parameters

dir (pathlib.Path) – directory to look in for a unknown directory name

Returns

the found directory

Return type

pathlib.Path

press.publishing.expand_zip(file)[source]

Expand a zip file into a temporary directory and return the path to the expanded directory location.

Parameters

file (can be a path to a file (a string), a file-like object or a path-like object) – zip file to expand

Returns

path to expanded zip

Return type

pathlib.Path

press.publishing.get_var_location(registry=None)[source]

Lookup the var location for this application.

Parameters

registry (pyramid.registry.Registry) – the application registry

press.publishing.persist_file_to_filesystem(file)[source]

Persist the given file to the filesystem within the shared directory space.

Parameters

file (file-like object) – file to persist

Returns

path to written file

Return type

pathlib.Path

press.legacy_publishing

Parsers

press.parsers

press.parsers.common.make_cnx_xpath(elm_tree)[source]

Makes an xpath function that includes the CNX namespaces.

Parameters

elm_tree (an element-like object from lxml.etree) – the xml element to begin the xpath from

press.parsers.common.make_elm_tree(model)[source]

Makes an element-like object (lxml.etree) from a litezip model (litezip.Collection or litezip.Module).

press.parsers.common.parse_common_properties(elm_tree)[source]

Given an element-like object (lxml.etree) lookup the common and return the properties.

Parameters

elm_tree (an element-like object from lxml.etree) – the root xml element

Returns

common metadata properties

Return type

dict

Note

Press does not parse or update user information (aka “actor” in the xml). User modifications should be done using the “legacy” software.

class press.parsers.collection.CollectionXmlHandler(root)[source]
characters(content)[source]

Receive notification of character data.

The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity so that the Locator provides useful information.

endElementNS(name, qname)[source]

Signals the end of an element in namespace mode.

The name parameter contains the name of the element type, just as with the startElementNS event.

startElementNS(name, qname, attrs)[source]

Signals the start of an element in namespace mode.

The name parameter contains the name of the element type as a (uri, localname) tuple, the qname parameter the raw XML 1.0 name used in the source document, and the attrs parameter holds an instance of the Attributes class containing the attributes of the element.

The uri part of the name tuple is None for elements which have no namespace.

press.parsers.collection.parse_collection_metadata(model)[source]

Parse the metadata from the given object.

Parameters

model (litezip.Collection) – the object to parse

Returns

a metadata object

Return type

press.models.CollectionMetadata

press.parsers.collection.parse_collxml(input_collxml)[source]

Given a collxml document, parses the document to a python object where collections and sub-collections (both branching points) contain subcollections and modules (leaf nodes).

press.parsers.module.parse_module_metadata(model)[source]

Parse the metadata from the given object.

Parameters

model (litezip.Module) – the object to parse

Returns

a metadata object

Return type

press.models.ModuleMetadata

Runtime Functions

press.main.make_wsgi_app(config=None)[source]

WSGI application factory

Parameters

config (pyramid.configuration.Configurator) – optional configuration object

Data Models

press.models

class press.models.CollectionMetadata(id, version, created, revised, title, license_url, language, print_style, authors, maintainers, licensors, keywords, subjects, abstract)
property abstract

Alias for field number 13

property authors

Alias for field number 8

property created

Alias for field number 2

property id

Alias for field number 0

property keywords

Alias for field number 11

property language

Alias for field number 6

property license_url

Alias for field number 5

property licensors

Alias for field number 10

property maintainers

Alias for field number 9

property print_style

Alias for field number 7

property revised

Alias for field number 3

property subjects

Alias for field number 12

property title

Alias for field number 4

property version

Alias for field number 1

class press.models.ModuleMetadata(id, version, created, revised, title, license_url, language, authors, maintainers, licensors, keywords, subjects, abstract)
property abstract

Alias for field number 12

property authors

Alias for field number 7

property created

Alias for field number 2

property id

Alias for field number 0

property keywords

Alias for field number 10

property language

Alias for field number 6

property license_url

Alias for field number 5

property licensors

Alias for field number 9

property maintainers

Alias for field number 8

property revised

Alias for field number 3

property subjects

Alias for field number 11

property title

Alias for field number 4

property version

Alias for field number 1

class press.models.PressElement(tag, attrs=None, text='', tail='')[source]

Represents a collxml element parsed from a Collection XML file.

Tweens

See also

See also Error Reporting for information on how to configure Sentry’s Raven integration.