Skip to content

Commit

Permalink
Use DEFAULT_SPEC_VERSION config (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
zimeon authored Dec 12, 2024
1 parent 27ecfd7 commit 02528be
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 141 deletions.
7 changes: 2 additions & 5 deletions docs/demo_using_bagit_bags.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ INFO:bagit:Verifying checksum for file /home/runner/work/ocfl-py/ocfl-py/tests/t
INFO:bagit:Verifying checksum for file /home/runner/work/ocfl-py/ocfl-py/tests/testdata/bags/uaa_v2/bag-info.txt
INFO:bagit:Verifying checksum for file /home/runner/work/ocfl-py/ocfl-py/tests/testdata/bags/uaa_v2/manifest-sha512.txt
INFO:root:Updated OCFL object info:bb123cd4567 by adding v2
### <ocfl.version_metadata.VersionMetadata object at 0x7f6067126b30>
Updated object info:bb123cd4567 to v2
```

Expand Down Expand Up @@ -104,7 +103,6 @@ INFO:bagit:Verifying checksum for file /home/runner/work/ocfl-py/ocfl-py/tests/t
INFO:bagit:Verifying checksum for file /home/runner/work/ocfl-py/ocfl-py/tests/testdata/bags/uaa_v3/bag-info.txt
INFO:bagit:Verifying checksum for file /home/runner/work/ocfl-py/ocfl-py/tests/testdata/bags/uaa_v3/manifest-sha512.txt
INFO:root:Updated OCFL object info:bb123cd4567 by adding v3
### <ocfl.version_metadata.VersionMetadata object at 0x7f586cc5ab60>
Updated object info:bb123cd4567 to v3
```

Expand Down Expand Up @@ -150,7 +148,6 @@ INFO:bagit:Verifying checksum for file /home/runner/work/ocfl-py/ocfl-py/tests/t
INFO:bagit:Verifying checksum for file /home/runner/work/ocfl-py/ocfl-py/tests/testdata/bags/uaa_v4/bag-info.txt
INFO:bagit:Verifying checksum for file /home/runner/work/ocfl-py/ocfl-py/tests/testdata/bags/uaa_v4/manifest-sha512.txt
INFO:root:Updated OCFL object info:bb123cd4567 by adding v4
### <ocfl.version_metadata.VersionMetadata object at 0x7fbd12f42b60>
Updated object info:bb123cd4567 to v4
```

Expand All @@ -164,8 +161,8 @@ Taking the newly created OCFL object `/tmp/obj` we can `--extract` the `v4` cont
INFO:root:Extracted v4 into tmp/extracted_v4
INFO:bagit:Creating bag for directory tmp/extracted_v4
INFO:bagit:Creating data directory
INFO:bagit:Moving my_content to tmp/extracted_v4/tmpw3baynt4/my_content
INFO:bagit:Moving tmp/extracted_v4/tmpw3baynt4 to data
INFO:bagit:Moving my_content to tmp/extracted_v4/tmp0odx3wcl/my_content
INFO:bagit:Moving tmp/extracted_v4/tmp0odx3wcl to data
INFO:bagit:Using 1 processes to generate manifests: sha512
INFO:bagit:Generating manifest lines for file data/my_content/dracula.txt
INFO:bagit:Generating manifest lines for file data/my_content/dunwich.txt
Expand Down
216 changes: 108 additions & 108 deletions docs/validation_status.md

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion ocfl.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import ocfl # pylint: disable=import-self; this isn"t actually self import
from ocfl.command_line_utils import add_version_arg, add_verbosity_args, \
check_version_arg, check_verbosity_args
from ocfl.constants import DEFAULT_SPEC_VERSION


def add_common_args(parser):
Expand Down Expand Up @@ -38,7 +39,8 @@ def parse_arguments():
"create",
help="Create and initialize storage root")
add_common_args(create_parser)
create_parser.add_argument("--spec-version", "--spec", action="store", default="1.1",
create_parser.add_argument("--spec-version", "--spec", action="store",
default=DEFAULT_SPEC_VERSION,
help="OCFL specification version to adhere to")
create_parser.add_argument("--layout-params", action="store", default=None,
help="Specify parameters for the selected storage layout as a JSON string (including the extensionName is optional)")
Expand Down
2 changes: 1 addition & 1 deletion ocfl/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
>>> import ocfl
>>> inv = ocfl.Inventory(filepath="fixtures/1.1/good-objects/spec-ex-full/inventory.json")
>>> inv.spec_version
'1.1'
"1.1"
>>> inv.version_numbers
[1, 2, 3]
>>> v2 = inv.version("v2")
Expand Down
11 changes: 6 additions & 5 deletions ocfl/inventory_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
>>> iv.validate(inv)
True
>>> iv.spec_version
'1.1'
"1.1"
>>> with open("fixtures/1.1/bad-objects/E025_wrong_digest_algorithm/inventory.json") as fh:
... inv = json.load(fh)
...
Expand All @@ -27,7 +27,7 @@
"""
import re

from .constants import SPEC_VERSIONS_SUPPORTED, DEFAULT_CONTENT_DIRECTORY
from .constants import SPEC_VERSIONS_SUPPORTED, DEFAULT_SPEC_VERSION, DEFAULT_CONTENT_DIRECTORY
from .digest import digest_regex, normalized_digest
from .validation_logger import ValidationLogger
from .w3c_datetime import str_to_datetime
Expand Down Expand Up @@ -55,7 +55,7 @@ class InventoryValidator():
"""Class for OCFL Inventory Validator."""

def __init__(self, *, log=None, where="???",
lax_digests=False, default_spec_version="1.1"):
lax_digests=False, default_spec_version=DEFAULT_SPEC_VERSION):
"""Initialize OCFL Inventory Validator.
It is expected that a new InventoryValidator object be created for
Expand All @@ -75,8 +75,9 @@ def __init__(self, *, log=None, where="???",
lax_digests: True to allow any digest to be used for
content addressing, as opposed to only those allowed
by the specification.
default_spec_version: string (default "1.1") indicating
the specification version to assume if it is not set.
default_spec_version: string (defaults to
ocfl.constants.DEFAULT_SPEC_VERSION) indicating
the specification version to assume if it is not set.
"""
self.log = ValidationLogger() if log is None else log
self.where = where
Expand Down
9 changes: 5 additions & 4 deletions ocfl/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import fs.path
import fs.copy

from .constants import INVENTORY_FILENAME, DEFAULT_CONTENT_DIRECTORY
from .constants import INVENTORY_FILENAME, DEFAULT_SPEC_VERSION, DEFAULT_CONTENT_DIRECTORY
from .digest import file_digest
from .inventory import Inventory
from .inventory_validator import InventoryValidator
Expand Down Expand Up @@ -81,7 +81,8 @@ class Object(): # pylint: disable=too-many-public-methods
def __init__(self, *, identifier=None,
content_directory=DEFAULT_CONTENT_DIRECTORY,
digest_algorithm="sha512", content_path_normalization="uri",
spec_version="1.1", forward_delta=True, dedupe=True,
spec_version=DEFAULT_SPEC_VERSION,
forward_delta=True, dedupe=True,
lax_digests=False, fixity=None,
obj_fs=None, path=None, create=False):
"""Initialize OCFL object.
Expand All @@ -91,7 +92,8 @@ def __init__(self, *, identifier=None,
content_directory: allow override of the default "content"
digest_algorithm: allow override of the default "sha512"
content_path_normalization: allow override of default "uri"
spec_version: OCFL specification version
spec_version: OCFL specification version, default value is
taken from ocfl.constants.DEFAULT_SPEC_VERSION
forward_delta: set False to turn off foward delta. With forward delta
turned off, the same content will be repeated in a new version
rather than simply being included by reference through the
Expand Down Expand Up @@ -381,7 +383,6 @@ def add_version_with_content(self, objdir="", srcdir=None, metadata=None):
settings (such as using a new digest). There will be no content change
between versions.
"""
print("### " + str(metadata))
nv = self.start_new_version(objdir=objdir,
srcdir=srcdir,
digest_algorithm=self.digest_algorithm,
Expand Down
4 changes: 2 additions & 2 deletions ocfl/storage_root.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import fs
from fs.copy import copy_dir

from .constants import SPEC_VERSIONS_SUPPORTED
from .constants import DEFAULT_SPEC_VERSION, SPEC_VERSIONS_SUPPORTED
from .namaste import find_namastes, Namaste
from .object import Object
from .pyfs import pyfs_openfs, pyfs_walk, pyfs_opendir
Expand Down Expand Up @@ -85,7 +85,7 @@ def __init__(self, root=None, layout_name=None, lax_digests=False,
self.structure_error = None
self.traversal_errors = None

def check_spec_version(self, spec_version, default="1.1"):
def check_spec_version(self, spec_version, default=DEFAULT_SPEC_VERSION):
"""Check the OCFL specification version is supported."""
if spec_version is None and self.spec_version is None:
spec_version = default
Expand Down
17 changes: 10 additions & 7 deletions ocfl/validation_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import os.path
import re

from ocfl.constants import DEFAULT_SPEC_VERSION


class ValidationLogger():
"""Class for OCFL ValidationLogger.
Expand All @@ -40,24 +42,25 @@ class ValidationLogger():
validation_codes = None

def __init__(self, *, log_warnings=False, log_errors=True,
spec_version="1.1", lang="en", validation_codes=None):
spec_version=DEFAULT_SPEC_VERSION,
lang="en", validation_codes=None):
"""Initialize OCFL validation logger.
Keyword arguments:
Arguments:
log_warnings (bool): True to log warnings via the
warning() method. Default False.
warning() method. Default False
log_errors (bool): True to logs errors via the error()
method. Default True.
method. Default True
spec_version (str): Specification version being validated
against, default "1.1".
against, default taken from ocfl.constants.DEFAULT_SPEC_VERSION
lang (str): Language code to look up description strings
with, default "en".
with, default "en"
validation_codes (dict): Default None. Usual behavior is to
not use this argument in which case the validation codes
and description data are loaded from the normal location
on first use of this class. Subsequent instantiations use
the same class data. Allows an override to supply the
data explicitly.
data explicitly
"""
self.log_warnings = log_warnings
self.log_errors = log_errors
Expand Down
14 changes: 8 additions & 6 deletions ocfl/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import fs

from .constants import INVENTORY_FILENAME, SPEC_VERSIONS_SUPPORTED, \
DEFAULT_CONTENT_DIRECTORY
DEFAULT_SPEC_VERSION, DEFAULT_CONTENT_DIRECTORY
from .digest import file_digest, normalized_digest
from .inventory_validator import InventoryValidator
from .namaste import find_namastes
Expand All @@ -31,7 +31,8 @@ class Validator():

def __init__(self, *, log_warnings=False, log_errors=True,
check_digests=True, lax_digests=False,
force_spec_version=None, default_spec_version="1.1",
force_spec_version=None,
default_spec_version=DEFAULT_SPEC_VERSION,
log=None, lang="en"):
"""Initialize OCFL Object validator object.
Expand All @@ -44,18 +45,19 @@ def __init__(self, *, log_warnings=False, log_errors=True,
lax_digests: default is False. Set True to allow digests beyond
those included in the specification for fixity and to allow
non-preferred digest algorithms for content references in the
object.
object
force_spec_version: string of specification version to force
validation at, else None (default) to not force a specific
version. If force_spec_version is set then a declaration within
the object that doesn't match will be reported as an error.
the object that doesn't match will be reported as an error
default_spec_version: string of default specification version to
assume where not specified (default "1.1")
assume where not specified. Default is taken from
ocfl.constants.DEFAULT_SPEC_VERSION
log: None (default) to create new ValidationLogger instance, or
else use the specified instance which is the appropriate case
for validation of multiple objects within a storage root.
lang: language string (default "en") to pass to the validation
logger.
logger
"""
self.check_digests = check_digests
self.lax_digests = lax_digests
Expand Down
4 changes: 2 additions & 2 deletions tests/test_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def test_validate(self):
self.assertFalse(passed)
self.assertIn("[E036a]", validator.status_str())
#
oo = Object(spec_version='1.1')
oo = Object(spec_version="1.1")
(passed, validator) = oo.validate(objdir='fixtures/1.1/good-objects/minimal_one_version_one_file')
self.assertTrue(passed)
self.assertEqual(validator.status_str(), "")
Expand All @@ -213,7 +213,7 @@ def test_validate_inventory(self):
self.assertFalse(oo.validate_inventory(path='fixtures/1.0/bad-objects/E036_no_id/inventory.json')[0])
self.assertFalse(oo.validate_inventory(path='tests/testdata/namaste/0=frog')[0]) # not JSON
#
oo = Object(spec_version='1.1')
oo = Object(spec_version="1.1")
(passed, validator) = oo.validate_inventory(path='fixtures/1.1/good-objects/minimal_one_version_one_file/inventory.json')
self.assertTrue(passed)
self.assertEqual(validator.status_str(), '')
Expand Down

0 comments on commit 02528be

Please sign in to comment.