MOS Collection

This part of the module provides a wrapper class MosCollection which stores references to specified MOS files, strings or S3 object keys so the MosFile objects can be recreated when needed rather than kept in memory.

Note

Note that creating a MosCollection from strings does not benefit from memory efficiency as the strings would still be held in memory.

The MosCollection is typically imported like so:

from mosromgr.moscollection import MosCollection

MOS collections are constructed using one of three classmethods. Either from a list of file paths:

mos_files = ['roCreate.mos.xml', 'roStorySend.mos.xml', 'roDelete.mos.xml']
mc = MosCollection.from_files(mos_files)

from a list of strings:

mos_strings = [roCreate, roStorySend, roDelete]
mc = MosCollection.from_strings(mos_files)

or from an S3 bucket:

mc = MosCollection.from_s3(bucket_name=bucket_name, prefix=prefix)

Note

Your AWS credentials must be configured to construct using the from_s3() classmethod. See https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html

MosCollection

class mosromgr.moscollection.MosCollection[source]

Wrapper for a collection of MOS files representing a partial or complete programme

__str__()[source]

The XML string of the collection’s running order

classmethod from_files(mos_file_paths: List[Union[Path, str]], *, allow_incomplete: bool = False)[source]

Construct from a list of MOS file paths

Parameters
  • mos_file_paths (list) – A list of paths to MOS files

  • allow_incomplete (bool) – If False (the default), the collection is permitted to be constructed without a roDelete. If True, a InvalidMosCollection will be raised if one is not present. (keyword-only argument)

classmethod from_s3(*, bucket_name: str, prefix: str, suffix: str = '.mos.xml', allow_incomplete: bool = False)[source]

Construct from a list of MOS files in an S3 bucket

Parameters
  • bucket_name (str) – The name of the S3 bucket (keyword-only argument)

  • prefix (str) – The prefix of the file keys in the S3 bucket (keyword-only argument)

  • suffix (str) – The suffix of the file keys in the S3 bucket (keyword-only argument). Defaults to ‘.mos.xml’.

  • allow_incomplete (bool) – If True, the collection is permitted to be constructed without a roDelete. If False (the default), a InvalidMosCollection will be raised if one is not present. (keyword-only argument)

classmethod from_strings(mos_file_strings: List[str], *, allow_incomplete: bool = False)[source]

Construct from a list of MOS document XML strings

Parameters
  • mos_file_strings (list) – A list of strings containing MOS file contents

  • allow_incomplete (bool) – If False (the default), the collection is permitted to be constructed without a roDelete. If True, a InvalidMosCollection will be raised if one is not present. (keyword-only argument)

merge(*, strict: bool = True)[source]

Merge all MOS files into the collection’s running order (ro). If strict is True (the default), then merge errors will be fatal. If False, then merge errors will be downgraded to warnings.

property completed: bool

Whether or not the running order has had a RunningOrderEnd merged (bool)

property mos_readers: List[MosReader]

A list of MosReader objects representing all MOS files in the collection, except the RunningOrder (roCreate) which is held in ro

property ro: RunningOrder

The collection’s RunningOrder object

property ro_id: str

The running order ID

property ro_slug: str

The running order slug

MosReader

The MosReader class is internal and is not intended to be constructed by the user. A MosCollection object will contain a list of MosReader instances, so users may find it useful to refer to its members.

class mosromgr.moscollection.MosReader[source]

Internal construct for opening and inspecting a MOS file for the purposes of classifying, sorting and validating a MosCollection. Provides the means to reconstruct the MosFile instance when needed in order to preserve memory usage.

property message_id: str

The message ID of the MOS file

property mos_object: MosFile

Restore the MOS object and return it

property mos_type: MosFile

The MosFile subclass this object was classified as (returns the class object, not an instance or a string)

property ro_id: str

The MOS file’s running order ID