Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PPP-libmodule-Python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Moritz Aurel Pascal Schubotz
PPP-libmodule-Python
Commits
015736cd
Commit
015736cd
authored
10 years ago
by
Valentin Lorentz
Browse files
Options
Downloads
Patches
Plain Diff
Export the Config class so modules can use it instead of reimplementing it.
parent
1e6b3fa8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
ppp_core/__init__.py
+1
-0
1 addition, 0 deletions
ppp_core/__init__.py
ppp_core/config.py
+19
-7
19 additions, 7 deletions
ppp_core/config.py
ppp_core/router.py
+2
-2
2 additions, 2 deletions
ppp_core/router.py
with
22 additions
and
9 deletions
ppp_core/__init__.py
+
1
−
0
View file @
015736cd
"""
Core/router of the Projet Pensées Profondes.
"""
"""
Core/router of the Projet Pensées Profondes.
"""
from
.http
import
app
,
HttpRequestHandler
from
.http
import
app
,
HttpRequestHandler
from
.config
import
Config
This diff is collapsed.
Click to expand it.
ppp_core/config.py
+
19
−
7
View file @
015736cd
...
@@ -19,8 +19,12 @@ class Module(namedtuple('_Module', 'name url coefficient')):
...
@@ -19,8 +19,12 @@ class Module(namedtuple('_Module', 'name url coefficient')):
class
Config
:
class
Config
:
__slots__
=
(
'
debug
'
,
'
modules
'
)
__slots__
=
(
'
debug
'
,)
def
__init__
(
self
,
data
=
None
):
def
__init__
(
self
,
data
=
None
):
if
not
hasattr
(
self
,
'
config_path_variable
'
)
or
\
not
hasattr
(
self
,
'
parse_config
'
):
raise
NotImplementedError
(
'
Config class does not implement all
'
'
required attributes.
'
)
self
.
debug
=
True
self
.
debug
=
True
if
not
data
:
if
not
data
:
try
:
try
:
...
@@ -28,16 +32,23 @@ class Config:
...
@@ -28,16 +32,23 @@ class Config:
data
=
json
.
load
(
fd
)
data
=
json
.
load
(
fd
)
except
ValueError
as
exc
:
except
ValueError
as
exc
:
raise
InvalidConfig
(
*
exc
.
args
)
raise
InvalidConfig
(
*
exc
.
args
)
self
.
modules
=
self
.
_parse_modules
(
data
.
get
(
'
modules
'
,
{}))
self
.
parse_config
(
data
)
self
.
debug
=
data
.
get
(
'
debug
'
,
False
)
@
static
method
@
class
method
def
get_config_path
():
def
get_config_path
(
cls
):
path
=
os
.
environ
.
get
(
'
PPP_CORE_CONFIG
'
,
''
)
path
=
os
.
environ
.
get
(
cls
.
config_path_variable
,
''
)
if
not
path
:
if
not
path
:
raise
InvalidConfig
(
'
Could not find config file, please set
'
raise
InvalidConfig
(
'
Could not find config file, please set
'
'
environment variable $PPP_CORE_CONFIG.
'
)
'
environment variable $%s.
'
%
cls
.
config_path_variable
)
return
path
return
path
class
CoreConfig
(
Config
):
__slots__
=
(
'
modules
'
)
config_path_variable
=
'
PPP_CORE_CONFIG
'
def
parse_config
(
self
,
data
):
self
.
modules
=
self
.
_parse_modules
(
data
.
get
(
'
modules
'
,
{}))
self
.
debug
=
data
.
get
(
'
debug
'
,
False
)
def
_parse_modules
(
self
,
data
):
def
_parse_modules
(
self
,
data
):
modules
=
[]
modules
=
[]
...
@@ -49,3 +60,4 @@ class Config:
...
@@ -49,3 +60,4 @@ class Config:
config
[
'
name
'
])
config
[
'
name
'
])
modules
.
append
(
Module
(
**
config
))
modules
.
append
(
Module
(
**
config
))
return
modules
return
modules
This diff is collapsed.
Click to expand it.
ppp_core/router.py
+
2
−
2
View file @
015736cd
...
@@ -8,7 +8,7 @@ import itertools
...
@@ -8,7 +8,7 @@ import itertools
import
functools
import
functools
from
ppp_datamodel
import
AbstractNode
from
ppp_datamodel
import
AbstractNode
from
ppp_datamodel.communication
import
Request
,
Response
from
ppp_datamodel.communication
import
Request
,
Response
from
.config
import
Config
from
.config
import
Core
Config
from
.exceptions
import
ClientError
,
BadGateway
from
.exceptions
import
ClientError
,
BadGateway
s
=
lambda
x
:
x
if
isinstance
(
x
,
str
)
else
x
.
decode
()
s
=
lambda
x
:
x
if
isinstance
(
x
,
str
)
else
x
.
decode
()
...
@@ -21,7 +21,7 @@ class Router:
...
@@ -21,7 +21,7 @@ class Router:
self
.
tree
=
request
.
tree
self
.
tree
=
request
.
tree
self
.
measures
=
request
.
measures
self
.
measures
=
request
.
measures
self
.
trace
=
request
.
trace
self
.
trace
=
request
.
trace
self
.
config
=
Config
()
self
.
config
=
Core
Config
()
def
answer
(
self
):
def
answer
(
self
):
# First make all requests so modules can prepare their answer
# First make all requests so modules can prepare their answer
...
...
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