Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkindex
Backend
Commits
8eac54af
Commit
8eac54af
authored
6 years ago
by
Erwan Rouchet
Browse files
Options
Downloads
Patches
Plain Diff
Add custom volume name option
parent
764dffda
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!24
Import volumes from CSV
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex/documents/importer.py
+13
-6
13 additions, 6 deletions
arkindex/documents/importer.py
arkindex/documents/management/commands/import_manifest.py
+5
-0
5 additions, 0 deletions
arkindex/documents/management/commands/import_manifest.py
with
18 additions
and
6 deletions
arkindex/documents/importer.py
+
13
−
6
View file @
8eac54af
...
...
@@ -109,9 +109,10 @@ class ManifestsImporter(ABC):
Parses JSON manifests and annotation data to import them in the database.
"""
def
__init__
(
self
,
imgserv
,
offline
=
False
,
annotations
=
True
):
def
__init__
(
self
,
imgserv
,
offline
=
False
,
annotations
=
True
,
volume_name
=
None
):
"""
Initialize a manifest importer
`imgserv` can be either one ImageServer or a list of ImageServers.
"""
`imgserv` can be either one ImageServer or a list of ImageServers.
When `volume_name` is set, it overrides the manifest volume name.
"""
if
isinstance
(
imgserv
,
ImageServer
):
self
.
imgserv
=
[
imgserv
]
else
:
...
...
@@ -120,6 +121,7 @@ class ManifestsImporter(ABC):
self
.
offline
=
offline
self
.
annotations
=
annotations
self
.
volume_name
=
volume_name
# This dictionary associates canvas IDs with images and pages
# Filled by parse_manifest ; used by parse_annotation_list
...
...
@@ -163,8 +165,9 @@ class ManifestsImporter(ABC):
self
.
parse_annotation_list
(
stream
)
break
def
parse_manifest
(
self
,
stream
):
"""
Parse a IIIF manifest loaded as a stream.
"""
def
_extract_volume_name
(
self
,
stream
):
if
self
.
volume_name
is
not
None
:
return
self
.
volume_name
# Get this file's volume range ID from the top-most structure
try
:
range_id
=
next
(
struct
[
'
ranges
'
][
0
]
...
...
@@ -175,11 +178,15 @@ class ManifestsImporter(ABC):
# Get our volume's structure and label
vol_struct
=
next
(
struct
for
struct
in
ijson
.
items
(
stream
,
"
structures.item
"
)
if
struct
.
get
(
'
@id
'
)
==
range_id
)
vol_name
=
vol_struct
[
'
label
'
]
return
vol_struct
[
'
label
'
]
except
StopIteration
:
logger
.
debug
(
"
Invalid structures in manifest - using manifest label as volume name
"
)
stream
.
seek
(
0
)
vol_name
=
next
(
ijson
.
items
(
stream
,
'
label
'
))
return
next
(
ijson
.
items
(
stream
,
'
label
'
))
def
parse_manifest
(
self
,
stream
):
"""
Parse a IIIF manifest loaded as a stream.
"""
vol_name
=
self
.
_extract_volume_name
(
stream
)
# Create a volume and a register
logger
.
debug
(
"
Creating volume {}
"
.
format
(
vol_name
))
...
...
This diff is collapsed.
Click to expand it.
arkindex/documents/management/commands/import_manifest.py
+
5
−
0
View file @
8eac54af
...
...
@@ -38,6 +38,10 @@ class Command(BaseCommand):
help
=
'
Ignore annotation files
'
,
dest
=
'
annotations
'
,
)
parser
.
add_argument
(
'
--volume-name
'
,
help
=
'
Override the manifest volume name with a custom name.
'
,
)
def
handle
(
self
,
*
args
,
**
options
):
# Handle verbosity level
...
...
@@ -67,6 +71,7 @@ class Command(BaseCommand):
options
[
'
manifest_folder
'
],
offline
=
options
[
'
offline
'
],
annotations
=
options
[
'
annotations
'
],
volume_name
=
options
[
'
volume_name
'
],
)
importer
.
run
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment