Skip to content

Commit

Permalink
md.md5() documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
rbardaji committed Mar 29, 2020
1 parent 9e6dd0f commit 3a4d04e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
37 changes: 37 additions & 0 deletions docs/api_reference/util/md5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# mooda.md5(*file_path*, *save_dm5*=*True*, *md5_path*=*None*)

## Reference

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 as the input file with the md5 extension.

### Parameters

* file_path: Path of the file to make the MD5. (str)
* save_md5: If save_md5 is True, it creates a file with the MD5. (bool)
* md5_path: Path of the MD5 file. If md5_path is None, the name of the file is the same as the input file with the md5 extension. (path)

### Returns

* haser: MD5 code. (str)

### Example

To reproduce the example, download the NetCDF file [MO_TS_MO_OBSEA_201402.nc](http://data.emso.eu/files/emso/obsea/mo/ts/MO_TS_MO_OBSEA_201402.nc).

```python
import mooda as md


md5_string = md.md5("MO_TS_MO_OBSEA_201402.nc")
print(md5_string)
```

Output:

```shell
aff8d84c53f38e5525fd312f38d1e4cf
```

*Note: The script also makes a file called MO_TS_MO_OBSEA_201402.md5 with the MD5 code.*

Return to [mooda.WaterFrame](../index_api_reference.md).
21 changes: 18 additions & 3 deletions mooda/util/md5.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,28 @@
import hashlib


def md5(file_path, save_dm5=True, md5_path=None):
def md5(file_path, save_md5=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
If md5_path is None, the name of the file is the same as the input file
with the md5 extension.
Parameters
----------
file_path: str
Path of the file to make the MD5.
save_md5: bool
If save_md5 is True, it creates a file with the MD5.
md5_path: path
Path of the MD5 file. If md5_path is None, the name of the file is
the same as the input file with the md5 extension.
Returns
-------
haser: str
MD5 code.
"""

# Make the MD5 code
Expand All @@ -17,7 +32,7 @@ def md5(file_path, save_dm5=True, md5_path=None):
content = open_file.read()
haser.update(content)

if save_dm5:
if save_md5:
if md5_path:
filename_md5 = md5_path
else:
Expand Down

0 comments on commit 3a4d04e

Please sign in to comment.