Skip to content

Commit

Permalink
[app][rfct] rename params
Browse files Browse the repository at this point in the history
  • Loading branch information
M3ssman committed Aug 12, 2024
1 parent e42a2b7 commit 29543a6
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 86 deletions.
28 changes: 14 additions & 14 deletions src/digiflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,40 @@
from .validate.metadata_ddb import (
DIGIS_MULTIVOLUME,
DIGIS_NEWSPAPER,
IGNORE_DDB_RULES_INTERMEDIATE,
IGNORE_DDB_RULES_ULB,
IGNORE_DDB_RULES_INTERMEDIATE,
IGNORE_DDB_RULES_ULB,
REPORT_FILE_XSLT,
DigiflowMetadataValidationException,
DDBRole,
Report,
Reporter,
DDBRole,
Report,
Reporter,
)
from .validate import (
INVALID_LABEL_UNSET,
LABEL_SCAN_VALIDATOR_CHANNEL,
LABEL_SCAN_VALIDATOR_COMPRESSION,
LABEL_SCAN_VALIDATOR_RESOLUTION,
LABEL_SCAN_VALIDATOR_FILEDATA,
METS_MODS_XSD,
METS_MODS_XSD,
UNSET_NUMBR,
FSReadException,
FSWriteException,
Image,
ImageMetadata,
Invalid,
InvalidImageDataException,
ScanValidatorCombined,
ScanValidatorChannel,
ScanValidatorCompression,
ScanValidatorFile,
ScanValidatorPhotometric,
ScanValidatorResolution,
ScanValidatorCombined,
ScanValidatorChannel,
ScanValidatorCompression,
ScanValidatorFile,
ScanValidatorPhotometric,
ScanValidatorResolution,
Validator,
ValidatorFactory,
ValidatorFactory,
resource_can_be,
group_can_read,
group_can_write,
validate_tiff,
)

from .common import UNSET_LABEL, XMLNS
from .common import UNSET_LABEL, XMLNS
6 changes: 3 additions & 3 deletions src/digiflow/validate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
)

from .metadata_xsd import (
METS_MODS_XSD,
METS_MODS_XSD,
InvalidXMLException,
validate_xml,
)

from .metadata_ddb import (
DDBRole,
Report,
DDBRole,
Report,
Reporter,
)
81 changes: 44 additions & 37 deletions src/digiflow/validate/metadata_ddb.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
DIGIS_NEWSPAPER = ['issue', 'additional', 'OZ', 'AZ']


# please linter for lxml
# pylint: disable=c-extension-no-member


class DigiflowMetadataValidationException(Exception):
"""Mark Validation Criticals which
otherwise prevent records from being
Expand Down Expand Up @@ -167,72 +171,73 @@ class Report:
and optional schema error hints
"""

def __init__(self, meldungen: typing.List[DDBMeldung]):
self.meldungen = sorted(meldungen, key=lambda e: e.role.order, reverse=True)
self.ignored_rules = []
def __init__(self, ddb_meldungen: typing.List[DDBMeldung]):
self.ddb_meldungen = sorted(ddb_meldungen, key=lambda e: e.role.order, reverse=True)
self.ignored_ddn_rules = []
self.xsd_errors = None

def read(self, only_headlines=True, map_roles=False) -> typing.List:
def read(self, only_headlines=True, map_ddb_roles=False) -> typing.List:
"""Get information from validation in order
of their level from worse descending
"""

if len(self.meldungen) == 0:
if len(self.ddb_meldungen) == 0:
return []
delivery = self.meldungen
delivery = self.ddb_meldungen
if only_headlines:
delivery = [m.shortform() for m in delivery]
if map_roles:
map_roles = {}
if map_ddb_roles:
map_ddb_roles = {}
for news in delivery:
if isinstance(news, tuple):
the_key, appendum = news
elif isinstance(news, DDBMeldung):
the_key = news.role.label
appendum = news.longform()
if the_key not in map_roles:
map_roles.setdefault(the_key, [])
map_roles[the_key].append(appendum)
if len(map_roles) > 0:
delivery = [f"{k}({len(v)}x):{v}" for k, v in map_roles.items()]
if the_key not in map_ddb_roles:
map_ddb_roles.setdefault(the_key, [])
map_ddb_roles[the_key].append(appendum)
if len(map_ddb_roles) > 0:
delivery = [f"{k}({len(v)}x):{v}" for k, v in map_ddb_roles.items()]
return delivery

def categorize(self, ignore_rule_ids, min_level):
def categorize(self, ignore_ddb_rule_ids, min_ddb_level):
"""Move meldungen to ignores if matching
id labels (and optional below importance level
threshold - to just ignore levels like 'info')
"""

