Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
clinicaltrials
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
david Chavalarias
clinicaltrials
Commits
946ed3f7
Commit
946ed3f7
authored
Dec 13, 2016
by
Romain Loth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
config reader for previous commit
parent
04ed7892
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
0 deletions
+71
-0
comex_main_backend.py
services/comex_main_backend.py
+1
-0
tools.py
services/tools.py
+70
-0
No files found.
services/comex_main_backend.py
View file @
946ed3f7
...
@@ -184,6 +184,7 @@ def one_big_form():
...
@@ -184,6 +184,7 @@ def one_big_form():
# A) DB config + connection
# A) DB config + connection
reg_db
=
connect
(
reg_db
=
connect
(
host
=
config
[
'SQL_HOST'
],
host
=
config
[
'SQL_HOST'
],
port
=
int
(
config
[
'SQL_PORT'
]),
user
=
"root"
,
# TODO change db ownership to a comexreg user
user
=
"root"
,
# TODO change db ownership to a comexreg user
passwd
=
"very-safe-pass"
,
passwd
=
"very-safe-pass"
,
db
=
"comex_shared"
db
=
"comex_shared"
...
...
services/tools.py
0 → 100644
View file @
946ed3f7
"""
utility functions
"""
__author__
=
"CNRS"
__copyright__
=
"Copyright 2016 ISCPIF-CNRS"
__email__
=
"romain.loth@iscpif.fr"
from
configparser
import
ConfigParser
from
os
import
environ
,
path
CONFIGMENU
=
[
{
"sec"
:
'main'
,
"var"
:
'DEBUG_FLAG'
,
"def"
:
True
},
{
"sec"
:
'main'
,
"var"
:
'COMEX_HOST'
,
"def"
:
'0.0.0.0'
},
{
"sec"
:
'main'
,
"var"
:
'COMEX_PORT'
,
"def"
:
'9090'
},
{
"sec"
:
'routes'
,
"var"
:
'USR_PREFIX'
,
"def"
:
'/regcomex'
},
{
"sec"
:
'services'
,
"var"
:
'SQL_HOST'
,
"def"
:
'172.17.0.2'
},
{
"sec"
:
'services'
,
"var"
:
'SQL_PORT'
,
"def"
:
'3306'
},
{
"sec"
:
'services'
,
"var"
:
'DOORS_HOST'
,
"def"
:
'0.0.0.0'
},
{
"sec"
:
'services'
,
"var"
:
'DOORS_PORT'
,
"def"
:
'8989'
}
]
def
home_path
():
"""
we are in ./services so project home is the dirname of the parent
"""
return
path
.
dirname
(
path
.
dirname
(
path
.
realpath
(
__file__
)))
def
read_config
():
"""
reads all global config vars trying in order:
1) the config file $HOME/parametres_comex.ini
2) env variables of the same name
3) hard-coded default values
output is a simple dict
"""
out_dict
=
{}
our_home
=
home_path
()
ini
=
ConfigParser
()
ini
.
read
(
path
.
join
(
our_home
,
"parametres_comex.ini"
))
# debug sections
# print("ini sections:", [sec for sec in ini.keys()])
# read ini file and use 2 fallbacks: env or default
for
citem
in
CONFIGMENU
:
section
=
citem
[
'sec'
]
varname
=
citem
[
'var'
]
default
=
citem
[
'def'
]
is_bool
=
(
type
(
default
)
==
bool
)
if
section
in
ini
and
varname
in
ini
[
section
]:
if
is_bool
:
out_dict
[
varname
]
=
ini
.
getboolean
(
section
,
varname
)
else
:
out_dict
[
varname
]
=
ini
.
get
(
section
,
varname
)
elif
varname
in
environ
:
if
is_bool
:
out_dict
[
varname
]
=
(
environ
[
varname
]
==
'true'
)
else
:
out_dict
[
varname
]
=
environ
[
varname
]
else
:
out_dict
[
varname
]
=
default
# also add our project home since we have it and we'll need it
out_dict
[
'HOME'
]
=
our_home
return
out_dict
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment