Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Scientific Software
MDANSE
Commits
7831fa64
Commit
7831fa64
authored
Jul 09, 2015
by
eric pellegrini
Browse files
Fused the configurators and configuration
parent
1472708f
Changes
1
Hide whitespace changes
Inline
Side-by-side
MDANSE/Framework/Configurable.py
View file @
7831fa64
...
...
@@ -61,21 +61,24 @@ class Configurable(object):
Constructor
'''
self
.
_configuration
=
{}
self
.
_configuration
=
self
.
build_configuration
()
self
.
_configured
=
False
if
not
isinstance
(
self
.
settings
,
dict
):
raise
ConfigurationError
(
"Invalid type for settings: must be a mapping-like object"
)
self
.
_configurators
=
{}
for
name
,(
typ
,
kwds
)
in
self
.
settings
.
items
():
@
classmethod
def
build_configuration
(
cls
):
configuration
=
collections
.
OrderedDict
()
for
name
,(
typ
,
kwds
)
in
cls
.
settings
.
items
():
try
:
self
.
_
configurat
ors
[
name
]
=
REGISTRY
[
"configurator"
][
typ
](
name
,
**
kwds
)
configurat
ion
[
name
]
=
REGISTRY
[
"configurator"
][
typ
](
name
,
**
kwds
)
# Any kind of error has to be caught
except
:
raise
ConfigurationError
(
"Invalid type for %r configurator"
%
name
)
self
.
_
configur
ed
=
False
return
configur
ation
def
__getitem__
(
self
,
name
):
"""
...
...
@@ -88,15 +91,7 @@ class Configurable(object):
"""
return
self
.
_configuration
.
setdefault
(
name
,{})
@
classmethod
def
set_settings
(
cls
,
settings
):
cls
.
settings
.
clear
()
if
isinstance
(
settings
,
dict
):
cls
.
settings
.
update
(
settings
)
@
property
def
configuration
(
self
):
'''
...
...
@@ -116,33 +111,30 @@ class Configurable(object):
:type parameters: dict
'''
# Cleans the previous configuration
self
.
_configuration
.
clear
()
self
.
_configured
=
False
# If no configurator has to be configured, just return
if
not
self
.
_configurat
ors
:
if
not
self
.
_configurat
ion
:
self
.
_configured
=
True
return
if
isinstance
(
parameters
,
dict
):
# Loop over the configuration items
for
k
,
v
in
self
.
_configurat
ors
.
items
():
for
k
,
v
in
self
.
_configurat
ion
.
items
():
# If no input parameter has been set for this item, use its default value.
if
not
parameters
.
has_key
(
k
):
parameters
[
k
]
=
v
.
default
else
:
raise
ConfigurationError
(
"Invalid type for configuration parameters"
)
toBeConfigured
=
set
(
self
.
_configurat
ors
.
keys
())
toBeConfigured
=
set
(
self
.
_configurat
ion
.
keys
())
configured
=
set
()
while
toBeConfigured
!=
configured
:
progress
=
False
for
name
,
conf
in
self
.
_configurat
ors
.
items
():
for
name
,
conf
in
self
.
_configurat
ion
.
items
():
if
name
in
configured
:
continue
...
...
@@ -174,11 +166,11 @@ class Configurable(object):
return
"Not yet configured"
info
=
[]
for
configurator
in
self
.
_configurators
.
keys
():
for
configurator
in
self
.
_configuration
.
values
():
info
.
append
(
configurator
.
get_information
())
info
.
append
(
'
\n
'
)
info
.
append
(
self
.
_configuration
[
configurator
].
get_information
())
return
"
\n
"
.
join
(
info
)
return
""
.
join
(
info
)
@
classmethod
def
build_doc
(
cls
):
...
...
@@ -269,14 +261,3 @@ class Configurable(object):
params
[
name
]
=
cfg
.
default
return
params
@
property
def
configurators
(
self
):
'''
Return the configurator objects of this Configurable object
:return: a mapping between the name of the configurator object and its corresponding IConfigurator instance
:rtype: dict
'''
return
self
.
_configurators
\ No newline at end of file
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