tts_tower
Subpackages
Submodules
tts_tower.exceptions
- exception tts_tower.exceptions.CheckerStepFailure
Bases:
TowerExceptionException raised when a specific step within a Checker fails.
This indicates that a discrete logical step within a checker could not be completed, typically due to missing data or calculation errors, without necessarily crashing the entire application.
- exception tts_tower.exceptions.TowerException
Bases:
ExceptionBase exception class for all Tower-related errors.
All custom exceptions in the Tower library should inherit from this class to allow for coarse-grained error handling of library-specific issues.
tts_tower.rule_results
- class tts_tower.rule_results.RULE_REVISION_SPECIAL(*values)
Bases:
AccessEnumSpecial values for overriding TOWER’s default rule revision behavior If a RuleResults has one of these values for its “revision” attribute, special handling (or no handling) is applied
- IGNORE_REVISION = 2
- USER_RULE = 1
- class tts_tower.rule_results.RuleCmdDisposition(message, rule_status_enum, status=None, flag=None, target=None)
Bases:
RuleDispositionDisposition specific to Command objects. Overrides context retrieval to use repr_context() of the command.
- DISPO_TYPE = 'CMD'
- get_target_context()
Extracts context from a Command object.
- Returns:
The string representation of the command’s context.
- Return type:
str
- class tts_tower.rule_results.RuleDisposition(message, rule_status_enum, status=None, flag=None, target=None)
Bases:
objectContainer class for any disposition, with space for a message, status, type flag, and related object.
This class serves as the atomic unit of feedback for a rule check, capturing what happened, the resulting status, and context about the object involved.
- Parameters:
message (str) – Primary information-containing message for the disposition.
rule_status_enum (EnumType) – The Enum class defining valid rule statuses (e.g., RULE_STATUS).
status (str or IntEnum, optional) – Rule status to be applied by this disposition. If None, the disposition is informational only.
flag (int or str, optional) – A special identifier used by testing suites to differentiate specific dispositions programmatically.
target (any, optional) – A target object relevant to this disposition (e.g., a Command, Sequence, or File object).
- DISPO_TYPE = 'GENERIC'
- property context
Retrieves the string representation of the target object context, if a target exists.
- Returns:
String context or None.
- Return type:
str or None
- get_target_context()
Helper method to extract context string from the target. Intended to be overridden by specific disposition types.
- Returns:
String representation of target.
- Return type:
str
- property text
The full text representation of the disposition, combining context (if present) and message.
- Returns:
Formatted disposition text.
- Return type:
str
- class tts_tower.rule_results.RuleFileDisposition(message, rule_status_enum, status=None, flag=None, target=None)
Bases:
RuleDispositionDisposition specific to File objects. Overrides context retrieval to use the file onboard_name.
- DISPO_TYPE = 'FILE_LOAD'
- get_target_context()
Extracts context from a File object.
- Returns:
The onboard name of the file.
- Return type:
str
- class tts_tower.rule_results.RuleResults(rule_id, revision, user_title=None)
Bases:
objectPrimary storage and tracking class for Flight Rules.
Keeps track of the Status (i.e. PASSED, VIOLATING, etc.) and all dispositions/errors generated while checking a particular Flight Rule.
- Parameters:
rule_id (str) – Flight rule ID (e.g., “AVS-0002”, “SYS-A-0010”).
revision (int or RULE_REVISION_SPECIAL) – FR Source revision number. If this doesn’t match the latest Approved revision for a rule, dispositions will be rejected unless individually accepted by the user. RULE_REVISION_SPECIAL enumerations provide some special parsing.
user_title (str, optional) – An optional human-readable title for the rule to override the dictionary default.
- add_cmd_dispo(cmd, message)
Add a disposition, automatically adding context about a specific FSW Command.
- Parameters:
cmd (Command) – The Command object related to the message.
message (str) – The text content of the disposition.
- add_cmd_status_dispo(cmd, status, message, flag=None)
Add a disposition w/ Cmd context and set the rule Status. Also adds an entry for test checking.
- Parameters:
cmd (Command) – The Command object related to the message.
status (str or Enum) – The status to associate with this disposition.
message (str) – The text content of the disposition.
flag (int or str, optional) – Optional flag identifier for testing.
- add_dispo(message)
Simply adds a generic disposition to this rule’s running list without changing status.
- Parameters:
message (str) – The text content of the disposition.
- add_file_dispo(file_load, message)
Add a disposition, automatically adding context about a specific File Load.
- Parameters:
file_load (File) – The File object related to the message.
message (str) – The text content of the disposition.
- add_file_status_dispo(file_load, status, message, flag=None)
Add a disposition w/ File context and set the rule Status. Also adds an entry for test checking.
- Parameters:
file_load (File) – The File object related to the message.
status (str or Enum) – The status to associate with this disposition.
message (str) – The text content of the disposition.
flag (int or str, optional) – Optional flag identifier for testing.
- add_report(report_name, components, weight=0, section_class=None, append=False)
Attaches report components to this rule result, to be displayed in the generated HTML report.
- Parameters:
report_name (str) – Name of the report section (e.g., “Execution”).
components (list or object) – List of (or single) Report Components (e.g., Plot, Table). See tts-html-utils.
weight (int, optional) – Sorting weight for the report tab (lower numbers appear first). Defaults to 0.
section_class (type, optional) – Custom TowerSection class to use for rendering. deprecated
append (bool, optional) – If True, appends components to an existing report name instead of warning about duplicates.
- add_seq_dispo(seq, message)
Add a disposition, automatically adding context about a specific Sequence.
- Parameters:
seq (Sequence) – The Sequence object related to the message.
message (str) – The text content of the disposition.
- add_seq_status_dispo(seq, status, message, flag=None)
Add a disposition w/ Seq context and set the rule Status. Also adds an entry for test checking.
- Parameters:
seq (Sequence) – The Sequence object related to the message.
status (str or Enum) – The status to associate with this disposition.
message (str) – The text content of the disposition.
flag (int or str, optional) – Optional flag identifier for testing.
- add_status_dispo(status, message)
Adds a generic disposition and attempts to update the rule status.
- Parameters:
status (str or Enum) – The status to associate with this disposition (e.g., ‘PASSED’, ‘VIOLATING’).
message (str) – The text content of the disposition.
- property dispositions
List of all dispositions associated with this rule.
- Returns:
List of RuleDisposition objects.
- Return type:
list[RuleDisposition]
- get_all_dispos()
Returns a shallow copy of all dispositions.
- Returns:
Copy of the dispositions list.
- Return type:
list[RuleDisposition]
- get_cmd_dispos()
Returns a list of all Command-type dispositions.
- Returns:
List of RuleCmdDisposition objects.
- Return type:
list[RuleCmdDisposition]
- get_file_dispos()
Returns a list of all File-type dispositions.
- Returns:
List of RuleFileDisposition objects.
- Return type:
list[RuleFileDisposition]
- get_reports()
Returns the dictionary of attached reports.
- Returns:
Dictionary mapping report names to component/metadata tuples.
- Return type:
dict
- get_seq_dispos()
Returns a list of all Sequence-type dispositions.
- Returns:
List of RuleSeqDisposition objects.
- Return type:
list[RuleSeqDisposition]
- is_pending()
Checks if the rule status is currently PENDING.
- Returns:
True if status is PENDING, False otherwise.
- Return type:
bool
- merge(other_results)
Merge another RuleResult for the same Flight Rule into this one. Picks the “highest” status of the 2, but merges all dispositions into one big list.
- Parameters:
other_results (RuleResults) – The other RuleResults object to merge into this one.
- Raises:
ValueError – If the Rule IDs or Revisions do not match (and are not ignored).
- set_status(new_status)
Set a new status for this rule. If the new status is ‘lower’ priority than an existing status, nothing happens. (e.g., ERROR overwrites PASSED, but PASSED does not overwrite ERROR).
- Parameters:
new_status (RULE_STATUS or str) – New status to attempt to set the rule to.
- Raises:
TypeError – If the new_status is not a valid Enum or string.
- property status
The current aggregate status of the rule.
- Returns:
The current status enum member.
- Return type:
Enum member
- to_fr_source_dict()
Converts the rule result into a dictionary compatible with the Flight Rule Source schema.
- Returns:
Dictionary with keys ‘status’, ‘disposition’, and ‘rule_id’.
- Return type:
dict
- class tts_tower.rule_results.RuleSeqDisposition(message, rule_status_enum, status=None, flag=None, target=None)
Bases:
RuleDispositionDisposition specific to Sequence objects. Overrides context retrieval to use the sequence name.
- DISPO_TYPE = 'SEQ'
- get_target_context()
Extracts context from a Sequence object.
- Returns:
The name of the sequence.
- Return type:
str
- tts_tower.rule_results.consolidate_rule_reports(rule_results, source_rules)
Aggregates individual reports attached to RuleResults into TowerSection objects.
If multiple rules contribute to the same report name (e.g. “Power”), they are grouped together into a single Section.
- Parameters:
rule_results (list[RuleResults]) – List of RuleResult objects.
source_rules (dict) – The Rule Dictionary containing definitions for the rules.
- Returns:
List of TowerSection objects ready for rendering.
- Return type:
list[TowerSection]
- tts_tower.rule_results.consolidate_rule_results(all_rule_results)
Groups a flat list of RuleResults by ID and consolidates them.
If multiple results exist for the same Rule ID: 1. It identifies the highest revision number used. 2. It filters out any results with older revisions (logging a warning). 3. It merges all remaining results into a single RuleResults object.
- Parameters:
all_rule_results (list[RuleResults]) – List of RuleResults objects from various checkers.
- Returns:
A list of unique, consolidated RuleResults objects.
- Return type:
list[RuleResults]
- tts_tower.rule_results.rules_to_json(rule_results, outfile=None)
Serializes rule results to a JSON string and optionally writes to a file.
- Parameters:
rule_results (list[RuleResults]) – List of RuleResult objects.
outfile (str, optional) – Optional path to write the JSON output. If None, only returns string.
- Returns:
JSON string representation of the results.
- Return type:
str
- tts_tower.rule_results.rules_to_xml(rule_results, outfile=None)
Serializes rule results to an XML string and optionally writes to a file.
- Parameters:
rule_results (list[RuleResults]) – List of RuleResult objects.
outfile (str, optional) – Optional path to write the XML output. If None, only returns string.
- Returns:
Pretty-printed XML string representation of the results.
- Return type:
str
- tts_tower.rule_results.verify_rule_revisions(rule_results, fr_source_rules, revision_passthrough_list=None)
Verifies that the revision of the verified rules matches the latest revision in the source dictionary.
- Parameters:
rule_results (list[RuleResults]) – List of consolidated RuleResults objects.
fr_source_rules (dict) – The Rule Dictionary containing official rule definitions.
revision_passthrough_list (list[str], optional) – List of Rule IDs to ignore version mismatches for. Defaults to None.
- Returns:
Three lists: verified_rr (passed), nonmatching_rr (ID not found), bad_version_rr (version mismatch).
- Return type:
tuple[list, list, list]
tts_tower.split_logging
- class tts_tower.split_logging.ColorFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)
Bases:
FormatterCustom logging formatter that injects ANSI color codes based on log severity.
This formatter is primarily intended for console/stdout usage to improve readability of logs during development.
- FORMATS = {10: '\x1b[0m', 20: '\x1b[0m', 30: '\x1b[38;5;214m', 40: '\x1b[38;5;160m', 50: '\x1b[38;5;160m'}
- format(record)
Formats the log record, prepending color codes to the level name and line number.
- Parameters:
record (logging.LogRecord) – The log record to format.
- Returns:
The formatted log string.
- Return type:
str
- tts_tower.split_logging.clear_handlers_by_type(handler_type)
Removes all handlers of a specific type from the root logger.
- Parameters:
handler_type (Type[logging.Handler]) – The class of handler to remove (e.g.,
logging.FileHandler).
- tts_tower.split_logging.create_logger(name)
Factory function to retrieve a logger instance.
This is the standard entry point for modules to get their logger. It ensures that loggers are correctly associated with the application’s logging hierarchy.
- Parameters:
name (str) – The name of the logger (typically
__name__).- Returns:
A logger instance configured for the application.
- Return type:
logging.Logger
- tts_tower.split_logging.handle_exception(exc_type, exc_value, tb)
- tts_tower.split_logging.log_to_file(logfile, clear_previous_files=True, tmpdir_fallback=True)
Configures the logger to output to a specified file.
This function adds a FileHandler to the root logger. It attempts to write to the requested path, but can fallback to the system temporary directory if the requested path is not writable.
- Parameters:
logfile (str | pathlib.Path) – The desired path for the log file.
clear_previous_files (bool, optional) – If True, removes existing FileHandlers before adding the new one.
tmpdir_fallback (bool, optional) – If True, falls back to the system temp directory if
logfileis unwritable.
- Raises:
Exception – If
logfileis not a string or Path object.PermissionError – If the file cannot be written and fallback is disabled.
- tts_tower.split_logging.stdout_simple_format()
Reconfigures the stdout stream handler to use the simplified formatter.
This is useful for unit tests or CLI output where timestamps and module paths add too much noise.
tts_tower.tower
tts_tower.util
- class tts_tower.util.AccessEnum(new_class_name, /, names, *, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
EnumAn enhanced Enum class that provides a flexible lookup method.
This class adds a
getmethod to retrieving enum members by instance, value, or name (string). This is useful when processing inputs that might be the Enum object itself, its database value, or its string representation.- classmethod get(x, strict=True)
Retrieves an enum member by instance, value, or name.
- Parameters:
x (Any) – The key to look up. Can be an instance of the enum, a valid value, or a string name.
strict (bool, optional) – If True, raises a KeyError on failure. If False, returns None (implicit).
- Returns:
The matching Enum member.
- Return type:
- Raises:
KeyError – If
strictis True and no matching member is found.
- tts_tower.util.as_list(x)
Coerces a given input into a list.
Lists remain lists.
Strings and Dicts are wrapped in a single-element list (to prevent character/key iteration).
Iterables (other than str/dict) are converted to lists.
Scalars are wrapped in a single-element list.
- Parameters:
x (Any) – The input to coerce.
- Returns:
A list containing the input elements.
- Return type:
list
- tts_tower.util.reverse_dict_order(d)
Returns a new dictionary with the keys in reverse insertion order.
- Parameters:
d (dict) – The source dictionary.
- Returns:
A new dictionary with keys reversed.
- Return type:
dict
- tts_tower.util.reverse_prio_dict_merge(d1, d2)
Merges two dictionaries while prioritizing the order of keys from the first dictionary.
This is often used to ensure specific keys appear at the top of a dictionary (e.g., for report ordering) by reversing, merging, and reversing back.
- Parameters:
d1 (dict) – The dictionary whose key order takes priority (usually defaults/header info).
d2 (dict) – The dictionary containing additional data.
- Returns:
A merged dictionary with
d1keys appearing first.- Return type:
dict