Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update rml_mapper.py #470

Merged
merged 1 commit into from
Mar 28, 2023
Merged
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
16 changes: 13 additions & 3 deletions ted_sws/notice_transformer/adapters/rml_mapper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import abc
import os
import signal
import subprocess
from enum import Enum
from pathlib import Path
Expand Down Expand Up @@ -91,8 +93,16 @@ def execute(self, package_path: Path) -> str:
"""
# java -jar ./rmlmapper.jar -m rml.ttl -s turtle -o output.ttl
bash_script = f"cd {package_path} && java -jar {self.rml_mapper_path} -m {package_path / MS_TRANSFORM_FOLDER_NAME / MS_MAPPINGS_FOLDER_NAME / '*'} -s {self.get_serialization_format_value()}"
script_result = subprocess.run(bash_script, shell=True, capture_output=True, timeout=self.transformation_timeout)
error = script_result.stderr.decode('utf-8')
process = subprocess.Popen(bash_script, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, start_new_session=True)
if self.transformation_timeout:
try:
process.wait(timeout=self.transformation_timeout)
except subprocess.TimeoutExpired as e:
os.killpg(os.getpgid(process.pid), signal.SIGTERM)
raise e
output, error = process.communicate()
error = error.decode(encoding="utf-8")
if error:
raise Exception(error)
return script_result.stdout.decode('utf-8')
return output.decode(encoding="utf-8")