Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
NIRS_Workflow
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CEFE
PACE
NIRS_Workflow
Commits
b3239243
Commit
b3239243
authored
8 months ago
by
Nicolas Barthes
Browse files
Options
Downloads
Patches
Plain Diff
hash update (split create, check & add function)
parent
6e35d0f4
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Class_Mod/Hash.py
+16
-12
16 additions, 12 deletions
src/Class_Mod/Hash.py
with
16 additions
and
12 deletions
src/Class_Mod/Hash.py
+
16
−
12
View file @
b3239243
from
Packages
import
*
def
create_hash
(
spectra
):
def
create_hash
(
to_hash
):
#using the md5 hash function.
hash_func
=
hashlib
.
md5
()
spectra
=
str
(
spectra
)
encoded_
spectra
=
spectra
.
encode
()
hash_func
.
update
(
encoded_
spectra
)
to_hash
=
str
(
to_hash
)
encoded_
to_hash
=
to_hash
.
encode
()
hash_func
.
update
(
encoded_
to_hash
)
hash
=
hash_func
.
hexdigest
()
return
hash
def
check_hash
(
hash
):
def
check_hash
(
hash
,
hash_type
):
# path to hash file and grep/cat functions for Win
subprocess_path
=
Path
(
"
src/data/hash/
"
)
# run a grep from the hash onto the hash file
nb_hash
=
subprocess
.
run
([
subprocess_path
/
'
grep.exe
'
,
'
-c
'
,
hash
,
subprocess_path
/
"
hash
.txt
"
],
shell
=
True
)
nb_hash
=
subprocess
.
run
([
subprocess_path
/
'
grep.exe
'
,
'
-c
'
,
hash
,
subprocess_path
/
str
(
hash_type
+
"
.txt
"
)
],
shell
=
True
)
# if hash present
if
'
returncode=0
'
in
str
(
nb_hash
):
return
'
existing hash
'
# if hash not present
, add it to the file with cat function
# if hash not present
else
:
add_hash
=
subprocess
.
run
([
'
echo
'
,
str
(
hash
)
+
'
>>
'
,
subprocess_path
/
"
hash.txt
"
],
shell
=
True
)
if
'
returncode=0
'
in
str
(
add_hash
):
return
'
hash added
'
else
:
return
'
error while adding the new hash
'
\ No newline at end of file
return
'
missing hash
'
def
add_hash
(
hash
,
hash_type
):
# add it to the file with cat function
add_hash
=
subprocess
.
run
([
'
echo
'
,
str
(
hash
)
+
'
>>
'
,
subprocess_path
/
str
(
hash_type
+
"
.txt
"
)],
shell
=
True
)
if
'
returncode=0
'
in
str
(
add_hash
):
return
'
hash added
'
else
:
return
'
error while adding the new hash
'
\ No newline at end of file
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