Files
galaxy/scripts/config_parse.py
T
Nicola Soranzo 8afac1afd5 Use `load_app_properties()` to load Galaxy config file
instead of directly loading it as YAML.
Will make it easier to uniformly deal with changes of format (e.g.
we are deprecating ini now).

Fix traceback:

```
Traceback (most recent call last):
  File "scripts/config_parse.py", line 31, in <module>
    main(args.config_file, args.setting)
  File "scripts/config_parse.py", line 16, in main
    gx_config = GalaxyAppConfiguration(**yaml.safe_load(open(config))["galaxy"])
  File "/home/berntm/.planemo/gx_venv_3/lib/python3.8/site-packages/yaml/__init__.py", line 125, in safe_load
    return load(stream, SafeLoader)
  File "/home/berntm/.planemo/gx_venv_3/lib/python3.8/site-packages/yaml/__init__.py", line 81, in load
    return loader.get_single_data()
  File "/home/berntm/.planemo/gx_venv_3/lib/python3.8/site-packages/yaml/constructor.py", line 49, in get_single_data
    node = self.get_single_node()
  File "/home/berntm/.planemo/gx_venv_3/lib/python3.8/site-packages/yaml/composer.py", line 39, in get_single_node
    if not self.check_event(StreamEndEvent):
  File "/home/berntm/.planemo/gx_venv_3/lib/python3.8/site-packages/yaml/parser.py", line 98, in check_event
    self.current_event = self.state()
  File "/home/berntm/.planemo/gx_venv_3/lib/python3.8/site-packages/yaml/parser.py", line 171, in parse_document_start
    raise ParserError(None, None,
yaml.parser.ParserError: expected '<document start>', but found '<scalar>'
  in "/tmp/tmpsffm7of5/galaxy.ini", line 3, column 1
```

when starting Galaxy with a `galaxy.ini` config file (though Galaxy startup
will still fail later).
2022-04-26 09:48:18 +01:00

32 lines
1.1 KiB
Python

import argparse
import os
import pprint
import sys
sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, "lib")))
from galaxy.config import GalaxyAppConfiguration
from galaxy.util.properties import load_app_properties
def main(config, setting):
# Use explicit config, then env, then guess.
config = config or os.environ.get("GALAXY_CONFIG_FILE", "config/galaxy.yml")
if config and os.path.exists(config):
app_properties = load_app_properties(config_file=config)
gx_config = GalaxyAppConfiguration(**app_properties)
if setting:
print(gx_config.get(setting))
else:
pprint.pprint(gx_config.config_dict)
if __name__ == "__main__":
arg_parser = argparse.ArgumentParser(description="Fetch values from Galaxy config, or print all set values.")
# add optional 'setting' argument
arg_parser.add_argument("-s", "--setting", default=None, help="setting")
arg_parser.add_argument(
"-c", "--config-file", default=None, help="Galaxy config file (defaults to config/galaxy.ini)"
)
args = arg_parser.parse_args()
main(args.config_file, args.setting)