Skip to content

Commit

Permalink
Merge pull request #365 Version 0.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Mec-iS committed Mar 18, 2019
2 parents 5fa4a68 + c6e11f4 commit a5a5cf1
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 148 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,6 @@ ENV/

# Keys
*.pem

# Pipenv generated
Pipfile*
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ FROM tiangolo/uwsgi-nginx-flask:flask-python3.5-index-upload
MAINTAINER Akshay Dahiya <xadahiya@gmail.com>

COPY ./requirements.txt requirements.txt
RUN pip install -U pip && pip install -r requirements.txt && rm -rf *
RUN pip install -U pip && pip install --upgrade pip setuptools \
&& pip install -r requirements.txt && rm -rf *

COPY . /app

Expand Down
4 changes: 2 additions & 2 deletions cli.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session

from hydrus.app import app_factory
from hydrus.app_factory import app_factory
from hydrus.utils import (set_session, set_doc, set_hydrus_server_url,
set_token, set_api_name, set_authentication)
from hydrus.data import doc_parse
from hydra_python_core import doc_maker
from hydrus.data.db_models import Base
from hydrus.data.user import add_user
from gevent.pywsgi import WSGIServer
from hydrus.parser.openapi_parser import parse
from hydra_openapi_parser.openapi_parser import parse
from hydrus.samples.hydra_doc_sample import doc as api_document
from importlib.machinery import SourceFileLoader
from typing import Tuple
Expand Down
10 changes: 5 additions & 5 deletions hydrus/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ def verify_user() -> Union[Response, None]:
auth = check_authorization(request, get_session())
if auth is False:
return failed_authentication(True)
else:
if get_token():
token = add_token(request, get_session())
return token_response(token)
elif get_token():
token = add_token(request, get_session())
return token_response(token)
except Exception as e:
status_code, message = e.get_HTTP() # type: ignore
return set_response_headers(jsonify(message), status_code=status_code)
Expand All @@ -70,4 +69,5 @@ def check_authentication_response() -> Union[Response, None]:
return failed_authentication(False)
else:
return verify_user()
return None
else:
return None
35 changes: 17 additions & 18 deletions hydrus/data/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,10 @@ def insert(object_: Dict[str, Any], session: scoped_session,
RDFClass.name == object_["@type"]).one()
except NoResultFound:
raise ClassNotFound(type_=object_["@type"])
if id_ is not None:
if session.query(exists().where(Instance.id == id_)).scalar():
raise InstanceExists(type_=rdf_class.name, id_=id_)
else:
instance = Instance(id=id_, type_=rdf_class.id)
if id_ is not None and session.query(exists().where(Instance.id == id_)).scalar():
raise InstanceExists(type_=rdf_class.name, id_=id_)
elif id_ is not None:
instance = Instance(id=id_, type_=rdf_class.id)
else:
instance = Instance(type_=rdf_class.id)
session.add(instance)
Expand Down Expand Up @@ -211,20 +210,20 @@ def insert(object_: Dict[str, Any], session: scoped_session,
raise NotInstanceProperty(type_=prop_name)

# For insertion in IAC
elif session.query(exists().where(RDFClass.name == str(object_[prop_name]))).scalar() \
and property_.type_ == "PROPERTY" or property_.type_ == "ABSTRACT":
property_.type_ = "ABSTRACT"
session.add(property_)
class_ = session.query(RDFClass).filter(
RDFClass.name == object_[prop_name]).one()
triple = GraphIAC(
subject=instance.id,
predicate=property_.id,
object_=class_.id)
session.add(triple)
elif session.query(exists().where(RDFClass.name == str(object_[prop_name]))).scalar():
if property_.type_ == "PROPERTY" or property_.type_ == "ABSTRACT":
property_.type_ = "ABSTRACT"
session.add(property_)
class_ = session.query(RDFClass).filter(
RDFClass.name == object_[prop_name]).one()
triple = GraphIAC(
subject=instance.id,
predicate=property_.id,
object_=class_.id)
session.add(triple)
else:
session.close()
raise NotAbstractProperty(type_=prop_name)
session.close()
raise NotAbstractProperty(type_=prop_name)

# For insertion in IIT
else:
Expand Down
8 changes: 4 additions & 4 deletions hydrus/data/doc_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ def insert_classes(classes: List[Dict[str, Any]],
not session.query(exists().where(RDFClass.name == class_["label"]
.strip('.'))).scalar()]

class_list = class_list + [RDFClass(name=class_["title"].strip('.')) for class_ in classes
if "title" in class_ and
not session.query(exists().where(RDFClass.name == class_["title"]
.strip('.'))).scalar()]
class_list.extend([RDFClass(name=class_["title"].strip('.')) for class_ in classes
if "title" in class_ and
not session.query(exists().where(RDFClass.name == class_["title"]
.strip('.'))).scalar()])
# print(class_list)
session.add_all(class_list)
session.commit()
Expand Down
Loading

0 comments on commit a5a5cf1

Please sign in to comment.