Another Q on that - does pyhocon
allows me to edit the file while keeping the comments in place?
However, that can easily be done using ConfigFactory.parse_file("apiserver.conf")
The only way to change it is to convert apiserver_conf
to a dictionary object ( as_plain_ordered_dict()
) and edit it
Since your aim is to end up with content you can paste into apiserver.conf
(which is not loaded by Trains)
Sorry my bad:config_obj['sdk']['stuff']['here'] = value
it seems apiserver_conf
doesn't even change
WackyRabbit7 please note that if your aim is to edit the Server's configuration, you'll need to do that without the config_obj
loaded by Trains
but using that code - how would I edit fileds?
AgitatedDove14 permanent. I want to start with a CLI interface that allows me add users to the trains server
If you need to change the values:config_obj.set(...)
You might want to edit the object on a copy, not the original 🙂
whatttt? I looked at config_obj
didn't find any set
method
essentially editing apiserver.conf
section auth.fixed_users.users
it will return a
Config
object right?
Will return a ConfigTree
object which behaves the same way
What about:apiserver_conf.put( "auth.fixed_users.users", list(apiserver_conf.get("auth.fixed_users.users", [])) + [{'username': username, 'password': password, 'name': name}] )
WackyRabbit7 in that case:from trains.utilities.pyhocon import ConfigFactory, HOCONConverter from trains.config import config_obj new_conf_text = HOCONConverter.to_hocon(config=ConfigFactory.from_dict(config_obj.as_plain_ordered_dict()), compact=False, level=0, indent=2) print(new_conf_text)
SuccessfulKoala55 this actually doesn't work
` apiserver_conf = ConfigFactory.parse_file(API_SERVER_CONF_PATH)
POINT 1
conf_content = HOCONConverter.to_hocon(config=ConfigFactory.from_dict(apiserver_conf.as_plain_ordered_dict()),
compact=False,
level=0, indent=2)
apiserver_conf['auth']['fixed_users']['users'].append(
ConfigFactory.from_dict({'username': username, 'password': password, 'name': name}))
POINT 2
new_conf_content = HOCONConverter.to_hocon(config=ConfigFactory.from_dict(apiserver_conf.as_plain_ordered_dict()),
compact=False,
level=0, indent=2) Strangely enough running this code results in
new_conf_content == conf_content to be
True . Seems like through this
ConfigTree ` object I can't really apply changes on the configuration file