Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
python-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor 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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
nomad-lab
python-common
Commits
26cf34e4
Commit
26cf34e4
authored
7 years ago
by
Mohamed, Fawzi Roberto (fawzi)
Browse files
Options
Downloads
Patches
Plain Diff
improve generation of gids
compact_sha.sha512("blabla").gid("X")
parent
62c6d3d8
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
common/python/nomadcore/compact_sha.py
+16
-2
16 additions, 2 deletions
common/python/nomadcore/compact_sha.py
with
16 additions
and
2 deletions
common/python/nomadcore/compact_sha.py
+
16
−
2
View file @
26cf34e4
...
...
@@ -3,6 +3,7 @@ import hashlib
import
base64
class
CompactHash
(
object
):
"""
compact sha can be used to calculate nomad gids
"""
def
__init__
(
self
,
proto
):
self
.
_proto
=
proto
...
...
@@ -18,14 +19,27 @@ class CompactHash(object):
data
=
data
.
encode
(
"
utf-8
"
)
return
self
.
_proto
.
update
(
data
)
def
gid
(
self
,
prefix
=
""
):
"""
returns a nomad gid with the given prefix
"""
return
prefix
+
self
.
b64digest
()[:
28
]
def
__getattr__
(
self
,
name
):
return
getattr
(
self
.
_proto
,
name
)
def
sha224
(
*
args
,
**
kwargs
):
"""
CompactSha using sha224 for the checksums (non standard)
"""
return
CompactHash
(
hashlib
.
sha224
(
*
args
,
**
kwargs
))
def
sha512
(
*
args
,
**
kwargs
):
return
CompactHash
(
hashlib
.
sha512
(
*
args
,
**
kwargs
))
def
sha512
(
baseStr
=
None
,
*
args
,
**
kwargs
):
"""
Uses sha512 to calculate the gid (default in nomad)
If you pass and argument it is immediately added to the checksum.
Thus sha512(
"
someString
"
).gid(
"
X
"
) creates a gid in one go
"""
sha
=
CompactHash
(
hashlib
.
sha512
(
*
args
,
**
kwargs
))
if
baseStr
is
not
None
:
sha
.
update
(
baseStr
)
return
sha
def
md5
(
*
args
,
**
kwargs
):
"""
CompactSha using md5 for the checksums (non standard)
"""
return
CompactHash
(
hashlib
.
md5
(
*
args
,
**
kwargs
))
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