Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Paste
P17854
(An Untitled Masterwork)
Active
Public
Actions
Authored by
dcaro
on Nov 25 2021, 3:31 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Flag For Later
Tags
None
Referenced Files
F34767031: raw-paste-data.txt
Nov 25 2021, 3:31 PM
2021-11-25 15:31:21 (UTC+0)
Subscribers
None
@classmethod
def
from_file
(
cls
,
configfile
:
Optional
[
Path
],
overrides
:
Dict
[
str
,
Any
])
->
"ControllerConfig"
:
try
:
data
=
yaml
.
safe_load
(
configfile
.
read_text
())
if
configfile
is
not
None
else
{}
except
FileNotFoundError
as
error
:
LOGGER
.
exception
(
"Configuration file
%s
is not a file:
%s
"
,
configfile
,
error
)
except
yaml
.
error
.
YAMLError
as
error
:
LOGGER
.
exception
(
"Configuration file
%s
contains malformed yaml:
%s
"
,
configfile
,
error
)
raise
data
.
update
(
overrides
)
for
key
,
value
in
data
.
items
():
if
key
not
in
dir
(
cls
):
raise
Exception
(
f
"Unknown config key {key}, known ones are: {dir(self)}"
)
expected_type
=
cls
.
__annotations__
[
key
]
try
:
# make sure to cast the strings to they annotated types
data
[
key
]
=
expected_type
(
value
)
except
Exception
as
error
:
raise
Exception
(
f
"Bad value for key {key}, got {type(value)} expected {expected_type}."
)
from
error
return
cls
(
**
data
)
Event Timeline
dcaro
created this paste.
Nov 25 2021, 3:31 PM
2021-11-25 15:31:21 (UTC+0)
Log In to Comment