Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
Notification system
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
17
Issues
17
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Turris
Notification system
Commits
3eaddc35
Verified
Commit
3eaddc35
authored
Feb 08, 2019
by
Martin Matějek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable passing user config values as dictionary
parent
3f0113f8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
4 deletions
+10
-4
notifylib/api.py
notifylib/api.py
+6
-3
notifylib/config.py
notifylib/config.py
+4
-1
No files found.
notifylib/api.py
View file @
3eaddc35
...
...
@@ -22,9 +22,12 @@ logger = logging.getLogger(__name__)
class
Api
:
"""Public interface of module"""
def
__init__
(
self
,
conf
=
None
):
if
conf
:
# override default config
config
.
load_config
(
conf
)
def
__init__
(
self
,
conffile
=
None
,
confdict
=
None
):
# override default config
if
conffile
:
config
.
load_from_file
(
conffile
)
elif
confdict
:
config
.
load_from_dict
(
confdict
)
plugin_dir
=
config
.
get
(
'settings'
,
'plugin_dir'
)
volatile_dir
=
config
.
get
(
'settings'
,
'volatile_dir'
)
...
...
notifylib/config.py
View file @
3eaddc35
...
...
@@ -16,7 +16,7 @@ class Config:
self
.
conf
.
set
(
"settings"
,
"plugin_dir"
,
"plugins"
)
self
.
conf
.
set
(
"settings"
,
"cmd_timeout"
,
"10"
)
def
load_
config
(
self
,
filename
):
def
load_
from_file
(
self
,
filename
):
try
:
with
open
(
filename
,
'r'
)
as
f
:
self
.
conf
.
read_file
(
f
)
...
...
@@ -24,6 +24,9 @@ class Config:
logger
.
warning
(
"Failed to open config file '{}'"
.
format
(
filename
))
# TODO: handle configparser exceptions
def
load_from_dict
(
self
,
dictionary
):
self
.
conf
.
read_dict
(
dictionary
)
def
get
(
self
,
section
,
key
):
return
self
.
conf
.
get
(
section
,
key
)
...
...
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