Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
CaosDB Crawler
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
CaosDB Crawler
Commits
f411d63b
Commit
f411d63b
authored
7 months ago
by
Alexander Schlemmer
Browse files
Options
Downloads
Patches
Plain Diff
ENH(converters): implemented zipfile converter
parent
bd74a095
No related branches found
No related tags found
2 merge requests
!217
TST: Make NamedTemporaryFiles Windows-compatible
,
!200
Zipfile converter
Pipeline
#57687
passed with warnings
7 months ago
Stage: info
Stage: setup
Stage: cert
Stage: style
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/caoscrawler/converters/__init__.py
+1
-0
1 addition, 0 deletions
src/caoscrawler/converters/__init__.py
src/caoscrawler/converters/zipfile.py
+81
-0
81 additions, 0 deletions
src/caoscrawler/converters/zipfile.py
with
82 additions
and
0 deletions
src/caoscrawler/converters/__init__.py
+
1
−
0
View file @
f411d63b
...
@@ -23,6 +23,7 @@
...
@@ -23,6 +23,7 @@
from
..
import
utils
from
..
import
utils
from
.converters
import
*
from
.converters
import
*
from
.xml_converter
import
*
from
.xml_converter
import
*
from
.zipfile
import
*
try
:
try
:
from
.spss
import
SPSSConverter
from
.spss
import
SPSSConverter
...
...
This diff is collapsed.
Click to expand it.
src/caoscrawler/converters/zipfile.py
0 → 100644
+
81
−
0
View file @
f411d63b
# encoding: utf-8
#
# This file is a part of the LinkAhead Project.
#
# Copyright (C) 2024 Indiscale GmbH <info@indiscale.com>
# Copyright (C) 2024 Alexander Schlemmer
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
Converters take structure elements and create Records and new structure elements from them.
This converter opens zip files, unzips them into a temporary directory and
exposes its contents as File structure elements.
"""
from
__future__
import
annotations
import
os
import
tempfile
from
os.path
import
isdir
,
join
from
zipfile
import
ZipFile
from
..stores
import
GeneralStore
from
..structure_elements
import
Directory
,
File
,
StructureElement
from
.converters
import
SimpleFileConverter
class
ZipFileConverter
(
SimpleFileConverter
):
"""
Convert zipfiles.
"""
def
setup
(
self
):
self
.
_tempdir
=
None
def
cleanup
(
self
):
self
.
_tempdir
.
cleanup
()
def
create_children
(
self
,
generalStore
:
GeneralStore
,
element
:
StructureElement
):
"""
Loads an ROCrate from an rocrate file or directory.
Arguments:
----------
element must be a File or Directory (structure element).
Returns:
--------
A list with an ROCrateElement representing the contents of the .eln-file or None
in case of errors.
"""
if
isinstance
(
element
,
File
):
self
.
_tempdir
=
tempfile
.
TemporaryDirectory
()
unzd_path
=
self
.
_tempdir
.
name
with
ZipFile
(
element
.
path
)
as
zipf
:
zipf
.
extractall
(
unzd_path
)
entity_ls
=
[]
for
el
in
os
.
listdir
(
unzd_path
):
if
isdir
(
join
(
unzd_path
,
el
)):
entity_ls
.
append
(
Directory
())
else
:
entity_ls
.
append
(
File
())
return
entity_ls
else
:
raise
ValueError
(
"
create_children was called with wrong type of StructureElement
"
)
return
None
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