Skip to content

Commit

Permalink
fix(start-stack): fix outdated TTL paths, open config file correctly (D…
Browse files Browse the repository at this point in the history
  • Loading branch information
jnussbaum committed Jul 27, 2023
1 parent e03d633 commit 98e0579
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/dsp_tools/fast_xmlupload/upload_files.py
Expand Up @@ -131,7 +131,7 @@ def _upload_without_processing(
# This error can be safely ignored, since the file was uploaded correctly.
logger.info(f"In spite of 'server.fs.mkdir() failed: File exists', successfully uploaded file {file}")
elif response_upload.status_code != 200:
err_msg = f"An error occurred while uploading the file {file}. The response was {response_upload.json()}"
err_msg = f"An error occurred while uploading the file {file}. The response was {vars(response_upload)}"
print(f"{datetime.now()}: ERROR: {err_msg}")
logger.error(err_msg)
return False
Expand Down
2 changes: 1 addition & 1 deletion src/dsp_tools/resources/start-stack/start-stack-config.yml
@@ -1,4 +1,4 @@
---

# take commit hash of latest DSP-API release from https://github.com/dasch-swiss/dsp-api/commits/main
DSP-API commit: 746b3ba1878225831d836dcfe34fa71da3890077
DSP-API commit: 00f62564a8693d168f0e11be6390bb61d9c192df
26 changes: 16 additions & 10 deletions src/dsp_tools/utils/stack_handling.py
Expand Up @@ -82,16 +82,17 @@ def _get_url_prefix(self) -> str:
if self.__stack_configuration.latest_dev_version:
return f"{url_prefix_base}/main/"

config_file = Path("src/dsp_tools/resources/start-stack/start-stack-config.yml")
config_file = importlib.resources.files("dsp_tools").joinpath("resources/start-stack/start-stack-config.yml")
if not config_file.is_file():
return f"{url_prefix_base}/main/"

with open("src/dsp_tools/resources/start-stack/start-stack-config.yml", "r", encoding="utf-8") as f:
with config_file.open("r", encoding="utf-8") as f:
try:
start_stack_config = yaml.safe_load(f)
except yaml.YAMLError:
start_stack_config = {}
commit_of_used_api_version = start_stack_config.get("DSP-API commit", "main")

return f"{url_prefix_base}/{commit_of_used_api_version}/"

def _copy_resources_to_home_dir(self) -> None:
Expand Down Expand Up @@ -148,7 +149,7 @@ def _start_up_fuseki(self) -> None:
)
if not completed_process or completed_process.returncode != 0:
msg = "Cannot start the API: Error while executing 'docker compose up db -d'"
logger.error(f"{msg}. completed_process = '{completed_process}'")
logger.error(f"{msg}. completed_process = '{vars(completed_process)}'")
raise UserError(msg)

def _wait_for_fuseki(self) -> None:
Expand Down Expand Up @@ -189,7 +190,7 @@ def _create_knora_test_repo(self) -> None:
"Cannot start DSP-API: Error when creating the 'knora-test' repository. "
"Is DSP-API perhaps running already?"
)
logger.error(f"{msg}. response = {response}")
logger.error(f"{msg}. response = {vars(response)}")
raise UserError(msg)

def _load_data_into_repo(self) -> None:
Expand All @@ -208,21 +209,26 @@ def _load_data_into_repo(self) -> None:
("knora-ontologies/standoff-onto.ttl", "http://www.knora.org/ontology/standoff"),
("knora-ontologies/standoff-data.ttl", "http://www.knora.org/data/standoff"),
("knora-ontologies/salsah-gui.ttl", "http://www.knora.org/ontology/salsah-gui"),
("test_data/all_data/admin-data.ttl", "http://www.knora.org/data/admin"),
("test_data/all_data/permissions-data.ttl", "http://www.knora.org/data/permissions"),
("test_data/ontologies/anything-onto.ttl", "http://www.knora.org/ontology/0001/anything"),
("test_data/all_data/anything-data.ttl", "http://www.knora.org/data/0001/anything"),
("test_data/project_data/admin-data.ttl", "http://www.knora.org/data/admin"),
("test_data/project_data/permissions-data.ttl", "http://www.knora.org/data/permissions"),
("test_data/project_ontologies/anything-onto.ttl", "http://www.knora.org/ontology/0001/anything"),
("test_data/project_data/anything-data.ttl", "http://www.knora.org/data/0001/anything"),
]
for ttl_file, graph in ttl_files:
ttl_text = requests.get(self.__url_prefix + ttl_file, timeout=10).text
ttl_text_response = requests.get(self.__url_prefix + ttl_file, timeout=10)
if not ttl_text_response.ok:
msg = f"Cannot start DSP-API: Error when retrieving '{self.__url_prefix + ttl_file}'"
logger.error(f"{msg}'. response = {vars(ttl_text_response)}")
raise UserError(msg)
ttl_text = ttl_text_response.text
response = requests.post(
url=graph_prefix + graph,
files={"file": ("file.ttl", ttl_text, "text/turtle; charset: utf-8")},
auth=("admin", "test"),
timeout=10,
)
if not response.ok:
logger.error(f"Cannot start DSP-API: Error when creating graph '{graph}'. response = {response}")
logger.error(f"Cannot start DSP-API: Error when creating graph '{graph}'. response = {vars(response)}")
raise UserError(f"Cannot start DSP-API: Error when creating graph '{graph}'")

def _initialize_fuseki(self) -> None:
Expand Down

0 comments on commit 98e0579

Please sign in to comment.