Skip to content

Commit

Permalink
md.md5()
Browse files Browse the repository at this point in the history
  • Loading branch information
rbardaji committed Mar 28, 2020
1 parent 3ec4e90 commit 9e6dd0f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
4 changes: 2 additions & 2 deletions mooda/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
""" Implementation of mooda """
from .waterframe import WaterFrame
from .input import read_nc_emodnet, read_nc, read_nc_imos, read_pkl
from .util import concat, iplot_location, iplot_timeseries
from .util import concat, iplot_location, iplot_timeseries, md5

__version__ = '1.1.3'
__version__ = '1.2.0'
4 changes: 2 additions & 2 deletions mooda/util/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Implementation of util """
from .concat import concat
from .iplot import iplot_location
from .iplot import iplot_timeseries
from .iplot import iplot_location, iplot_timeseries
from .md5 import md5
35 changes: 35 additions & 0 deletions mooda/util/md5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
""" Implementation of md.md5 """
import hashlib


def md5(file_path, save_dm5=True, md5_path=None):
"""
It generates the MD5 code of the input file.
It saves the code into a file if it save_md5 is True.
It saves the code into the text file of 'md5_path'.
If md5_path is None, the name of the file is the same of the input file
with the md5 extension.
"""

# Make the MD5 code
haser = hashlib.md5()
with open(file_path, 'rb') as open_file:
content = open_file.read()
haser.update(content)

if save_dm5:
if md5_path:
filename_md5 = md5_path
else:
# Get the same path but with md5 extension
parts = file_path.split('.')
filename_md5 = ""
for part in parts[:-1]:
filename_md5 += part
filename_md5 += ".md5"

# Save the md5 code into the file
with open(filename_md5, 'w') as open_file:
open_file.write(haser.hexdigest())

return haser.hexdigest()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


NAME = 'mooda'
VERSION = '1.1.3'
VERSION = '1.2.0'
DESCRIPTION = 'Module for Ocean Observatory Data Analysis'
LONG_DESCRIPTION = ("""
MOODA - Module for Ocean Observatory Data Analysis
Expand Down

0 comments on commit 9e6dd0f

Please sign in to comment.