]> git.ipfire.org Git - ipfire.org.git/commitdiff
Provide a sensible default configuration
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 12 Jul 2018 17:02:02 +0000 (18:02 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 12 Jul 2018 17:02:17 +0000 (18:02 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/backend/base.py
src/web/__init__.py

index 2497f4db266e030a823e27dbe6576d48a0ebf97c..47d22c8b37573fd08f614edce84044025e8edf5f 100644 (file)
@@ -1,6 +1,7 @@
 #!/usr/bin/python
 
 import ConfigParser as configparser
+import StringIO
 
 import accounts
 import ads
@@ -20,11 +21,22 @@ import talk
 
 from . import zeiterfassung
 
+DEFAULT_CONFIG = StringIO.StringIO("""
+[global]
+debug = false
+
+data_dir      =
+static_dir    = %(data_dir)s/static
+templates_dir = %(data_dir)s/templates
+""")
+
 class Backend(object):
        def __init__(self, configfile, debug=False):
                # Read configuration file.
                self.config = self.read_config(configfile)
-               self.debug = debug
+
+               # Enable debug logging if configured
+               self.debug = debug or self.config.getboolean("global", "debug")
 
                # Setup database.
                self.setup_database()
@@ -52,6 +64,11 @@ class Backend(object):
 
        def read_config(self, configfile):
                cp = configparser.ConfigParser()
+
+               # Initialize configuration with some sensible defaults
+               cp.readfp(DEFAULT_CONFIG)
+
+               # Parse file
                cp.read(configfile)
 
                return cp
index fdd5b477b6bbc60db5b5ef7bac89aca1bca0a8b2..5f94d90588194a410535fe6437ddad3661ebc99e 100644 (file)
@@ -18,14 +18,25 @@ class Application(tornado.web.Application):
                # Initialize backend
                self.backend = ipfire.Backend(config)
 
-               settings = dict(
-                       debug = tornado.options.options.debug,
-                       login_url = "/login",
-                       template_path = os.path.join(BASEDIR, "templates"),
-                       ui_methods = {
+               settings = {
+                       # Do not compress responses
+                       "gzip" : False,
+
+                       # Enable XSRF cookies
+                       "xsrf_cookies" : True,
+
+                       # Login
+                       "login_url" : "/login",
+
+                       # Setup directory structure
+                       "static_path"   : self.backend.config.get("global", "static_dir"),
+                       "template_path" : self.backend.config.get("global", "templates_dir"),
+
+                       # UI Modules
+                       "ui_methods" : {
                                "format_month_name" : self.format_month_name,
                        },
-                       ui_modules = {
+                       "ui_modules" : {
                                "Advertisement"        : AdvertisementModule,
                                "DonationBox"          : DonationBoxModule,
                                "DonationButton"       : DonationButtonModule,
@@ -58,8 +69,7 @@ class Application(tornado.web.Application):
                                "TalkLines"            : TalkLinesModule,
                                "TalkOngoingCalls"     : TalkOngoingCallsModule,
                        },
-                       xsrf_cookies = True,
-               )
+               }
                settings.update(kwargs)
 
                tornado.web.Application.__init__(self, **settings)