Skip to content

Commit

Permalink
Add extract single file (#123)
Browse files Browse the repository at this point in the history
* Add extract single file
* Disable duplicate-code check, seems not controllable: pylint-dev/pylint#214
* Tidy some excessive sets of positional args
  • Loading branch information
zimeon authored Oct 21, 2024
1 parent 1b2bf39 commit 065c8e3
Show file tree
Hide file tree
Showing 15 changed files with 325 additions and 137 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
pydocstyle *.py ocfl tests
- name: Lint with pylint
run: |
pylint --disable=line-too-long,raise-missing-from,fixme,redefined-builtin,invalid-name,consider-using-f-string,too-many-instance-attributes,too-many-return-statements,too-many-branches,too-many-arguments,too-many-locals,too-many-statements,too-many-nested-blocks,broad-exception-raised,superfluous-parens *.py ocfl
pylint --disable=line-too-long,raise-missing-from,fixme,redefined-builtin,invalid-name,consider-using-f-string,too-many-instance-attributes,too-many-return-statements,too-many-branches,too-many-arguments,too-many-locals,too-many-statements,too-many-nested-blocks,broad-exception-raised,superfluous-parens,duplicate-code *.py ocfl
pylint --disable=line-too-long,fixme,invalid-name,consider-using-f-string,too-many-statements,duplicate-code tests
- name: Test with pytest
run: |
Expand Down
6 changes: 3 additions & 3 deletions docs/demo_build_v1_0_spec_examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ This is inventory should match the example with 3 versions in <https://ocfl.io/1
"type": "https://ocfl.io/1.0/spec/#inventory",
"versions": {
"v1": {
"created": "2024-10-21T14:04:00.192769Z",
"created": "2024-10-21T17:57:00.954822Z",
"state": {
"7dcc352f96c56dc...c31": [
"foo/bar.xml"
Expand All @@ -114,7 +114,7 @@ This is inventory should match the example with 3 versions in <https://ocfl.io/1
}
},
"v2": {
"created": "2024-10-21T14:04:00.193378Z",
"created": "2024-10-21T17:57:00.955241Z",
"state": {
"4d27c86b026ff70...b53": [
"foo/bar.xml"
Expand All @@ -126,7 +126,7 @@ This is inventory should match the example with 3 versions in <https://ocfl.io/1
}
},
"v3": {
"created": "2024-10-21T14:04:00.193732Z",
"created": "2024-10-21T17:57:00.955552Z",
"state": {
"4d27c86b026ff70...b53": [
"foo/bar.xml"
Expand Down
6 changes: 3 additions & 3 deletions docs/demo_build_v1_1_spec_examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ This is inventory should match the example with 3 versions in <https://ocfl.io/1
"type": "https://ocfl.io/1.1/spec/#inventory",
"versions": {
"v1": {
"created": "2024-10-21T14:04:00.709527Z",
"created": "2024-10-21T17:57:01.757332Z",
"state": {
"7dcc352f96c56dc...c31": [
"foo/bar.xml"
Expand All @@ -114,7 +114,7 @@ This is inventory should match the example with 3 versions in <https://ocfl.io/1
}
},
"v2": {
"created": "2024-10-21T14:04:00.710212Z",
"created": "2024-10-21T17:57:01.757764Z",
"state": {
"4d27c86b026ff70...b53": [
"foo/bar.xml"
Expand All @@ -126,7 +126,7 @@ This is inventory should match the example with 3 versions in <https://ocfl.io/1
}
},
"v3": {
"created": "2024-10-21T14:04:00.710604Z",
"created": "2024-10-21T17:57:01.758072Z",
"state": {
"4d27c86b026ff70...b53": [
"foo/bar.xml"
Expand Down
67 changes: 60 additions & 7 deletions docs/demo_ocfl_object_script.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Without an `--objdir` argument the script just writes out the inventory for the
"type": "https://ocfl.io/1.1/spec/#inventory",
"versions": {
"v1": {
"created": "2024-10-21T14:03:55.460006Z",
"created": "2024-10-21T17:56:53.127967Z",
"state": {
"43a43fe8a8a082d3b5343dfaf2fd0c8b8e370675b1f376e92e9994612c33ea255b11298269d72f797399ebb94edeefe53df243643676548f584fb8603ca53a0f": [
"a_file.txt"
Expand Down Expand Up @@ -69,23 +69,23 @@ Without an `--objdir` argument the script just writes out the inventory for each
"type": "https://ocfl.io/1.1/spec/#inventory",
"versions": {
"v1": {
"created": "2024-10-21T14:03:55.607383Z",
"created": "2024-10-21T17:56:53.371204Z",
"state": {
"43a43fe8a8a082d3b5343dfaf2fd0c8b8e370675b1f376e92e9994612c33ea255b11298269d72f797399ebb94edeefe53df243643676548f584fb8603ca53a0f": [
"a_file.txt"
]
}
},
"v2": {
"created": "2024-10-21T14:03:55.607784Z",
"created": "2024-10-21T17:56:53.371363Z",
"state": {
"296e72b8fd5f7f0ac1473993600ae34953d5dab646f17e7b182b8648aff830d7bf01b56490777cb3e72b33fcc1ae520506badea1032252d1a55fd7362e269975": [
"a_file.txt"
]
}
},
"v3": {
"created": "2024-10-21T14:03:55.607960Z",
"created": "2024-10-21T17:56:53.371494Z",
"state": {
"43a43fe8a8a082d3b5343dfaf2fd0c8b8e370675b1f376e92e9994612c33ea255b11298269d72f797399ebb94edeefe53df243643676548f584fb8603ca53a0f": [
"a_file.txt"
Expand Down Expand Up @@ -119,7 +119,7 @@ INFO:root:Built object http://example.org/obj2 at tmp/obj2 with 3 versions

## 5. Test extract of version.

### 5.1 Extract v1 of an OCFL v1.0 object
### 5.1 Extract v1 of content in an OCFL v1.0 object

Version 1 object with location specified in `--objdir` and the first version specified in `--objver`, extract into tmp/v1:

Expand All @@ -134,21 +134,32 @@ and the extracted files are:
```
> find tmp/v1 -print
tmp/v1
tmp/v1/empty.txt
tmp/v1/image.tiff
tmp/v1/empty.txt
tmp/v1/foo
tmp/v1/foo/bar.xml
```


### 5.2 Extract v2 of content in the same OCFL v1.1 object
### 5.2 Extract v2 of content in an OCFL v1.1 object

```
> python ocfl-object.py extract --objver v2 --objdir fixtures/1.1/good-objects/spec-ex-full --dstdir tmp/v2 -v
INFO:root:Extracted v2 into tmp/v2
Extracted content for v2 in tmp/v2
```

and the extracted files are:

```
> find tmp/v2 -print
tmp/v2
tmp/v2/empty2.txt
tmp/v2/empty.txt
tmp/v2/foo
tmp/v2/foo/bar.xml
```


### 5.3 Extract head version (v3) of content in the same OCFL v1.1 object

Expand All @@ -158,6 +169,48 @@ INFO:root:Extracted v3 into tmp/head
Extracted content for v3 in tmp/head
```

and the extracted files are:

```
> find tmp/v3 -print
find: ‘tmp/v3’: No such file or directory
```

(last command exited with return code 1)


### 5.4 Extract foo/bar.xml of v3 into a new directory

```
> python ocfl-object.py extract --objver v3 --objdir fixtures/1.1/good-objects/spec-ex-full --logical-path foo/bar.xml --dstdir tmp/files -v
Extracted foo/bar.xml in v3 to tmp/files
```

and the extracted file is:

```
> find tmp/files -print
tmp/files
tmp/files/bar.xml
```


### 5.5 Extract image.tiff of v3 (default) into the same directory

```
> python ocfl-object.py extract --objdir fixtures/1.1/good-objects/spec-ex-full --logical-path image.tiff --dstdir tmp/files -v
Extracted image.tiff in v3 to tmp/files
```

and the directory now contains two extracted files:

```
> find tmp/files -print
tmp/files
tmp/files/image.tiff
tmp/files/bar.xml
```


## 6. Test error conditions.

Expand Down
2 changes: 1 addition & 1 deletion docs/demo_ocfl_script.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ ERROR:root:Add object failed because path ark%3A123%2Fabc exists

```
> python ocfl.py list --root=extra_fixtures/good-storage-roots/simple-root
http%3A%2F%2Fexample.org%2Fminimal_mixed_digests -- id=http://example.org/minimal_mixed_digests
ark%3A123%2Fabc -- id=ark:123/abc
http%3A%2F%2Fexample.org%2Fminimal_mixed_digests -- id=http://example.org/minimal_mixed_digests
ark%3A%2F12345%2Fbcd987 -- id=ark:/12345/bcd987
Found 3 OCFL Objects under root extra_fixtures/good-storage-roots/simple-root
```
Expand Down
16 changes: 8 additions & 8 deletions docs/demo_ocfl_sidecar_script.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ ocfl-sidecar.py is part of ocfl-py version 1.9.0

```
> mkdir -v tmp/obj
tmp/obj
mkdir: created directory 'tmp/obj'
```


### 2.2 Copy in an inventory from an example

```
> cp -v fixtures/1.0/good-objects/minimal_one_version_one_file/inventory.json tmp/obj
fixtures/1.0/good-objects/minimal_one_version_one_file/inventory.json -> tmp/obj/inventory.json
'fixtures/1.0/good-objects/minimal_one_version_one_file/inventory.json' -> 'tmp/obj/inventory.json'
```


Expand Down Expand Up @@ -68,47 +68,47 @@ Written sidecar file tmp/obj/inventory.json.sha256

```
> mkdir -v tmp/obj1
tmp/obj1
mkdir: created directory 'tmp/obj1'
```


### 3.2 Set up directory as object 2 root

```
> mkdir -v tmp/obj2
tmp/obj2
mkdir: created directory 'tmp/obj2'
```


### 3.3 Set up directory as object 3 root

```
> mkdir -v tmp/obj3
tmp/obj3
mkdir: created directory 'tmp/obj3'
```


### 3.4 Copy in an inventory from an example for object 1

```
> cp -v fixtures/1.1/good-objects/minimal_uppercase_digests/inventory.json tmp/obj1
fixtures/1.1/good-objects/minimal_uppercase_digests/inventory.json -> tmp/obj1/inventory.json
'fixtures/1.1/good-objects/minimal_uppercase_digests/inventory.json' -> 'tmp/obj1/inventory.json'
```


### 3.5 Copy in an inventory from an example for object 2

```
> cp -v fixtures/1.1/good-objects/minimal_mixed_digests/inventory.json tmp/obj2
fixtures/1.1/good-objects/minimal_mixed_digests/inventory.json -> tmp/obj2/inventory.json
'fixtures/1.1/good-objects/minimal_mixed_digests/inventory.json' -> 'tmp/obj2/inventory.json'
```


### 3.6 Copy in an inventory from an example for object 3

```
> cp -v fixtures/1.1/good-objects/minimal_no_content/inventory.json tmp/obj3
fixtures/1.1/good-objects/minimal_no_content/inventory.json -> tmp/obj3/inventory.json
'fixtures/1.1/good-objects/minimal_no_content/inventory.json' -> 'tmp/obj3/inventory.json'
```


Expand Down
54 changes: 27 additions & 27 deletions docs/demo_using_bagit_bags.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ Imagine that we have a Bagit bag [`tests/testdata/bags/uaa_v1`](https://github.c

```
> python ocfl-object.py create --objdir tmp/obj --srcbag tests/testdata/bags/uaa_v1 -v
INFO:bagit:Verifying checksum for file /Users/sw272/src/ocfl-py/tests/testdata/bags/uaa_v1/data/my_content/dracula.txt
INFO:bagit:Verifying checksum for file /Users/sw272/src/ocfl-py/tests/testdata/bags/uaa_v1/data/my_content/poe.txt
INFO:bagit:Verifying checksum for file /Users/sw272/src/ocfl-py/tests/testdata/bags/uaa_v1/bagit.txt
INFO:bagit:Verifying checksum for file /Users/sw272/src/ocfl-py/tests/testdata/bags/uaa_v1/bag-info.txt
INFO:bagit:Verifying checksum for file /Users/sw272/src/ocfl-py/tests/testdata/bags/uaa_v1/manifest-sha512.txt
INFO:bagit:Verifying checksum for file /home/runner/work/ocfl-py/ocfl-py/tests/testdata/bags/uaa_v1/data/my_content/dracula.txt
INFO:bagit:Verifying checksum for file /home/runner/work/ocfl-py/ocfl-py/tests/testdata/bags/uaa_v1/data/my_content/poe.txt
INFO:bagit:Verifying checksum for file /home/runner/work/ocfl-py/ocfl-py/tests/testdata/bags/uaa_v1/bagit.txt
INFO:bagit:Verifying checksum for file /home/runner/work/ocfl-py/ocfl-py/tests/testdata/bags/uaa_v1/bag-info.txt
INFO:bagit:Verifying checksum for file /home/runner/work/ocfl-py/ocfl-py/tests/testdata/bags/uaa_v1/manifest-sha512.txt
INFO:root:Created OCFL object info:bb123cd4567 in tmp/obj
```

Expand Down Expand Up @@ -55,13 +55,13 @@ If we have a bag [`tests/testdata/bags/uaa_v2`](https://github.com/zimeon/ocfl-p

```
> python ocfl-object.py update --objdir tmp/obj --srcbag tests/testdata/bags/uaa_v2 -v
INFO:bagit:Verifying checksum for file /Users/sw272/src/ocfl-py/tests/testdata/bags/uaa_v2/data/my_content/a_second_copy_of_dracula.txt
INFO:bagit:Verifying checksum for file /Users/sw272/src/ocfl-py/tests/testdata/bags/uaa_v2/data/my_content/dracula.txt
INFO:bagit:Verifying checksum for file /Users/sw272/src/ocfl-py/tests/testdata/bags/uaa_v2/data/my_content/poe-nevermore.txt
INFO:bagit:Verifying checksum for file /Users/sw272/src/ocfl-py/tests/testdata/bags/uaa_v2/data/my_content/another_directory/a_third_copy_of_dracula.txt
INFO:bagit:Verifying checksum for file /Users/sw272/src/ocfl-py/tests/testdata/bags/uaa_v2/bagit.txt
INFO:bagit:Verifying checksum for file /Users/sw272/src/ocfl-py/tests/testdata/bags/uaa_v2/bag-info.txt
INFO:bagit:Verifying checksum for file /Users/sw272/src/ocfl-py/tests/testdata/bags/uaa_v2/manifest-sha512.txt
INFO:bagit:Verifying checksum for file /home/runner/work/ocfl-py/ocfl-py/tests/testdata/bags/uaa_v2/data/my_content/a_second_copy_of_dracula.txt
INFO:bagit:Verifying checksum for file /home/runner/work/ocfl-py/ocfl-py/tests/testdata/bags/uaa_v2/data/my_content/dracula.txt
INFO:bagit:Verifying checksum for file /home/runner/work/ocfl-py/ocfl-py/tests/testdata/bags/uaa_v2/data/my_content/poe-nevermore.txt
INFO:bagit:Verifying checksum for file /home/runner/work/ocfl-py/ocfl-py/tests/testdata/bags/uaa_v2/data/my_content/another_directory/a_third_copy_of_dracula.txt
INFO:bagit:Verifying checksum for file /home/runner/work/ocfl-py/ocfl-py/tests/testdata/bags/uaa_v2/bagit.txt
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:Will update info:bb123cd4567 v1 -> v2
INFO:root:Updated OCFL object info:bb123cd4567 in tmp/obj by adding v2
```
Expand Down Expand Up @@ -96,12 +96,12 @@ Similarly we can `--update` with [`tests/testdata/bags/uaa_v3`](https://github.c

```
> python ocfl-object.py update --objdir tmp/obj --srcbag tests/testdata/bags/uaa_v3 -v
INFO:bagit:Verifying checksum for file /Users/sw272/src/ocfl-py/tests/testdata/bags/uaa_v3/data/my_content/dracula.txt
INFO:bagit:Verifying checksum for file /Users/sw272/src/ocfl-py/tests/testdata/bags/uaa_v3/data/my_content/poe-nevermore.txt
INFO:bagit:Verifying checksum for file /Users/sw272/src/ocfl-py/tests/testdata/bags/uaa_v3/data/my_content/another_directory/a_third_copy_of_dracula.txt
INFO:bagit:Verifying checksum for file /Users/sw272/src/ocfl-py/tests/testdata/bags/uaa_v3/bagit.txt
INFO:bagit:Verifying checksum for file /Users/sw272/src/ocfl-py/tests/testdata/bags/uaa_v3/bag-info.txt
INFO:bagit:Verifying checksum for file /Users/sw272/src/ocfl-py/tests/testdata/bags/uaa_v3/manifest-sha512.txt
INFO:bagit:Verifying checksum for file /home/runner/work/ocfl-py/ocfl-py/tests/testdata/bags/uaa_v3/data/my_content/dracula.txt
INFO:bagit:Verifying checksum for file /home/runner/work/ocfl-py/ocfl-py/tests/testdata/bags/uaa_v3/data/my_content/poe-nevermore.txt
INFO:bagit:Verifying checksum for file /home/runner/work/ocfl-py/ocfl-py/tests/testdata/bags/uaa_v3/data/my_content/another_directory/a_third_copy_of_dracula.txt
INFO:bagit:Verifying checksum for file /home/runner/work/ocfl-py/ocfl-py/tests/testdata/bags/uaa_v3/bagit.txt
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:Will update info:bb123cd4567 v2 -> v3
INFO:root:Updated OCFL object info:bb123cd4567 in tmp/obj by adding v3
```
Expand Down Expand Up @@ -140,13 +140,13 @@ Finally, we can `--update` again with [`tests/testdata/bags/uaa_v4`](https://git

```
> python ocfl-object.py update --objdir tmp/obj --srcbag tests/testdata/bags/uaa_v4 -v
INFO:bagit:Verifying checksum for file /Users/sw272/src/ocfl-py/tests/testdata/bags/uaa_v4/data/my_content/dracula.txt
INFO:bagit:Verifying checksum for file /Users/sw272/src/ocfl-py/tests/testdata/bags/uaa_v4/data/my_content/dunwich.txt
INFO:bagit:Verifying checksum for file /Users/sw272/src/ocfl-py/tests/testdata/bags/uaa_v4/data/my_content/poe-nevermore.txt
INFO:bagit:Verifying checksum for file /Users/sw272/src/ocfl-py/tests/testdata/bags/uaa_v4/data/my_content/another_directory/a_third_copy_of_dracula.txt
INFO:bagit:Verifying checksum for file /Users/sw272/src/ocfl-py/tests/testdata/bags/uaa_v4/bagit.txt
INFO:bagit:Verifying checksum for file /Users/sw272/src/ocfl-py/tests/testdata/bags/uaa_v4/bag-info.txt
INFO:bagit:Verifying checksum for file /Users/sw272/src/ocfl-py/tests/testdata/bags/uaa_v4/manifest-sha512.txt
INFO:bagit:Verifying checksum for file /home/runner/work/ocfl-py/ocfl-py/tests/testdata/bags/uaa_v4/data/my_content/dracula.txt
INFO:bagit:Verifying checksum for file /home/runner/work/ocfl-py/ocfl-py/tests/testdata/bags/uaa_v4/data/my_content/dunwich.txt
INFO:bagit:Verifying checksum for file /home/runner/work/ocfl-py/ocfl-py/tests/testdata/bags/uaa_v4/data/my_content/poe-nevermore.txt
INFO:bagit:Verifying checksum for file /home/runner/work/ocfl-py/ocfl-py/tests/testdata/bags/uaa_v4/data/my_content/another_directory/a_third_copy_of_dracula.txt
INFO:bagit:Verifying checksum for file /home/runner/work/ocfl-py/ocfl-py/tests/testdata/bags/uaa_v4/bagit.txt
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:Will update info:bb123cd4567 v3 -> v4
INFO:root:Updated OCFL object info:bb123cd4567 in tmp/obj by adding v4
```
Expand All @@ -161,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 /privatetmp/extracted_v4/tmp7apb1l_h/my_content
INFO:bagit:Moving /privatetmp/extracted_v4/tmp7apb1l_h to data
INFO:bagit:Moving my_content to tmp/extracted_v4/tmpvzloz7i3/my_content
INFO:bagit:Moving tmp/extracted_v4/tmpvzloz7i3 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
Loading

0 comments on commit 065c8e3

Please sign in to comment.