-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
start an aim.utils and move md5sum there
- Loading branch information
Showing
9 changed files
with
47 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
""" | ||
Here be utils. | ||
.%%..%%..%%%%%%..%%%%%%..%%.......%%%%.. | ||
.%%..%%....%%......%%....%%......%%..... | ||
.%%..%%....%%......%%....%%.......%%%%.. | ||
.%%..%%....%%......%%....%%..........%%. | ||
..%%%%.....%%....%%%%%%..%%%%%%...%%%%.. | ||
........................................ | ||
""" | ||
|
||
import hashlib | ||
from aim.core.exception import StackException | ||
from functools import partial | ||
|
||
|
||
def md5sum(filename=None, str_data=None): | ||
"""Computes and returns an MD5 sum in hexdigest format on a file or string""" | ||
d = hashlib.md5() | ||
if filename != None: | ||
with open(filename, mode='rb') as f: | ||
for buf in iter(partial(f.read, 128), b''): | ||
d.update(buf) | ||
elif str_data != None: | ||
d.update(bytearray(str_data, 'utf-8')) | ||
else: | ||
print("cli: md5sum: Filename or String data expected") | ||
raise StackException(AimErrorCode.Unknown) | ||
|
||
return d.hexdigest() |