You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

57 line
1.8 KiB

  1. # Copyright 2015, 2016 OpenMarket Ltd
  2. # Copyright 2021 The Matrix.org Foundation C.I.C.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import sys
  16. from typing import List
  17. from synapse.config._base import ConfigError
  18. from synapse.config.homeserver import HomeServerConfig
  19. def main(args: List[str]) -> None:
  20. action = args[1] if len(args) > 1 and args[1] == "read" else None
  21. # If we're reading a key in the config file, then `args[1]` will be `read` and `args[2]`
  22. # will be the key to read.
  23. # We'll want to rework this code if we want to support more actions than just `read`.
  24. load_config_args = args[3:] if action else args[1:]
  25. try:
  26. config = HomeServerConfig.load_config("", load_config_args)
  27. except ConfigError as e:
  28. sys.stderr.write("\n" + str(e) + "\n")
  29. sys.exit(1)
  30. print("Config parses OK!")
  31. if action == "read":
  32. key = args[2]
  33. key_parts = key.split(".")
  34. value = config
  35. try:
  36. while len(key_parts):
  37. value = getattr(value, key_parts[0])
  38. key_parts.pop(0)
  39. print(f"\n{key}: {value}")
  40. except AttributeError:
  41. print(
  42. f"\nNo '{key}' key could be found in the provided configuration file."
  43. )
  44. sys.exit(1)
  45. if __name__ == "__main__":
  46. main(sys.argv)