Skip to content

Commit

Permalink
Pre commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dockmd committed Oct 1, 2024
1 parent d379a52 commit a371633
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 56 deletions.
3 changes: 2 additions & 1 deletion eark_validator/infopacks/checksummer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from pathlib import Path

from eark_validator.const import NO_PATH, NOT_FILE
Expand Down Expand Up @@ -46,4 +47,4 @@ def hash_file(self, path: Path) -> 'Checksum':
def from_file(cls, path: Path, algorithm: 'ChecksumAlg') -> 'Checksum':
"""Create a Checksum from an etree element."""
# Get the child flocat element and grab the href attribute.
return Checksummer(algorithm).hash_file(path)
return Checksummer(algorithm).hash_file(path)
2 changes: 1 addition & 1 deletion eark_validator/infopacks/information_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def from_path(package_path: Path) -> InformationPackage:
mets_path: Path = to_parse.joinpath(METS_FILE)
if not mets_path.is_file():
raise ValueError('No METS file found in package')

mets: MetsFile = MetsFiles.from_file(mets_path)
details: PackageDetails = InformationPackages.details_from_mets_file(mets_path)
return InformationPackage.model_validate({
Expand Down
2 changes: 1 addition & 1 deletion eark_validator/ipxml/schematron.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
#
# E-ARK Validation
# Copyright (C) 2019
Expand Down
104 changes: 52 additions & 52 deletions eark_validator/mets.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
#
# E-ARK Validation
# Copyright (C) 2019
Expand Down Expand Up @@ -205,14 +205,14 @@ def _parse_file_entry(element: etree.Element) -> FileEntry:
'mimetype': element.attrib.get('MIMETYPE')
})


def _validate_file_entry(file_entry: FileEntry, element: etree.Element, root: Path) -> list[str]:
errors: List[str] = []

if file_entry.path is None:
errors.append(_get_path_requirement_id(element))
return errors

full_path: Path = Path(os.path.join(root, file_entry.path))
if not os.path.isfile(full_path):
errors.append(_get_path_requirement_id(element))
Expand Down Expand Up @@ -279,91 +279,91 @@ def _handle_rel_paths(rootpath: str, metspath: str) -> tuple[str, str]:
else:
relpath = os.path.join(rootpath, metspath)
return relpath.rsplit('/', 1)[0], relpath

def _get_path_requirement_id(element: etree.Element) -> str:
tag = _get_tag_value(element)

if tag == "FLocat":
return "CSIP79"
elif tag == "mptr":
return "CSIP110"
if tag == 'FLocat':
return 'CSIP79'
elif tag == 'mptr':
return 'CSIP110'

parent = element.getparent()
parent_tag = _get_tag_value(parent)
match parent_tag:
case "dmdSec":
return "CSIP24"
case "digiprovMD":
return "CSIP38"
case "rightsMD":
return "CSIP51"
case 'dmdSec':
return 'CSIP24'
case 'digiprovMD':
return 'CSIP38'
case 'rightsMD':
return 'CSIP51'
case _:
raise ValueError(f'Tag {tag} cannot be converted to a requirement ID.')

def _get_size_requirement_id(element: etree.Element) -> str:
element_parent: etree.Element = element.getparent()
tag = _get_tag_value(element_parent)

match tag:
case "dmdSec":
return "CSIP27"
case "digiprovMD":
return "CSIP41"
case "rightsMD":
return "CSIP54"
case "fileGrp":
return "CSIP69"
case 'dmdSec':
return 'CSIP27'
case 'digiprovMD':
return 'CSIP41'
case 'rightsMD':
return 'CSIP54'
case 'fileGrp':
return 'CSIP69'
case _:
raise ValueError(f'Tag {tag} cannot be converted to a requirement ID.')

def _get_checksum_algorithm_requirement_id(element: etree.Element) -> str:
element_parent: etree.Element = element.getparent()
tag = _get_tag_value(element_parent)

match tag:
case "dmdSec":
return "CSIP30"
case "digiprovMD":
return "CSIP44"
case "rightsMD":
return "CSIP57"
case "fileGrp":
return "CSIP72"
case 'dmdSec':
return 'CSIP30'
case 'digiprovMD':
return 'CSIP44'
case 'rightsMD':
return 'CSIP57'
case 'fileGrp':
return 'CSIP72'
case _:
raise ValueError(f'Tag {tag} cannot be converted to a requirement ID.')

def _get_checksum_value_requirement_id(element: etree.Element) -> str:
element_parent: etree.Element = element.getparent()
tag = _get_tag_value(element_parent)

match tag:
case "dmdSec":
return "CSIP29"
case "digiprovMD":
return "CSIP43"
case "rightsMD":
return "CSIP56"
case "fileGrp":
return "CSIP71"
case 'dmdSec':
return 'CSIP29'
case 'digiprovMD':
return 'CSIP43'
case 'rightsMD':
return 'CSIP56'
case 'fileGrp':
return 'CSIP71'
case _:
raise ValueError(f'Tag {tag} cannot be converted to a requirement ID.')

def _get_mimetype_requirement_id(element: etree.Element) -> str:
element_parent: etree.Element = element.getparent()
tag = _get_tag_value(element_parent)

match tag:
case "dmdSec":
return "CSIP26"
case "digiprovMD":
return "CSIP40"
case "rightsMD":
return "CSIP53"
case "fileGrp":
return "CSIP68"
case 'dmdSec':
return 'CSIP26'
case 'digiprovMD':
return 'CSIP40'
case 'rightsMD':
return 'CSIP53'
case 'fileGrp':
return 'CSIP68'
case _:
raise ValueError(f'Tag {tag} cannot be converted to a requirement ID.')

def _get_tag_value(element: etree.Element) -> str:
index: int = element.tag.find('}')
return element.tag if index == -1 else element.tag[index+1:]
2 changes: 1 addition & 1 deletion eark_validator/model/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ class MetsFile(BaseModel):
root: MetsRoot = MetsRoot()
file_entries: List[FileEntry] = []
invalid_file_entries: List[InvalidFileEntry] = []

1 change: 1 addition & 0 deletions eark_validator/model/mimetype.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
media_types = [
'application/1d-interleaved-parityfec',
'application/3gpdash-qoe-report+xml',
Expand Down

0 comments on commit a371633

Please sign in to comment.