Examples: query, "exact match", wildcard*, wild?ard, wild*rd
Fuzzy search: cake~ (finds cakes, bake)
Term boost: "red velvet"^4, chocolate^2
Field grouping: tags:(+work -"fun-stuff")
Escaping: Escape characters +-&|!(){}[]^"~*?:\ with \, e.g. \+
Range search: properties.timestamp:[1587729413488 TO *] (inclusive), properties.title:{A TO Z}(excluding A and Z)
Combinations: chocolate AND vanilla, chocolate OR vanilla, (chocolate OR vanilla) NOT "vanilla pudding"
Field search: properties.title:"The Title" AND text
Answered
Question About The Configuration Format - I'D Like To Parse It Within My Python Code So I'Ll Be Able To Access Things Like

Question about the configuration format - I'd like to parse it within my Python code so I'll be able to access things like google.storage.containers programatically - how should I go about that?

  
  
Posted 4 years ago
Votes Newest

Answers 30


Confirmed working 😄

  
  
Posted 4 years ago

later today or tomorrow, I'll update

  
  
Posted 4 years ago

I'll try

  
  
Posted 4 years ago

What about:
apiserver_conf.put( "auth.fixed_users.users", list(apiserver_conf.get("auth.fixed_users.users", [])) + [{'username': username, 'password': password, 'name': name}] )

  
  
Posted 4 years ago

The only way to change it is to convert apiserver_conf to a dictionary object ( as_plain_ordered_dict() ) and edit it

  
  
Posted 4 years ago

even though I apply append

  
  
Posted 4 years ago

it seems apiserver_conf doesn't even change

  
  
Posted 4 years ago

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

  
  
Posted 4 years ago

it will return a

Config

object right?

Will return a ConfigTree object which behaves the same way

  
  
Posted 4 years ago

👍

  
  
Posted 4 years ago

it will return a Config object right?

  
  
Posted 4 years ago

However, that can easily be done using ConfigFactory.parse_file("apiserver.conf")

  
  
Posted 4 years ago

Since your aim is to end up with content you can paste into apiserver.conf (which is not loaded by Trains)

  
  
Posted 4 years ago

yeah I know

  
  
Posted 4 years ago

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

  
  
Posted 4 years ago

I'll tr yto work with that

  
  
Posted 4 years ago

okay, that's acceptable

  
  
Posted 4 years ago

Sorry my bad:
config_obj['sdk']['stuff']['here'] = value

  
  
Posted 4 years ago

Config == conf_obj no?

  
  
Posted 4 years ago

whatttt? I looked at config_obj didn't find any set method

  
  
Posted 4 years ago

If you need to change the values:
config_obj.set(...)You might want to edit the object on a copy, not the original 🙂

  
  
Posted 4 years ago

but using that code - how would I edit fileds?

  
  
Posted 4 years ago

yeah I guessed so

  
  
Posted 4 years ago

BTW: you will be loosing the comments 😞

  
  
Posted 4 years ago

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)

  
  
Posted 4 years ago

Not sure about that...

  
  
Posted 4 years ago

Another Q on that - does pyhocon allows me to edit the file while keeping the comments in place?

  
  
Posted 4 years ago

essentially editing apiserver.conf section auth.fixed_users.users

  
  
Posted 4 years ago

AgitatedDove14 permanent. I want to start with a CLI interface that allows me add users to the trains server

  
  
Posted 4 years ago