From 24609374fa9881467a6fa9f7b6924daec9534ddf Mon Sep 17 00:00:00 2001 From: Ivan Subotic Date: Fri, 22 Mar 2019 13:12:39 +0100 Subject: [PATCH] fix: add folder independence --- knora/create_ontology.py | 7 +++++-- knora/knora.py | 24 ++++++++++++++---------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/knora/create_ontology.py b/knora/create_ontology.py index ff4fde234..8ec69ec4c 100644 --- a/knora/create_ontology.py +++ b/knora/create_ontology.py @@ -1,3 +1,4 @@ +import os from typing import List, Set, Dict, Tuple, Optional from pprint import pprint import argparse @@ -17,12 +18,14 @@ def main(): args = parser.parse_args() + current_dir = os.path.dirname(os.path.realpath(__file__)) + # let's read the schema for the ontology definition if args.lists: - with open('knora-schema-lists.json') as s: + with open(os.path.join(current_dir, 'knora-schema-lists.json')) as s: schema = json.load(s) else: - with open('knora-schema.json') as s: + with open(os.path.join(current_dir, 'knora-schema.json')) as s: schema = json.load(s) # read the ontology definition diff --git a/knora/knora.py b/knora/knora.py index 48a3a9075..03a2b2baa 100755 --- a/knora/knora.py +++ b/knora/knora.py @@ -92,9 +92,9 @@ class knora: def __init__(self, server: str, email: str, password: str, prefixes: Dict[str,str] = None): """ Constructor requiring the server address, the user and password of KNORA - :param server: Adress of the server, e.g http://data.dasch.swiss - :param user: Username for Knora e.g., root@example.com - :param password: The password, e.g. test + :param server: Address of the server, e.g http://data.dasch.swiss + :param email: Email of user, e.g., root@example.com + :param password: Password of the user, e.g. test """ self.server = server self.prefixes = prefixes @@ -105,23 +105,27 @@ def __init__(self, server: str, email: str, password: str, prefixes: Dict[str,st } jsondata = json.dumps(credentials) - req = requests.post(self.server + '/v2/authentication', - headers={'Content-Type': 'application/json; charset=UTF-8'}, - data=jsondata) + req = requests.post( + self.server + '/v2/authentication', + headers={'Content-Type': 'application/json; charset=UTF-8'}, + data=jsondata + ) + self.on_api_error(req) result = req.json() self.token = result["token"] def __del__(self): - req = requests.delete(self.server + '/v2/authentication', - headers={'Authorization': 'Bearer ' + self.token}) - result = req.json() + req = requests.delete( + self.server + '/v2/authentication', + headers={'Authorization': 'Bearer ' + self.token} + ) + result = req.json() pprint.pprint(result) - def on_api_error(self, res): """ Method to check for any API errors