reorganize debug messages

This commit is contained in:
boyska 2024-11-17 00:28:42 +01:00
parent b31f50a27f
commit 982b10cc97

View file

@ -74,7 +74,7 @@ class ArchiveBackend(RcloneBackend):
def exists(self, destination_path: bytes):
return False
def copy(self, filename: Path, destination_path: bytes):
def copy(self, filename: Path, destination_path: bytes) -> str:
"""
destination_path is ignored
"""
@ -83,9 +83,8 @@ class ArchiveBackend(RcloneBackend):
bucketbase = f"{self.bucketprefix}-" + bucketbase
bucketname = bucketbase
auth = {"authorization": f"LOW {self.accesskey}:{self.secret}"}
print(auth)
for attempt in range(5):
print("trying", bucketname)
LOG.debug("trying %s", bucketname)
resp = requests.put(
f"https://s3.us.archive.org/{bucketname}",
headers=auth,
@ -93,14 +92,13 @@ class ArchiveBackend(RcloneBackend):
try:
resp.raise_for_status()
except requests.HTTPError:
print(resp.request.headers)
bucketname = f"{bucketbase}-{attempt + 1}"
continue
else:
break
else:
raise ValueError("could not find a good bucket for ")
print("Found good bucket: %s", bucketname)
LOG.info("Found good bucket: %s", bucketname)
url = f"https://s3.us.archive.org/{bucketname}/{filename.name}"
# XXX: set some more header based on file metadata (date, title, etc.)
@ -115,7 +113,9 @@ class ArchiveBackend(RcloneBackend):
headers={**headers, **auth},
)
resp.raise_for_status()
return f"https://archive.org/download/{bucketname}/{filename.name}"
dl_url = f"https://archive.org/download/{bucketname}/{filename.name}"
LOG.info("loaded on %s", dl_url)
return dl_url
class ArkiwiBackend(RcloneBackend):