Skip to content
Snippets Groups Projects
Commit 47c7bbb5 authored by Sebastian Lobinger's avatar Sebastian Lobinger
Browse files

rename sams_classes/cls_sams_hub.py to sams_classes/sams_hub.py

parent 72471e8c
No related branches found
No related tags found
No related merge requests found
from flask import Blueprint, Flask, session
import os, sys
from .exceptions import (
ManifestDefaultLanguageMissing
, DefaultLanguageDictMissing
, AppNotExist
)
from typing import Dict, List
from importlib import import_module
#from .exceptions import HubDirNotExist, FunctionNotExists
#from importlib import import_module
from .cls_sams_app import SAMSApp
class SAMSHub:
def __init__(self, name: str, config: dict):
if not config.get('default_language'):
raise TypeError(
'Parameter config musst contain a value for "default_language"')
self._apps = {}
def addApp(self, app: SAMSApp = None):
if not isinstance(app, SAMSApp):
raise TypeError('Argument app has to be a SAMSApp.')
self._apps[app.name] = app;
@property
def appKeys(self):
return self._apps.keys()
def app(self, name):
try:
return self._apps[name]
except:
raise AppNotExist
def __modules_yaml(self):
try:
ymlFile = open(os.path.join(self.__confDir, 'modules.yaml'), 'r')
modules = yaml.load(ymlFile)
ymlFile.close()
except IOError as err:
modules = []
return modules
def __add_urls(self, module):
for view in self.__manifests[module].get('views', []):
pathElements = [module]
if view['url']:
pathElements.append(view['url'])
rule = '/' + '/'.join(pathElements)
endpoint = '_'.join(view['function'].split('.'))
view_func = self.__get_attr(self.__modules[module], view['function'])
self.__blueprints[module].add_url_rule(rule = rule, endpoint = endpoint
, view_func = view_func)
def load_language(self, module = None):
pass
@staticmethod
def _load_from_yaml(path):
with open(path) as f:
return yaml.load(f)
@staticmethod
def _get_module_rule(module, path):
pathElements = [module]
if path:
pathElements.append(path)
return '/' + '/'.join(pathElements)
@staticmethod
def _get_attr(object, attrString):
attr = None
try:
return getattr(object, attrString)
except AttributeError:
pass
attrList = attrString.split('.')
if len(attrList) <= 1:
raise FunctionNotExists('The function ' + attrString + ' does not exist')
return(
SAMSHub._get_attr(getattr(object, attrList[0]), '.'.join(attrList[1:]))
)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment