Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nomad-lab
nomad-FAIR
Commits
d3b96e98
Commit
d3b96e98
authored
Dec 19, 2019
by
Markus Scheidgen
Browse files
Added support for .xz file preview.
parent
a4661185
Changes
4
Hide whitespace changes
Inline
Side-by-side
nomad/app/api/raw.py
View file @
d3b96e98
...
...
@@ -25,6 +25,7 @@ import magic
import
fnmatch
import
json
import
gzip
import
lzma
import
urllib.parse
from
nomad
import
search
,
utils
,
config
...
...
@@ -140,10 +141,15 @@ def get_raw_file_from_upload_path(
raw_file
=
upload_files
.
raw_file
(
upload_filepath
,
'br'
)
if
request
.
args
.
get
(
'decompress'
)
is
not
None
and
upload_filepath
.
endswith
(
'.gz'
):
filename
=
upload_filepath
[:
3
]
upload_filepath
=
filename
raw_file
=
gzip
.
GzipFile
(
filename
=
filename
,
mode
=
'rb'
,
fileobj
=
raw_file
)
if
request
.
args
.
get
(
'decompress'
)
is
not
None
:
if
upload_filepath
.
endswith
(
'.gz'
):
filename
=
upload_filepath
[:
3
]
upload_filepath
=
filename
raw_file
=
gzip
.
GzipFile
(
filename
=
filename
,
mode
=
'rb'
,
fileobj
=
raw_file
)
if
upload_filepath
.
endswith
(
'.xz'
):
filename
=
upload_filepath
[:
3
]
upload_filepath
=
filename
raw_file
=
lzma
.
open
(
filename
=
raw_file
,
mode
=
'rb'
)
buffer
=
raw_file
.
read
(
2048
)
raw_file
.
seek
(
0
)
...
...
tests/app/test_api.py
View file @
d3b96e98
...
...
@@ -479,7 +479,8 @@ class TestUploads:
@
pytest
.
mark
.
parametrize
(
'upload_file, ending'
,
[
(
'examples_potcar.zip'
,
''
),
(
'examples_potcar_gz.tgz'
,
'.gz'
)])
(
'examples_potcar_gz.tgz'
,
'.gz'
),
(
'examples_potcar_xz.tgz'
,
'.xz'
)])
def
test_potcar
(
self
,
api
,
proc_infra
,
test_user_auth
,
upload_file
,
ending
):
# only the owner, shared with people are supposed to download the original potcar file
example_file
=
'tests/data/proc/%s'
%
upload_file
...
...
@@ -1388,9 +1389,13 @@ class TestRaw(UploadFilesBasedTests):
upload
=
files
.
ArchiveBasedStagingUploadFiles
(
'upload_id'
,
upload_path
=
'tests/data/api/example_with_compressed.zip'
,
create
=
True
)
upload
.
extract
()
rv
=
api
.
get
(
'raw/upload_id/example_with_compressed/mainfile.gz?decompress=true&offset=5&length=3'
,
headers
=
admin_user_auth
)
assert
rv
.
status_code
==
200
assert
rv
.
data
==
b
'con'
for
compression
in
[
'gz'
,
'xz'
]:
rv
=
api
.
get
(
'raw/upload_id/example_with_compressed/mainfile.%s?'
'decompress=true&offset=5&length=3'
%
compression
,
headers
=
admin_user_auth
)
assert
rv
.
status_code
==
200
assert
rv
.
data
==
b
'con'
@
UploadFilesBasedTests
.
ignore_authorization
def
test_raw_file_signed
(
self
,
api
,
upload
,
_
,
test_user_signature_token
):
...
...
tests/data/api/example_with_compressed.zip
View file @
d3b96e98
No preview for this file type
tests/data/proc/examples_potcar_xz.tgz
0 → 100644
View file @
d3b96e98
File added
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment