Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nomad-FAIR
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
nomad-lab
nomad-FAIR
Commits
1bd3943f
Commit
1bd3943f
authored
6 years ago
by
Markus Scheidgen
Browse files
Options
Downloads
Patches
Plain Diff
Added metadata and hash functions to files.py
parent
fec088cf
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
nomad/files.py
+12
-6
12 additions, 6 deletions
nomad/files.py
with
12 additions
and
6 deletions
nomad/files.py
+
12
−
6
View file @
1bd3943f
...
@@ -43,6 +43,8 @@ from minio import Minio
...
@@ -43,6 +43,8 @@ from minio import Minio
import
minio.error
import
minio.error
import
logging
import
logging
import
itertools
import
itertools
import
hashlib
import
base64
import
nomad.config
as
config
import
nomad.config
as
config
...
@@ -160,6 +162,7 @@ class Upload():
...
@@ -160,6 +162,7 @@ class Upload():
upload_file: The path of the tmp version of this file for an open upload.
upload_file: The path of the tmp version of this file for an open upload.
upload_extract_dir: The path of the tmp directory with the extracted contents.
upload_extract_dir: The path of the tmp directory with the extracted contents.
filelist: A list of filenames relative to the .zipped upload root.
filelist: A list of filenames relative to the .zipped upload root.
metadata: The upload object storage metadata.
"""
"""
def
__init__
(
self
,
upload_id
:
str
)
->
None
:
def
__init__
(
self
,
upload_id
:
str
)
->
None
:
self
.
upload_id
=
upload_id
self
.
upload_id
=
upload_id
...
@@ -168,7 +171,7 @@ class Upload():
...
@@ -168,7 +171,7 @@ class Upload():
self
.
filelist
:
List
[
str
]
=
None
self
.
filelist
:
List
[
str
]
=
None
try
:
try
:
_client
.
stat_object
(
config
.
s3
.
uploads_bucket
,
upload_id
)
self
.
metadata
=
_client
.
stat_object
(
config
.
s3
.
uploads_bucket
,
upload_id
)
.
metadata
except
minio
.
error
.
NoSuchKey
:
except
minio
.
error
.
NoSuchKey
:
raise
KeyError
(
self
.
upload_id
)
raise
KeyError
(
self
.
upload_id
)
...
@@ -187,11 +190,14 @@ class Upload():
...
@@ -187,11 +190,14 @@ class Upload():
return
wrapper
return
wrapper
@Decorators.handle_errors
@Decorators.handle_errors
def
metadata
(
self
):
def
hash
(
self
)
->
str
:
try
:
"""
Calculates the first 28 bytes of a websafe base64 encoded SHA512 of the upload.
"""
return
_client
.
stat_object
(
config
.
s3
.
uploads_bucket
,
self
.
upload_id
).
metadata
hash
=
hashlib
.
sha512
()
except
minio
.
error
.
NoSuchKey
:
with
open
(
self
.
upload_file
,
'
rb
'
)
as
f
:
raise
KeyError
(
self
.
upload_id
)
for
data
in
iter
(
lambda
:
f
.
read
(
65536
),
b
''
):
hash
.
update
(
data
)
return
base64
.
b64encode
(
hash
.
digest
(),
altchars
=
b
'
-_
'
)[
0
:
28
].
decode
(
'
utf-8
'
)
@Decorators.handle_errors
@Decorators.handle_errors
def
open
(
self
)
->
None
:
def
open
(
self
)
->
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