Skip to content

Commit

Permalink
Refactor the hash helper script to use pathlib and CLI args
Browse files Browse the repository at this point in the history
  • Loading branch information
webknjaz authored Jan 8, 2022
1 parent 8682135 commit 0575dc8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions print-hash.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import os
import hashlib
import pathlib
import sys

sha256 = hashlib.sha256()
md5 = hashlib.md5()
blake2_256 = hashlib.blake2b(digest_size=256 // 8)

file_list = os.listdir(os.path.abspath(os.getenv("INPUT_PACKAGES_DIR")))
packages_dir = pathlib.Path(sys.argv[1]).resolve().absolute()
file_iterable = packages_dir.iterdir()

print("Showing hash values of files to be uploaded:")

for file in file_list:
print(file)
for file_object in file_iterable:
print(file_object)
print("")

with open(os.path.abspath(os.path.join(os.getenv("INPUT_PACKAGES_DIR"), file)), "rb") as f:
content = f.read()
content = file_object.read_bytes()

sha256.update(content)
md5.update(content)
Expand Down
2 changes: 1 addition & 1 deletion twine-upload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ if [[ ${INPUT_VERBOSE,,} != "false" ]] ; then
fi

if [[ ${INPUT_PRINT_HASH,,} != "false" || ${INPUT_VERBOSE,,} != "false" ]] ; then
python /app/print-hash.py
python /app/print-hash.py "${INPUT_PACKAGES_DIR%%/}"
fi

TWINE_USERNAME="$INPUT_USER" \
Expand Down

0 comments on commit 0575dc8

Please # to comment.