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
50ea8e63
Commit
50ea8e63
authored
6 years ago
by
Erwan Rouchet
Browse files
Options
Downloads
Patches
Plain Diff
Fix multiprocessing pool
parent
43235f20
No related branches found
No related tags found
1 merge request
!24
Import volumes from CSV
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
arkindex/documents/management/commands/from_csv.py
+30
-28
30 additions, 28 deletions
arkindex/documents/management/commands/from_csv.py
with
30 additions
and
28 deletions
arkindex/documents/management/commands/from_csv.py
+
30
−
28
View file @
50ea8e63
...
...
@@ -19,38 +19,40 @@ logging.basicConfig(
logger
=
logging
.
getLogger
(
__name__
)
class
Command
(
BaseCommand
):
help
=
"
Import Himanis volumes from CSV file. May require the Arkindex backend in PATH.
"
def
import_manifest
(
url
,
name
):
"
Import a manifest from a given URL with a given volume name.
"
logger
.
info
(
'
Importing volume {} from {}
'
.
format
(
name
,
url
))
URLManifestsImporter
([],
url
,
offline
=
True
,
volume_name
=
name
).
run
()
def
import_manifest
(
url
,
name
):
"
Import a manifest from a given URL with a given volume name.
"
logger
.
info
(
'
Importing volume {} from {}
'
.
format
(
name
,
url
))
URLManifestsImporter
([],
url
,
offline
=
True
,
volume_name
=
name
).
run
()
def
import_annotations
(
source
,
raw_path
,
name
,
index_root
):
"""
Import annotations.
source:
'
bvmm
'
or
'
gallica
'
raw_path: Raw path to index file
name: Volume name
index_root: Root folder for index files
"""
def
import_annotations
(
source
,
raw_path
,
name
,
index_root
):
"""
Import annotations.
source:
'
bvmm
'
or
'
gallica
'
raw_path: Raw path to index file
name: Volume name
index_root: Root folder for index files
"""
if
raw_path
.
startswith
(
'
/home/data/indexes
'
):
raw_path
=
raw_path
[
18
:]
raw_path
=
raw_path
.
lstrip
(
'
/
'
)
index_path
=
os
.
path
.
join
(
index_root
,
raw_path
)
assert
os
.
path
.
exists
(
index_path
)
if
raw_path
.
startswith
(
'
/home/data/indexes
'
):
raw_path
=
raw_path
[
18
:]
raw_path
=
raw_path
.
lstrip
(
'
/
'
)
index_path
=
os
.
path
.
join
(
index_root
,
raw_path
)
assert
os
.
path
.
exists
(
index_path
)
volume
=
Element
.
objects
.
get
(
name
=
name
,
type
=
ElementType
.
Volume
)
volume
=
Element
.
objects
.
get
(
name
=
name
,
type
=
ElementType
.
Volume
)
if
source
==
'
bvmm
'
:
IndexImporter
(
index_path
,
volume
,
mask
=
r
'
(?:.*/)?([^/]+)_[A-Z]\.idx\.gz
'
).
run
()
elif
source
==
'
gallica
'
:
GallicaIndexImporter
(
index_path
,
volume
).
run
()
else
:
# Try anyway
IndexImporter
(
index_path
,
volume
).
run
()
if
source
==
'
bvmm
'
:
IndexImporter
(
index_path
,
volume
,
mask
=
r
'
(?:.*/)?([^/]+)_[A-Z]\.idx\.gz
'
).
run
()
elif
source
==
'
gallica
'
:
GallicaIndexImporter
(
index_path
,
volume
).
run
()
else
:
# Try anyway
IndexImporter
(
index_path
,
volume
).
run
()
class
Command
(
BaseCommand
):
help
=
"
Import Himanis volumes from CSV file. May require the Arkindex backend in PATH.
"
def
add_arguments
(
self
,
parser
):
parser
.
add_argument
(
'
csv
'
)
...
...
@@ -84,6 +86,6 @@ class Command(BaseCommand):
with
Pool
(
options
[
'
processes
'
])
as
pool
:
logger
.
info
(
'
Importing all manifests
'
)
pool
.
starmap
(
self
.
import_manifest
,
[(
row
[
1
],
row
[
0
])
for
row
in
data
])
pool
.
starmap
(
import_manifest
,
[(
row
[
1
],
row
[
0
])
for
row
in
data
])
logger
.
info
(
'
Importing all annotations
'
)
pool
.
starmap
(
self
.
import_annotations
,
[(
row
[
3
],
row
[
2
],
row
[
0
],
args
[
'
index_root
'
])
for
row
in
data
])
pool
.
starmap
(
import_annotations
,
[(
row
[
3
],
row
[
2
],
row
[
0
],
args
[
'
index_root
'
])
for
row
in
data
])
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