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
ca239e78
Commit
ca239e78
authored
6 years ago
by
Erwan Rouchet
Browse files
Options
Downloads
Patches
Plain Diff
Move Gallica importer to backend
parent
30e52848
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/images/importer.py
+23
-0
23 additions, 0 deletions
arkindex/images/importer.py
from_csv.py
+0
-21
0 additions, 21 deletions
from_csv.py
with
23 additions
and
21 deletions
arkindex/images/importer.py
+
23
−
0
View file @
ca239e78
...
...
@@ -221,6 +221,7 @@ class BaseIndexImporter(ABC):
class
IndexImporter
(
BaseIndexImporter
):
"""
Basic index importer with image matching based on a regular expression.
"""
DEFAULT_MASK
=
r
'
(?:.*/)?([^/]+)\.idx\.gz
'
...
...
@@ -241,3 +242,25 @@ class IndexImporter(BaseIndexImporter):
return
next
(
img
for
img
in
self
.
images
if
image_id
in
img
.
path
)
except
StopIteration
:
raise
Image
.
DoesNotExist
class
GallicaIndexImporter
(
BaseIndexImporter
):
"""
Special importer due to Gallica
'
s complicated URLs
"""
REGEX
=
re
.
compile
(
r
'
.*_0*([0-9]+)(?:_[a-z]+)?\.idx\.gz
'
)
def
__init__
(
self
,
path
,
volume
):
super
().
__init__
(
path
,
volume
)
self
.
images
=
{
p
.
zone
.
image
.
path
.
rpartition
(
'
/
'
)[
2
]:
p
.
zone
.
image
for
p
in
self
.
pages
}
def
get_image
(
self
,
path
):
try
:
return
self
.
images
[
'
f
'
+
GallicaIndexImporter
.
REGEX
.
findall
(
path
)[
0
]]
except
IndexError
:
logger
.
debug
(
'
Mask did not match path {}
'
.
format
(
path
))
raise
Image
.
DoesNotExist
except
KeyError
:
raise
Image
.
DoesNotExist
This diff is collapsed.
Click to expand it.
from_csv.py
+
0
−
21
View file @
ca239e78
...
...
@@ -34,27 +34,6 @@ def import_annotations(source, raw_path, name, index_root):
from
arkindex.images.models
import
Image
from
arkindex.images.importer
import
BaseIndexImporter
,
IndexImporter
class
GallicaIndexImporter
(
BaseIndexImporter
):
"""
Special importer due to Gallica
'
s complicated URLs
"""
REGEX
=
re
.
compile
(
r
'
.*_0*([0-9]+)(?:_[a-z]+)?\.idx\.gz
'
)
def
__init__
(
self
,
path
,
volume
):
super
().
__init__
(
path
,
volume
)
self
.
images
=
{
p
.
zone
.
image
.
path
.
rpartition
(
'
/
'
)[
2
]:
p
.
zone
.
image
for
p
in
self
.
pages
}
def
get_image
(
self
,
path
):
try
:
return
self
.
images
[
'
f
'
+
GallicaIndexImporter
.
REGEX
.
findall
(
path
)[
0
]]
except
IndexError
:
logger
.
debug
(
'
Mask did not match path {}
'
.
format
(
path
))
raise
Image
.
DoesNotExist
except
KeyError
:
raise
Image
.
DoesNotExist
if
raw_path
.
startswith
(
'
/home/data/indexes
'
):
raw_path
=
raw_path
[
18
:]
raw_path
=
raw_path
.
lstrip
(
'
/
'
)
...
...
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