From c2247b3c2879bcec9489e5049fd64f28d5a1ef28 Mon Sep 17 00:00:00 2001 From: Jorik Schellekens Date: Fri, 23 Aug 2019 11:18:41 +0100 Subject: [PATCH 1/6] Let synctl use a config directory. --- synapse/config/__init__.py | 2 +- synctl | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/synapse/config/__init__.py b/synapse/config/__init__.py index f2a5a41e9228..c5ff51f4afe4 100644 --- a/synapse/config/__init__.py +++ b/synapse/config/__init__.py @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from ._base import ConfigError +from ._base import ConfigError, find_config_files, read_config_files # export ConfigError if somebody does import * # this is largely a fudge to stop PEP8 moaning about the import diff --git a/synctl b/synctl index 794de99ea3c1..83474eedc687 100755 --- a/synctl +++ b/synctl @@ -30,6 +30,8 @@ from six import iteritems import yaml +from synapse.config import find_config_files, read_config_files + SYNAPSE = [sys.executable, "-B", "-m", "synapse.app.homeserver"] GREEN = "\x1b[1;32m" @@ -135,7 +137,8 @@ def main(): "configfile", nargs="?", default="homeserver.yaml", - help="the homeserver config file, defaults to homeserver.yaml", + help="the homeserver config file, defaults to homeserver.yaml, may also specify" + " a directory with *.yaml files", ) parser.add_argument( "-w", "--worker", metavar="WORKERCONFIG", help="start or stop a single worker" @@ -176,8 +179,7 @@ def main(): ) sys.exit(1) - with open(configfile) as stream: - config = yaml.safe_load(stream) + config = read_config_files(find_config_files([configfile])) pidfile = config["pid_file"] cache_factor = config.get("synctl_cache_factor") From 5af9299a9feefb7e3fe5c7f57e2dab7c28c4fb25 Mon Sep 17 00:00:00 2001 From: Jorik Schellekens Date: Fri, 23 Aug 2019 11:23:20 +0100 Subject: [PATCH 2/6] newsfile --- changelog.d/5904.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/5904.feature diff --git a/changelog.d/5904.feature b/changelog.d/5904.feature new file mode 100644 index 000000000000..43b5304f3913 --- /dev/null +++ b/changelog.d/5904.feature @@ -0,0 +1 @@ +Let synctl accept a directory of config files. From 6e92cf478038dd2407953dfca123a9588df6351a Mon Sep 17 00:00:00 2001 From: Jorik Schellekens Date: Fri, 23 Aug 2019 16:35:23 +0100 Subject: [PATCH 3/6] No moaning. --- synapse/config/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/synapse/config/__init__.py b/synapse/config/__init__.py index c5ff51f4afe4..87fd47972711 100644 --- a/synapse/config/__init__.py +++ b/synapse/config/__init__.py @@ -15,6 +15,7 @@ from ._base import ConfigError, find_config_files, read_config_files -# export ConfigError if somebody does import * +# export ConfigError, find_cofig_files, read_config_files if somebody does +# import * # this is largely a fudge to stop PEP8 moaning about the import -__all__ = ["ConfigError"] +__all__ = ["ConfigError", "find_config_files", "read_config_files"] From 48c26d24f5fc789f6d5687ffadffc5a02a758b15 Mon Sep 17 00:00:00 2001 From: Jorik Schellekens Date: Wed, 28 Aug 2019 09:59:50 +0100 Subject: [PATCH 4/6] Docs Co-Authored-By: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> --- synapse/config/__init__.py | 2 +- synctl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/synapse/config/__init__.py b/synapse/config/__init__.py index 87fd47972711..11313619d278 100644 --- a/synapse/config/__init__.py +++ b/synapse/config/__init__.py @@ -15,7 +15,7 @@ from ._base import ConfigError, find_config_files, read_config_files -# export ConfigError, find_cofig_files, read_config_files if somebody does +# export ConfigError, find_config_files, read_config_files if somebody does # import * # this is largely a fudge to stop PEP8 moaning about the import __all__ = ["ConfigError", "find_config_files", "read_config_files"] diff --git a/synctl b/synctl index 83474eedc687..7ed021899480 100755 --- a/synctl +++ b/synctl @@ -137,7 +137,7 @@ def main(): "configfile", nargs="?", default="homeserver.yaml", - help="the homeserver config file, defaults to homeserver.yaml, may also specify" + help="the homeserver config file. Defaults to homeserver.yaml. May also be" " a directory with *.yaml files", ) parser.add_argument( From 765d1f13d2b183dbd36c7d441741c0ab4719df14 Mon Sep 17 00:00:00 2001 From: Jorik Schellekens Date: Wed, 28 Aug 2019 10:08:51 +0100 Subject: [PATCH 5/6] Explicitely read yaml for clarity. --- synapse/config/__init__.py | 4 ++-- synctl | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/synapse/config/__init__.py b/synapse/config/__init__.py index 11313619d278..ea71d6cfef27 100644 --- a/synapse/config/__init__.py +++ b/synapse/config/__init__.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -from ._base import ConfigError, find_config_files, read_config_files +from ._base import ConfigError, find_config_files # export ConfigError, find_config_files, read_config_files if somebody does # import * # this is largely a fudge to stop PEP8 moaning about the import -__all__ = ["ConfigError", "find_config_files", "read_config_files"] +__all__ = ["ConfigError", "find_config_files"] diff --git a/synctl b/synctl index 7ed021899480..a9629cf0e8a1 100755 --- a/synctl +++ b/synctl @@ -30,7 +30,7 @@ from six import iteritems import yaml -from synapse.config import find_config_files, read_config_files +from synapse.config import find_config_files SYNAPSE = [sys.executable, "-B", "-m", "synapse.app.homeserver"] @@ -179,7 +179,12 @@ def main(): ) sys.exit(1) - config = read_config_files(find_config_files([configfile])) + config_files = find_config_files([configfile]) + config = {} + for config_file in config_files: + with open(config_file) as file_stream: + yaml_config = yaml.safe_load(file_stream) + config.update(yaml_config) pidfile = config["pid_file"] cache_factor = config.get("synctl_cache_factor") From d1ec76f10d51fd40645305a6643953ae27382233 Mon Sep 17 00:00:00 2001 From: Jorik Schellekens Date: Wed, 28 Aug 2019 15:18:40 +0100 Subject: [PATCH 6/6] Misleading comment --- synapse/config/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/config/__init__.py b/synapse/config/__init__.py index ea71d6cfef27..1e76e9559df6 100644 --- a/synapse/config/__init__.py +++ b/synapse/config/__init__.py @@ -15,7 +15,7 @@ from ._base import ConfigError, find_config_files -# export ConfigError, find_config_files, read_config_files if somebody does +# export ConfigError and find_config_files if somebody does # import * # this is largely a fudge to stop PEP8 moaning about the import __all__ = ["ConfigError", "find_config_files"]