Skip to content

Commit

Permalink
Merge pull request #41 from E-ARK-Software/integration
Browse files Browse the repository at this point in the history
Integration
  • Loading branch information
carlwilson authored Sep 11, 2024
2 parents a3c1094 + 34343eb commit c10ae9a
Show file tree
Hide file tree
Showing 143 changed files with 8,742 additions and 1,933 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,33 @@ jobs:

steps:
- uses: actions/[email protected]
with:
fetch-depth: 0
- name: Set up Python
uses: actions/[email protected]
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ".[testing]"
- name: Install python package
run: |
pip install --editable ".[testing]"
- name: Static Pylint code QA
run: |
pylint --errors-only eark_validator
- name: Run pre-commit tests
run: pre-commit run --all-files --verbose
- name: Test with pytest
run: |
pytest
- name: Test setuptools-git-versioning versioning
run: |
python -m pip install setuptools_git_versioning
python -m setuptools_git_versioning
- name: Install build utils
run: |
pip install build
- name: Build package
run: python -m build
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["pypy3.10", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ website of the Digital Information LifeCycle Interoperability Standards Board (D

### Pre-requisites

You must be running either a Debian/Ubuntu Linux distribution or Windows Subsystem for Linux on Windows to follow these commands.
Python 3.10 or later is required to run the E-ARK Python Information Package Validator.

You must be running either a Debian/Ubuntu Linux distribution or Windows Subsystem for Linux on Windows to follow these commands.
If you are running a different Linux distribution you must change the apt commands to your package manager.

For getting Windows Subsystem for Linux up and running, please follow the guide further down and then come back to this step.

### Getting up and running with the E-ARK Python Information Package Validator
Expand Down Expand Up @@ -88,7 +88,7 @@ pip install -U pip
pip install .
```

You are now able to run the application "ip-check". It will validate an Information Package for you.
You are now able to run the application "eark-validator". It will validate an Information Package for you.


#### Testing a valid package.
Expand All @@ -111,10 +111,10 @@ Delete the .zip-file you just downloaded:
rm mets-xml_metsHdr_agent_TYPE_exist.zip
```

Run the ip-check:
Run the eark-validator:

```shell
ip-check mets-xml_metsHdr_agent_TYPE_exist/
eark-validator mets-xml_metsHdr_agent_TYPE_exist/
```

Result:
Expand Down Expand Up @@ -146,7 +146,7 @@ user@machine:~$ tree input

If you do not have Linux and have not previously used WSL please perform the following steps. You must either be logged in as Administrator on the machine or as a user with Administrator rights on the machine.

Start er command prompt (cmd.exe) and then enter the following command:
Start a command prompt (cmd.exe) and then enter the following command:

```shell
wsl --install
Expand Down Expand Up @@ -199,4 +199,4 @@ pip install --editable ".[testing]"

### Running tests

You can run unit tests from the project root: `pytest ./tests/`, or generate test coverage figures by: `pytest --cov=ip_validation ./tests/`. If you want to see which parts of your code aren't tested then: `pytest --cov=ip_validation --cov-report=html ./tests/`. After this you can open the file [`<projectRoot>/htmlcov/index.html`](./htmlcov/index.html) in your browser and survey the gory details.
You can run unit tests from the project root: `pytest ./tests/`, or generate test coverage figures by: `pytest --cov=eark_validator ./tests/`. If you want to see which parts of your code aren't tested then: `pytest --cov=eark_validator --cov-report=html ./tests/`. After this you can open the file [`<projectRoot>/htmlcov/index.html`](./htmlcov/index.html) in your browser and survey the gory details.
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

2 changes: 0 additions & 2 deletions eark_validator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,3 @@
E-ARK : Python information package validation
"""

__version__ = '1.1.1'
97 changes: 67 additions & 30 deletions eark_validator/cli/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,49 +26,75 @@
E-ARK : Information package validation
Command line validation application
"""
import argparse
from pprint import pprint
import json
import os.path
from pathlib import Path
import sys
from typing import Optional, Tuple
import importlib.metadata

import argparse

import eark_validator.structure as STRUCT
from eark_validator.model import ValidationReport
import eark_validator.packages as PACKAGES
from eark_validator.infopacks.package_handler import PackageHandler
from eark_validator.specifications.specification import SpecificationVersion

__version__ = '0.1.0'
__version__ = importlib.metadata.version('eark_validator')

defaults = {
'description': """E-ARK Information Package validation (ip-check).
ip-check is a command-line tool to analyse and validate the structure and
'description': """E-ARK Information Package validation (eark-validator).
eark-validator is a command-line tool to analyse and validate the structure and
metadata against the E-ARK Information Package specifications.
It is designed for simple integration into automated work-flows.""",
'epilog': """
DILCIS Board (http://dilcis.eu)
See LICENSE for license information.
GitHub: https://github.com/E-ARK-Software/py-rest-ip-validator
Author: Carl Wilson (OPF), 2020-2023
Maintainer: Carl Wilson (OPF), 2020-2023"""
GitHub: https://github.com/E-ARK-Software/eark-validator
Author: Carl Wilson (OPF), 2020-2024
Maintainer: Carl Wilson (OPF), 2020-2024"""
}

# Create PARSER
PARSER = argparse.ArgumentParser(description=defaults['description'], epilog=defaults['epilog'])
PARSER = argparse.ArgumentParser(prog='eark-validator',
description=defaults['description'],
epilog=defaults['epilog'])

def parse_command_line():
"""Parse command line arguments."""
# Add arguments
PARSER.add_argument('-r', '--recurse',
action='store_true',
dest='inputRecursiveFlag',
default=True,
default=False,
help='When analysing an information package recurse into representations.')
PARSER.add_argument('-c', '--checksum',
action='store_true',
dest='inputChecksumFlag',
default=False,
help='Calculate and verify file checksums in packages.')
help='Calculate and verify package checksums.')
PARSER.add_argument('-m', '--manifest',
action='store_true',
dest='inputManifestFlag',
default=False,
help='Display package manifest information.')
PARSER.add_argument('-v', '--verbose',
action='store_true',
dest='outputVerboseFlag',
default=False,
help='report results in verbose format')
help='Verbose reporting for selected output options.')
PARSER.add_argument('--schema',
action='store_true',
dest='output_schema',
default=False,
help='Request display of the JSON schema of the output report.')
PARSER.add_argument('-s', '--specification_version',
nargs='?',
dest='specification_version',
default=SpecificationVersion.V2_1_0,
type=SpecificationVersion,
choices=list(SpecificationVersion),
help='Specification version used for validation. Default is %(default)s.')
PARSER.add_argument('--version',
action='version',
version=__version__)
Expand All @@ -89,37 +115,48 @@ def main():
# Get input from command line
args = parse_command_line()
# If no target files or folders specified then print usage and exit
if not args.files:
if _is_show_help(args):
PARSER.print_help()

if args.output_schema:
print(json.dumps(ValidationReport.model_json_schema(), indent=2))
sys.exit(0)

# Iterate the file arguments
for file_arg in args.files:
_loop_exit, _ = _validate_ip(file_arg)
_loop_exit, _ = _validate_ip(file_arg, args.specification_version)
_exit = _loop_exit if (_loop_exit > 0) else _exit
sys.exit(_exit)

def _validate_ip(info_pack):
ret_stat = _check_path(info_pack)
struct_details = STRUCT.validate_package_structure(info_pack)
pprint('Path {}, struct result is: {}'.format(info_pack,
struct_details.status))
for error in struct_details.errors:
pprint(error.to_json())
def _validate_ip(path: str, version: SpecificationVersion) -> Tuple[int, Optional[ValidationReport]]:
ret_stat, checked_path = _check_path(path)
if ret_stat > 0:
return ret_stat, None
report = PACKAGES.PackageValidator(checked_path, version).validation_report
print(f'Path {checked_path}, struct result is: {report.structure.status.value}')
# for message in report.structure.messages:
print(report.model_dump_json())

return ret_stat, struct_details
return ret_stat, report

def _check_path(path):
def _check_path(path: str) -> Tuple[int, Optional[Path]]:
if not os.path.exists(path):
# Skip files that don't exist
pprint('Path {} does not exist'.format(path))
return 1
print(_format_check_path_message(path, 'does not exist'))
return 1, None
if os.path.isfile(path):
# Check if file is a archive format
if not STRUCT.ArchivePackageHandler.is_archive(path):
if not PackageHandler.is_archive(path):
# If not we can't process so report and iterate
pprint('Path {} is not a file we can process.'.format(path))
return 2
return 0
print(_format_check_path_message(path, 'is not an archive file or directory'))
return 2, None
return 0, Path(path)

def _format_check_path_message(path: Path, message: str) -> str:
return f'Processing terminated, path: {path} {message}.'

def _is_show_help(args) -> bool:
return not args.files and not args.output_schema

# def _test_case_schema_checks():
if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion eark_validator/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
E-ARK (https://e-ark4all.eu/)
Open Preservation Foundation (http://www.openpreservation.org)
See LICENSE for license information.
Author: Carl Wilson (OPF), 2016-17
Author: Carl Wilson (OPF), 2016-24
This work was funded by the European commission project funded
as grant number LC-01390244 CEF-TC-2019-3 E-ARK3 under
CONNECTING EUROPE FACILITY (CEF) - TELECOMMUNICATIONS SECTOR
Expand Down
Loading

0 comments on commit c10ae9a

Please sign in to comment.