Skip to content

Commit

Permalink
fixing pair-tree path
Browse files Browse the repository at this point in the history
  • Loading branch information
liseli committed Jun 19, 2024
1 parent 50f16a8 commit e1f012c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ht_document/ht_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ def get_document_pairtree_path(self):
# sanitized_obj_id_translated = self.file_name.translate(TRANSLATE_TABLE)

# source_path = f"{SDR_DIR}/{self.namespace}/pairtree_root{doc_translated_path}/{sanitized_obj_id_translated}"
doc_path = f"{doc_translated_path}/{self.file_name}"
doc_path = f"{doc_pairtree_path}/{self.file_name}"

return doc_path
10 changes: 6 additions & 4 deletions ht_document/ht_document_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def test_get_namespace():


def test_get_object_id():
namespace = HtDocument.get_object_id("uc2.ark:/13960/t4mk66f1d")
assert namespace == "ark:/13960/t4mk66f1d"
object_id = HtDocument.get_object_id("uc2.ark:/13960/t4mk66f1d")
assert object_id == "ark:/13960/t4mk66f1d"


def test_colon_name_pattern():
Expand All @@ -47,8 +47,10 @@ def test_colon_name_pattern():
ht_doc = HtDocument(document_id="coo1.ark:/13960/t57d3f780", document_repository="pairtree")

doc_path = ht_doc.get_document_pairtree_path()
assert doc_path == r"/ar/k+/\=1/39/60/\=t/57/d3/f7/80/ark+\=13960\=t57d3f780/ark+=13960=t57d3f780"
assert r"/sdr1/obj/coo1/pairtree_root/ar/k+/\=1/39/60/\=t/57/d3/f7/80/ark+\=13960\=t57d3f780/ark+=13960=t57d3f780" == ht_doc.source_path
assert doc_path == "/ar/k+/=1/39/60/=t/57/d3/f7/80/ark+=13960=t57d3f780/ark+=13960=t57d3f780"

# source_path includes the name of the file
assert "/sdr1/obj/coo1/pairtree_root/ar/k+/=1/39/60/=t/57/d3/f7/80/ark+=13960=t57d3f780/ark+=13960=t57d3f780" == ht_doc.source_path


def test_document_several_points():
Expand Down
21 changes: 19 additions & 2 deletions ht_utils/ht_pairtree.py → ht_document/ht_pairtree.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
import inspect
import os
import subprocess
import sys

current = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parent = os.path.dirname(current)
sys.path.insert(0, parent)

from pathlib import Path

from ht_document.ht_document import HtDocument
from ht_utils.ht_logger import get_ht_logger

logger = get_ht_logger(name=__name__)


def download_document_file(
source_path: str = None, target_path: str = None, extension: str = "zip"
ht_id: str = None, target_path: str = None, extension: str = "zip"
):
os.environ["SDR_DIR"] = '/sdr1/obj'

ht_doc = HtDocument(document_id=ht_id, document_repository="pairtree")
source_path = ht_doc.source_path
try:
public_key = os.environ["PUBLIC_KEY"]
except KeyError:
Expand All @@ -35,4 +47,9 @@ def download_document_file(
f"{target_path}.{extension}",
]
subprocess.run(command)
logger.info(f"Download {source_path}.{extension} to {target_path}")
print(f"Download {source_path}.{extension} to {target_path}")


if __name__ == "__main__":
download_document_file(ht_id="coo1.ark:/13960/t57d3f780", target_path=str(Path(__file__).parents[1]),
extension="zip")

0 comments on commit e1f012c

Please sign in to comment.