From ab6cf52533c29b7c5815c94c8c27ca60b32f8ad7 Mon Sep 17 00:00:00 2001 From: msramalho <19508417+msramalho@users.noreply.github.com> Date: Mon, 10 Feb 2025 16:45:28 +0000 Subject: [PATCH 1/2] fixes bad hash initialization --- src/auto_archiver/modules/hash_enricher/hash_enricher.py | 8 ++++---- src/auto_archiver/utils/misc.py | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/auto_archiver/modules/hash_enricher/hash_enricher.py b/src/auto_archiver/modules/hash_enricher/hash_enricher.py index b3ca8be..7a0587c 100644 --- a/src/auto_archiver/modules/hash_enricher/hash_enricher.py +++ b/src/auto_archiver/modules/hash_enricher/hash_enricher.py @@ -30,10 +30,10 @@ class HashEnricher(Enricher): to_enrich.media[i].set("hash", f"{self.algorithm}:{hd}") def calculate_hash(self, filename) -> str: - hash = None + hash_algo = None if self.algorithm == "SHA-256": - hash = hashlib.sha256() + hash_algo = hashlib.sha256 elif self.algorithm == "SHA3-512": - hash = hashlib.sha3_512() + hash_algo = hashlib.sha3_512 else: return "" - return calculate_file_hash(filename, hash, self.chunksize) + return calculate_file_hash(filename, hash_algo, self.chunksize) diff --git a/src/auto_archiver/utils/misc.py b/src/auto_archiver/utils/misc.py index 3af5a54..4d48372 100644 --- a/src/auto_archiver/utils/misc.py +++ b/src/auto_archiver/utils/misc.py @@ -65,10 +65,11 @@ def json_loader(cli_val): return json.loads(cli_val) -def calculate_file_hash(filename: str, hash_algo = hashlib.sha256(), chunksize: int = 16000000) -> str: +def calculate_file_hash(filename: str, hash_algo = hashlib.sha256, chunksize: int = 16000000) -> str: + hash = hash_algo() with open(filename, "rb") as f: while True: buf = f.read(chunksize) if not buf: break - hash_algo.update(buf) - return hash_algo.hexdigest() + hash.update(buf) + return hash.hexdigest() From 12f14cccc933d44b02906b2b9e239d1dd98af036 Mon Sep 17 00:00:00 2001 From: msramalho <19508417+msramalho@users.noreply.github.com> Date: Mon, 10 Feb 2025 16:58:35 +0000 Subject: [PATCH 2/2] fixes gsheet feeder<->db connection via context. --- src/auto_archiver/core/storage.py | 2 +- src/auto_archiver/modules/gsheet_feeder/gsheet_feeder.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/auto_archiver/core/storage.py b/src/auto_archiver/core/storage.py index 9f355f6..5dfa39d 100644 --- a/src/auto_archiver/core/storage.py +++ b/src/auto_archiver/core/storage.py @@ -1,6 +1,6 @@ from __future__ import annotations from abc import abstractmethod -from typing import IO, Optional +from typing import IO import os from loguru import logger diff --git a/src/auto_archiver/modules/gsheet_feeder/gsheet_feeder.py b/src/auto_archiver/modules/gsheet_feeder/gsheet_feeder.py index d129182..1b81385 100644 --- a/src/auto_archiver/modules/gsheet_feeder/gsheet_feeder.py +++ b/src/auto_archiver/modules/gsheet_feeder/gsheet_feeder.py @@ -68,7 +68,7 @@ class GsheetsFeeder(Feeder): folder = os.path.join(folder, slugify(self.sheet), slugify(wks.title)) m.set_context('folder', folder) - m.set_context('worksheet', {"row": row, "worksheet": gw}) + m.set_context('gsheet', {"row": row, "worksheet": gw}) yield m logger.success(f'Finished worksheet {wks.title}')