summary refs log tree commit diff
path: root/synapse/config
diff options
context:
space:
mode:
Diffstat (limited to 'synapse/config')
-rw-r--r--synapse/config/_base.py23
-rw-r--r--synapse/config/database.py5
-rw-r--r--synapse/config/logger.py14
-rw-r--r--synapse/config/server.py11
-rw-r--r--synapse/config/tls.py2
5 files changed, 35 insertions, 20 deletions
diff --git a/synapse/config/_base.py b/synapse/config/_base.py
index b4cf0262f4..78197e4a75 100644
--- a/synapse/config/_base.py
+++ b/synapse/config/_base.py
@@ -25,6 +25,10 @@ class Config(object):
         pass
 
     @staticmethod
+    def abspath(file_path):
+        return os.path.abspath(file_path) if file_path else file_path
+
+    @staticmethod
     def read_file(file_path):
         with open(file_path) as file_stream:
             return file_stream.read()
@@ -54,9 +58,14 @@ class Config(object):
             metavar="CONFIG_FILE",
             help="Specify config file"
         )
+        config_parser.add_argument(
+            "--generate-config",
+            action="store_true",
+            help="Generate config file"
+        )
         config_args, remaining_args = config_parser.parse_known_args(argv)
 
-        if generate_section:
+        if config_args.generate_config:
             if not config_args.config_path:
                 config_parser.error(
                     "Must specify where to generate the config file"
@@ -64,6 +73,8 @@ class Config(object):
             config_dir_path = os.path.dirname(config_args.config_path)
             if os.path.exists(config_args.config_path):
                 defaults = cls.read_config_file(config_args.config_path)
+            else:
+                defaults = {}
         else:
             if config_args.config_path:
                 defaults = cls.read_config_file(config_args.config_path)
@@ -75,23 +86,25 @@ class Config(object):
             description=description,
             formatter_class=argparse.RawDescriptionHelpFormatter,
         )
+        cls.add_arguments(parser)
         parser.set_defaults(**defaults)
 
-
-        cls.add_arguments(parser)
         args = parser.parse_args(remaining_args)
 
-        if generate_section:
+        if config_args.generate_config:
             config_dir_path = os.path.dirname(config_args.config_path)
             config_dir_path = os.path.abspath(config_dir_path)
             cls.generate_config(args, config_dir_path)
             config = configparser.SafeConfigParser()
             config.add_section(generate_section)
             for key, value in vars(args).items():
-                if key != "config_path" and value is not None:
+                if (key not in set(["config_path", "generate_config"])
+                    and value is not None):
+                    print key, "=", value
                     config.set(generate_section, key, str(value))
             with open(config_args.config_path, "w") as config_file:
                 config.write(config_file)
+            sys.exit(0)
 
         return cls(args)
 
diff --git a/synapse/config/database.py b/synapse/config/database.py
index 43f54be437..edf2361914 100644
--- a/synapse/config/database.py
+++ b/synapse/config/database.py
@@ -18,14 +18,15 @@ import os
 
 class DatabaseConfig(Config):
     def __init__(self, args):
-        self.db_path = os.path.abspath(args.database_path)
+        super(DatabaseConfig, self).__init__(args)
+        self.database_path = self.abspath(args.database_path)
 
     @classmethod
     def add_arguments(cls, parser):
         super(DatabaseConfig, cls).add_arguments(parser)
         db_group = parser.add_argument_group("database")
         db_group.add_argument(
-            "-d", "--database", dest="database_path", default="homeserver.db",
+            "-d", "--database-path", default="homeserver.db",
             help="The database name."
         )
 
diff --git a/synapse/config/logger.py b/synapse/config/logger.py
index d34532c41a..8db6621ae8 100644
--- a/synapse/config/logger.py
+++ b/synapse/config/logger.py
@@ -18,13 +18,13 @@ from ._base import Config
 from twisted.python.log import PythonLoggingObserver
 import logging
 import logging.config
-import os
 
 class LoggingConfig(Config):
     def __init__(self, args):
+        super(LoggingConfig, self).__init__(args)
         self.verbosity = int(args.verbose) if args.verbose else None
-        self.log_config = os.path.abspath(args.log_config)
-        self.log_file = os.path.abspath(args.log_file)
+        self.log_config = self.abspath(args.log_config)
+        self.log_file = self.abspath(args.log_file)
 
     @classmethod
     def add_arguments(cls, parser):
@@ -47,21 +47,21 @@ class LoggingConfig(Config):
         log_format = (
             '%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(message)s'
         )
-        if self.config_path is None:
+        if self.log_config is None:
 
             level = logging.INFO
-            if verbosity:
+            if self.verbosity:
                level = logging.DEBUG
 
                # FIXME: we need a logging.WARN for a -q quiet option
 
             logging.basicConfig(
                 level=level,
-                filename=filename,
+                filename=self.log_file,
                 format=log_format
             )
         else:
-            logging.config.fileConfig(config_path)
+            logging.config.fileConfig(self.log_config)
 
         observer = PythonLoggingObserver()
         observer.start()
diff --git a/synapse/config/server.py b/synapse/config/server.py
index 4a656b06ab..a3aceb521d 100644
--- a/synapse/config/server.py
+++ b/synapse/config/server.py
@@ -14,7 +14,6 @@
 # limitations under the License.
 
 import nacl.signing
-import socket
 import os
 from ._base import Config
 from syutil.base64util import encode_base64, decode_base64
@@ -28,7 +27,9 @@ class ServerConfig(Config):
         self.bind_port = args.bind_port
         self.bind_host = args.bind_host
         self.daemonize = args.daemonize
-        self.pid_file = os.path.abspath(args.pid_file)
+        self.pid_file = self.abspath(args.pid_file)
+        self.webclient = not args.no_webclient
+        self.manhole = args.manhole
 
     @classmethod
     def add_arguments(cls, parser):
@@ -44,11 +45,11 @@ class ServerConfig(Config):
                                   help="Local interface to listen on")
         server_group.add_argument("-D", "--daemonize", action='store_true',
                                   help="Daemonize the home server")
-        server_group.add_argument('--pid-file', default = "hs.pid",
+        server_group.add_argument('--pid-file', default="hs.pid",
                                   help="When running as a daemon, the file to"
                                   " store the pid in")
-        server_group.add_argument("-W", "--no-webclient", dest="webclient",
-                                  default=True, action="store_false",
+        server_group.add_argument("-W", "--no-webclient", default=True,
+                                  action="store_false",
                                   help="Don't host a web client.")
         server_group.add_argument("--manhole", dest="manhole", type=int,
                                   help="Turn on the twisted telnet manhole"
diff --git a/synapse/config/tls.py b/synapse/config/tls.py
index c65487ceb9..7a3d6e3a02 100644
--- a/synapse/config/tls.py
+++ b/synapse/config/tls.py
@@ -28,7 +28,7 @@ class TlsConfig(Config):
         self.tls_private_key = self.read_tls_private_key(
             args.tls_private_key_path
         )
-        self.tls_dh_params_path = args.tls_dh_params_path
+        self.tls_dh_params_path = self.abspath(args.tls_dh_params_path)
 
     @classmethod
     def add_arguments(cls, parser):