From 0575dc8eab29bdb32fdc059da3f8ac7a22a26fb7 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Sun, 9 Jan 2022 00:24:29 +0100 Subject: [PATCH] Refactor the hash helper script to use pathlib and CLI args --- print-hash.py | 13 +++++++------ twine-upload.sh | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/print-hash.py b/print-hash.py index 144ae57..8b0ee98 100755 --- a/print-hash.py +++ b/print-hash.py @@ -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) diff --git a/twine-upload.sh b/twine-upload.sh index 2a9b546..31da635 100755 --- a/twine-upload.sh +++ b/twine-upload.sh @@ -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" \