Skip to content

Commit

Permalink
Merge pull request Ymagis#237 from remia/improve-check-error
Browse files Browse the repository at this point in the history
Improve check diagnostic message and lower naming convention error level
  • Loading branch information
remia authored Jan 28, 2024
2 parents 9ffb875 + d327f4a commit fd47ccd
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 16 deletions.
2 changes: 1 addition & 1 deletion clairmeta/dcp_check_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __init__(self, func):

def short_desc(self):
"""Returns first line of the docstring or function name."""
docstring_lines = self.doc.split("\n")
docstring_lines = self.doc.split("\n") if self.doc else ""
return docstring_lines[0].strip() if docstring_lines else self.name

def is_valid(self, criticality="ERROR"):
Expand Down
19 changes: 11 additions & 8 deletions clairmeta/dcp_check_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from clairmeta.dcp_utils import list_cpl_assets, cpl_probe_asset
from clairmeta.dcp_check import CheckerBase
from clairmeta.utils.sys import all_keys_in_dict


class Checker(CheckerBase):
Expand Down Expand Up @@ -99,25 +98,29 @@ def setup_dcp_link_ov(self):
)

def check_dcp_signed(self):
"""DCP with encrypted content must be digitally signed.
"""Encrypted DCP must be digitally signed (XMLs include Signer and Signature).
References:
DCI DCSS (v1.3) 5.4.3.7
DCI DCSS (v1.3) 5.5.2.3
"""
for cpl in self.dcp._list_cpl:
cpl_name = cpl["FileName"]
cpl_node = cpl["Info"]["CompositionPlaylist"]
if not cpl_node["Encrypted"]:
continue

xmls = [
pkl["Info"]["PackingList"]
(pkl["FileName"], pkl["Info"]["PackingList"])
for pkl in self.dcp._list_pkl
if pkl["Info"]["PackingList"]["Id"] == cpl_node.get("PKLId")
]
xmls.append(cpl_node)
xmls.append((cpl_name, cpl_node))

for xml in xmls:
signed = all_keys_in_dict(xml, ["Signer", "Signature"])
if not signed and cpl_node["Encrypted"] is True:
self.error("Encrypted DCP must be signed")
for name, xml in xmls:
for field in ["Signer", "Signature"]:
if field not in xml.keys():
self.error("Missing {} element in {}".format(field, name))

def check_link_ov_coherence(self):
"""Relink OV/VF sanity checks.
Expand Down
2 changes: 1 addition & 1 deletion clairmeta/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# 4 levels : ERROR, WARNING, INFO and SILENT.
"criticality": {
"default": "ERROR",
"check_dcnc_": "WARNING",
"check_dcnc_": "INFO",
"check_dcp_foreign_files": "WARNING",
"check_assets_am_volindex_one": "WARNING",
"check_*_empty_text_fields": "WARNING",
Expand Down
18 changes: 13 additions & 5 deletions clairmeta/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@
class CheckReport(object):
"""Check report listing all checks executions."""

pretty_status = {
ORDERED_STATUS = [
"ERROR",
"WARNING",
"INFO",
"SILENT",
"BYPASS",
]

PRETTY_STATUS = {
"ERROR": "Error(s)",
"WARNING": "Warning(s)",
"INFO": "Info(s)",
Expand Down Expand Up @@ -109,20 +117,20 @@ def nested_dict():
# Ignore silenced checks
status_map.pop("SILENT", None)

for status, vals in six.iteritems(status_map):
for status in self.ORDERED_STATUS:
out_stack = []
for k, v in six.iteritems(vals):
for k, v in six.iteritems(status_map[status]):
out_stack += [self._dump_stack("", k, v, indent_level=0)]
if out_stack:
report += "{}\n{}\n".format(
self.pretty_status[status] + ":", "\n".join(out_stack)
self.PRETTY_STATUS[status] + ":", "\n".join(out_stack)
)

bypassed = "\n".join(
set([" . " + c.short_desc() for c in self.checks_bypassed()])
)
if bypassed:
report += "{}\n{}\n".format(self.pretty_status["BYPASS"] + ":", bypassed)
report += "{}\n{}\n".format(self.PRETTY_STATUS["BYPASS"] + ":", bypassed)

return report

Expand Down
3 changes: 2 additions & 1 deletion tests/test_dcp_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ def test_report_checks(self):
self.report.errors_by_criticality("ERROR")
self.assertEqual(3, len(self.report.checks_failed()))
self.assertEqual(1, len(self.report.errors_by_criticality("ERROR")))
self.assertEqual(2, len(self.report.errors_by_criticality("WARNING")))
self.assertEqual(1, len(self.report.errors_by_criticality("WARNING")))
self.assertEqual(1, len(self.report.errors_by_criticality("INFO")))

check = self.report.checks_by_criticality("ERROR")[0]
self.assertEqual(check.name, "check_picture_cpl_max_bitrate")
Expand Down

0 comments on commit fd47ccd

Please sign in to comment.