Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions hera_librarian/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@ class LibrarianClient:
port: int
user: str
password: str
checksum_threads: int = 1

def __init__(self, host: str, port: int, user: str, password: str):
def __init__(
self, host: str, port: int, user: str, password: str, checksum_threads: int = 1
):
"""
Create a new LibrarianClient.

Expand All @@ -105,6 +108,8 @@ def __init__(self, host: str, port: int, user: str, password: str):
The name of the user.
password : str
The password of the user.
checksum_threads : int
The number of threads to use for checksum computation. Default is 1.
"""

if host[-1] == "/":
Expand All @@ -115,6 +120,7 @@ def __init__(self, host: str, port: int, user: str, password: str):
self.port = port
self.user = user
self.password = password
self.checksum_threads = checksum_threads

def __repr__(self):
return f"Librarian Client ({self.user}) for {self.host}:{self.port}"
Expand Down Expand Up @@ -394,7 +400,9 @@ def upload(
endpoint="upload/stage",
request=UploadInitiationRequest(
upload_size=get_size_from_path(local_path),
upload_checksum=get_checksum_from_path(local_path, threads=1),
upload_checksum=get_checksum_from_path(
local_path, threads=self.checksum_threads
),
upload_name=dest_path.name,
destination_location=dest_path,
uploader=self.user,
Expand Down
12 changes: 2 additions & 10 deletions hera_librarian/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,11 @@ def individual(


def _filehash(filepath, hashfunc):
hasher = hashfunc()
blocksize = 64 * 1024

if not os.path.exists(filepath):
return hasher.hexdigest()
return hashfunc().hexdigest()

with open(filepath, "rb") as fp:
while True:
data = fp.read(blocksize)
if not data:
break
hasher.update(data)
return hasher.hexdigest()
return hashlib.file_digest(fp, hashfunc).hexdigest()


def _reduce_hash(hashlist, hashfunc):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exclude=["*tests*"]
[project]
name="hera_librarian"
requires-python = ">=3.10"
version = "5.0.1"
version = "5.1.0"
dependencies = [
"alembic",
"argon2-cffi",
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_test/test_secondary_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_secondary_server_simple(

response = test_client.post(
"/api/v2/ping",
content=PingRequest().model_dump_json(),
json=PingRequest().model_dump(),
auth=("admin", "password"),
)

Expand Down
Loading