Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sams-classes
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
coding-at-fu
sams-classes
Commits
47c7bbb5
Commit
47c7bbb5
authored
8 years ago
by
Sebastian Lobinger
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sams_classes/sams_hub.py
+84
-0
84 additions, 0 deletions
sams_classes/sams_hub.py
with
84 additions
and
0 deletions
sams_classes/sams_hub.py
0 → 100644
+
84
−
0
View file @
47c7bbb5
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment