From 3a0d5aa439389a42d1fc0cdcefdae2fe597c3e56 Mon Sep 17 00:00:00 2001 From: adi0509 Date: Wed, 7 Jul 2021 17:49:02 +0530 Subject: This patch will allow user to pass PDF file as an URL or a file path Signed-off-by: Adarsh Yadav Change-Id: I01a211e6a44ab57aaf8e9e4d21eca2e91791646d --- sdv/docker/sdvstate/core/load_pdf.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/sdv/docker/sdvstate/core/load_pdf.py b/sdv/docker/sdvstate/core/load_pdf.py index 6ce22f0..fa2bf7e 100644 --- a/sdv/docker/sdvstate/core/load_pdf.py +++ b/sdv/docker/sdvstate/core/load_pdf.py @@ -18,6 +18,8 @@ import json import yaml +import requests +import os from tools.conf import settings @@ -25,9 +27,21 @@ def load_pdf(): """ Updates settings with PDF data """ - filename = settings.getValue('pdf_file') - with open(filename) as handle: - data = handle.read() + path = settings.getValue('pdf_file') + data="" + if os.path.exists(path): + with open(path) as handle: + data = handle.read() + else: + if (path.find("github.com") != -1): + path = path.replace("github.com", "raw.githubusercontent.com") + path = path.replace("/blob", "") + try: + resp = requests.get(path) + if resp.status_code == requests.codes.ok: + data = resp.text + except: + raise Exception(f"Invalid path: {path}") try: pdf = json.loads(data) @@ -35,6 +49,6 @@ def load_pdf(): try: pdf = yaml.safe_load(data) except yaml.parser.ParserError: - raise Exception(f"Invalid PDF file: {filename}") + raise Exception(f"Invalid PDF file: {path}") settings.setValue('pdf_file', pdf) -- cgit 1.2.3-korg