|
12 | 12 | from yaml import safe_load
|
13 | 13 |
|
14 | 14 | from gravity import __version__
|
15 |
| -from gravity.defaults import ( |
16 |
| - CELERY_DEFAULT_CONFIG, |
17 |
| - DEFAULT_INSTANCE_NAME, |
18 |
| - GUNICORN_DEFAULT_CONFIG, |
19 |
| - GXIT_DEFAULT_IP, |
20 |
| - GXIT_DEFAULT_PORT, |
21 |
| - GXIT_DEFAULT_SESSIONS, |
22 |
| -) |
| 15 | +from gravity.settings import Settings |
23 | 16 | from gravity.io import debug, error, exception, info, warn
|
24 | 17 | from gravity.state import (
|
25 | 18 | ConfigFile,
|
@@ -76,50 +69,38 @@ def __convert_config(self):
|
76 | 69 | os.unlink(config_state_json)
|
77 | 70 |
|
78 | 71 | def get_config(self, conf, defaults=None):
|
| 72 | + defaults = defaults or {} |
79 | 73 | server_section = self.galaxy_server_config_section
|
80 | 74 | with open(conf) as config_fh:
|
81 | 75 | config_dict = safe_load(config_fh)
|
82 |
| - |
83 |
| - default_config = { |
84 |
| - "galaxy_root": None, |
85 |
| - "log_dir": join(expanduser(self.state_dir), "log"), |
86 |
| - "virtualenv": None, |
87 |
| - "instance_name": DEFAULT_INSTANCE_NAME, |
88 |
| - "app_server": "gunicorn", |
89 |
| - "gunicorn": GUNICORN_DEFAULT_CONFIG, |
90 |
| - "celery": CELERY_DEFAULT_CONFIG, |
91 |
| - "gx_it_proxy": {}, |
92 |
| - "handlers": {}, |
93 |
| - } |
94 |
| - if defaults is not None: |
95 |
| - recursive_update(default_config, defaults) |
| 76 | + _gravity_config = config_dict.get(self.gravity_config_section) or {} |
| 77 | + gravity_config = Settings(**recursive_update(defaults, _gravity_config)) |
| 78 | + if gravity_config.log_dir is None: |
| 79 | + gravity_config.log_dir = join(expanduser(self.state_dir), "log") |
96 | 80 |
|
97 | 81 | if server_section not in config_dict and self.gravity_config_section not in config_dict:
|
98 | 82 | error(f"Config file {conf} does not look like valid Galaxy, Reports or Tool Shed configuration file")
|
99 | 83 | return None
|
100 | 84 |
|
101 | 85 | app_config = config_dict.get(server_section) or {}
|
102 |
| - _gravity_config = config_dict.get(self.gravity_config_section) or {} |
103 |
| - gravity_config = recursive_update(default_config, _gravity_config) |
104 | 86 |
|
105 | 87 | config = ConfigFile()
|
106 | 88 | config.attribs = {}
|
107 | 89 | config.services = []
|
108 |
| - config.instance_name = gravity_config["instance_name"] |
| 90 | + config.instance_name = gravity_config.instance_name |
109 | 91 | config.config_type = server_section
|
110 |
| - config.attribs["app_server"] = gravity_config["app_server"] |
111 |
| - config.attribs["log_dir"] = gravity_config["log_dir"] |
112 |
| - config.attribs["virtualenv"] = gravity_config["virtualenv"] |
113 |
| - config.attribs["gunicorn"] = gravity_config["gunicorn"] |
114 |
| - config.attribs["celery"] = gravity_config["celery"] |
115 |
| - config.attribs["handlers"] = gravity_config["handlers"] |
116 |
| - config.attribs["gx_it_proxy"] = gravity_config["gx_it_proxy"] |
| 92 | + config.attribs["app_server"] = gravity_config.app_server |
| 93 | + config.attribs["log_dir"] = gravity_config.log_dir |
| 94 | + config.attribs["virtualenv"] = gravity_config.virtualenv |
| 95 | + config.attribs["gunicorn"] = gravity_config.gunicorn.dict() |
| 96 | + config.attribs["celery"] = gravity_config.celery.dict() |
| 97 | + config.attribs["handlers"] = gravity_config.handlers |
117 | 98 | # Store gravity version, in case we need to convert old setting
|
118 | 99 | config.attribs['gravity_version'] = __version__
|
119 | 100 | webapp_service_names = []
|
120 | 101 |
|
121 | 102 | # shortcut for galaxy configs in the standard locations -- explicit arg ?
|
122 |
| - config.attribs["galaxy_root"] = app_config.get("root") or gravity_config.get("galaxy_root") |
| 103 | + config.attribs["galaxy_root"] = app_config.get("root") or gravity_config.galaxy_root |
123 | 104 | if config.attribs["galaxy_root"] is None:
|
124 | 105 | if os.environ.get("GALAXY_ROOT_DIR"):
|
125 | 106 | config.attribs["galaxy_root"] = abspath(os.environ["GALAXY_ROOT_DIR"])
|
@@ -156,27 +137,26 @@ def get_config(self, conf, defaults=None):
|
156 | 137 | self.create_gxit_services(gravity_config, app_config, config)
|
157 | 138 | return config
|
158 | 139 |
|
159 |
| - def create_handler_services(self, gravity_config, config): |
| 140 | + def create_handler_services(self, gravity_config: Settings, config): |
160 | 141 | expanded_handlers = self.expand_handlers(gravity_config, config)
|
161 | 142 | for service_name, handler_settings in expanded_handlers.items():
|
162 | 143 | pools = handler_settings.get('pools')
|
163 | 144 | config.services.append(
|
164 | 145 | service_for_service_type("standalone")(config_type=config.config_type, service_name=service_name, server_pools=pools))
|
165 | 146 |
|
166 |
| - def create_gxit_services(self, gravity_config, app_config, config): |
167 |
| - if app_config.get("interactivetools_enable") and gravity_config["gx_it_proxy"].get("enable"): |
| 147 | + def create_gxit_services(self, gravity_config: Settings, app_config, config): |
| 148 | + if app_config.get("interactivetools_enable") and gravity_config.gx_it_proxy.enable: |
168 | 149 | # TODO: resolve against data_dir, or bring in galaxy-config ?
|
169 | 150 | # CWD in supervisor template is galaxy_root, so this should work for simple cases as is
|
170 |
| - gxit_config = gravity_config['gx_it_proxy'] |
171 |
| - gxit_config["sessions"] = app_config.get("interactivetools_map", GXIT_DEFAULT_SESSIONS) |
172 |
| - gxit_config["ip"] = gxit_config.get("ip", GXIT_DEFAULT_IP) |
173 |
| - gxit_config["port"] = gxit_config.get("port", GXIT_DEFAULT_PORT) |
174 |
| - gxit_config["verbose"] = '--verbose' if gxit_config.get("verbose") else '' |
175 |
| - config.services.append(service_for_service_type("gx-it-proxy")(config_type=config.config_type, gxit=gxit_config)) |
| 151 | + gxit_config = gravity_config.gx_it_proxy |
| 152 | + gxit_config.sessions = app_config.get("interactivetools_map", gxit_config.sessions) |
| 153 | + gxit_config.verbose = '--verbose' if gxit_config.verbose else '' |
| 154 | + config.services.append(service_for_service_type("gx-it-proxy")(config_type=config.config_type)) |
| 155 | + config.attribs["gx_it_proxy"] = gravity_config.gx_it_proxy.dict() |
176 | 156 |
|
177 | 157 | @staticmethod
|
178 |
| - def expand_handlers(gravity_config, config): |
179 |
| - handlers = gravity_config.get("handlers", {}) |
| 158 | + def expand_handlers(gravity_config: Settings, config): |
| 159 | + handlers = gravity_config.handlers or {} |
180 | 160 | expanded_handlers = {}
|
181 | 161 | default_name_template = "{name}_{process}"
|
182 | 162 | for service_name, handler_config in handlers.items():
|
|
0 commit comments