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
- 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 aroDelete
. IfTrue
, aInvalidMosCollection
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 aroDelete
. IfFalse
(the default), aInvalidMosCollection
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 aroDelete
. IfTrue
, aInvalidMosCollection
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 isTrue
(the default), then merge errors will be fatal. IfFalse
, 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 theRunningOrder
(roCreate
) which is held inro
- property ro: RunningOrder
The collection’s
RunningOrder
object
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 theMosFile
instance when needed in order to preserve memory usage.