ignores = []
respect = []
for m in self.meldungen:
if m.id in ignore_rule_ids:
for m in self.ddb_meldungen:
if m.id in ignore_ddb_rule_ids:
ignores.append(m)
elif isinstance(min_level, str):
elif isinstance(min_ddb_level, str):
current_role = m.role
mininum_role = DDBRole.from_label(min_level)
mininum_role = DDBRole.from_label(min_ddb_level)
if (current_role and mininum_role) \
and current_role < mininum_role:
ignores.append(m)
else:
respect.append(m)
else:
respect.append(m)
self.meldungen = respect
self.ignored_rules = ignores
self.ddb_meldungen = respect
self.ignored_ddn_rules = ignores

def alert(self, min_role_label=None):
def alert(self, min_ddb_role_label=None):
"""Inspect current meldungen if something
(per default) very severe lurks or
(per default) very severe lurks
OR
recognized schema errors
"""

role_level = None
if isinstance(min_role_label, str):
role_level = DDBRole.from_label(min_role_label)
if role_level is None:
role_level = DDBRole.FATAL
has_alerts = any(m for m in self.meldungen if m.role >= role_level)
min_level = None
if isinstance(min_ddb_role_label, str):
min_level = DDBRole.from_label(min_ddb_role_label)
if min_level is None:
min_level = DDBRole.FATAL
has_alerts = any(m for m in self.ddb_meldungen if m.role >= min_level)
return has_alerts or self.xsd_errors is not None


Expand Down Expand Up @@ -270,7 +275,9 @@ def clean(self):
class Reporter:
"""Encapsulates DDB conformant Validation
of metadata with corresponding schema
and the generation of DDBMeldungen
and the generation of DDBMeldungen for
common PICA Types
Switch for issues (PICA: AZ|OZ)
"""

def __init__(self, path_input,
Expand All @@ -286,8 +293,8 @@ def __init__(self, path_input,
path_xslt,
tmp_report_dir)

def get(self, ignore_rule_ids=None,
min_level=None,
def get(self, ignore_ddb_rule_ids=None,
min_ddb_level=None,
validate_schema=True) -> Report:
"""get actual validation report with
respect to custum ignore rule ids
Expand All @@ -301,11 +308,11 @@ def get(self, ignore_rule_ids=None,
ddb_report = Report(meldungen)
self._report = ddb_report
self.transformer.clean()
if ignore_rule_ids is None:
ignore_rule_ids = []
if min_level is None:
min_level = DDBRole.WARN.label
ddb_report.categorize(ignore_rule_ids, min_level)
if ignore_ddb_rule_ids is None:
ignore_ddb_rule_ids = []
if min_ddb_level is None:
min_ddb_level = DDBRole.WARN.label
ddb_report.categorize(ignore_ddb_rule_ids, min_ddb_level)
if validate_schema:
self.run_schema_validation()
return self._report
Expand Down Expand Up @@ -344,7 +351,7 @@ def _enrich_location(self, meldungen):
raise DigiflowMetadataValidationException(_exc) from _exc

def run_schema_validation(self):
"""Forward to separate XSD schema validation"""
"""Forward to XSD schema validation"""

try:
dfv.validate_xml(self.path_input,
Expand Down
15 changes: 3 additions & 12 deletions src/digiflow/validate/metadata_xsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
_DEFAULT_XSD_MAPPINGS = {'mets:mets': [METS_1_12], 'mods:mods': [MODS_3_7], 'mix:mix': [
MIX_2_0], 'alto': [ALTO_4_2]}

# please linter for lxml
# pylint: disable=c-extension-no-member


class InvalidXMLException(Exception):
"""Mark invalid Validation outcome"""
Expand All @@ -43,18 +46,6 @@ def _is_contained(xml_tree, schema):
return len(xml_tree.findall('.//' + schema, dfc.XMLNS)) > 0


# def __validation_error(xmlschema, xml_tree):
# err = xmlschema.error_log
# raise RuntimeError(f"invalid schema '{xml_tree}' {err}")


# def __validate_subtrees(xml_tree, schema, schema_tree):
# sections = xml_tree.findall('.//' + schema, dfc.XMLNS)
# for section in sections:
# if not schema_tree.validate(section):
# return __validation_error(schema_tree, xml_tree)


def _validate(xml_tree, schema, xsd_file):
if __is_schema_root(xml_tree, schema):
return _validate_with_xsd(xml_tree, xsd_file)
Expand Down
Loading

0 comments on commit 29543a6

Please sign in to comment.