From dfe253ed1a22de4534e6ccf1ca9aa826a1637bdf Mon Sep 17 00:00:00 2001 From: John Ferlito Date: Sun, 10 Dec 2023 10:25:44 +1100 Subject: [PATCH] Add validation script and Dockerfile --- Dockerfile | 12 ++++++++++++ src/cli.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 Dockerfile create mode 100644 src/cli.py diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..60550a7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM python:3.9-slim + +WORKDIR /usr/src/app + +COPY src/rocrateValidator/ rocrateValidator/ + +RUN echo "requests\nrocrate" > requirements.txt +RUN pip install --no-cache-dir -r requirements.txt + +COPY src/cli.py . + +ENTRYPOINT ["python", "./cli.py"] diff --git a/src/cli.py b/src/cli.py new file mode 100644 index 0000000..ef0e5f8 --- /dev/null +++ b/src/cli.py @@ -0,0 +1,35 @@ +import sys +import requests +import tempfile +import sys +import os + +sys.path.append(os.path.join(os.path.dirname(__file__), 'rocrateValidator')) + +from rocrateValidator import validate as validate + +def validate_rocrate(source): + if source.startswith('http://') or source.startswith('https://'): + response = requests.get(source) + + if response.status_code != 200: + raise Exception(f"Failed to download RO-Crate from URL: {source}") + + with tempfile.NamedTemporaryFile(mode='wb', delete=True, dir='/tmp') as temp_file: + temp_file.write(response.content) + temp_file.flush() + result = validate.validate(temp_file.name) + else: + # Handle file path + result = validate.validate(source) + + return result + +if __name__ == "__main__": + if len(sys.argv) != 2: + print("Usage: python validate_rocrate.py ") + sys.exit(1) + + source = sys.argv[1] + v = validate_rocrate(source) + v.validator()