Bladeren bron

better runner, use wsgidav.config_file param instead of env var

Guénaël Muller 6 jaren geleden
bovenliggende
commit
787e286a60
5 gewijzigde bestanden met toevoegingen van 31 en 28 verwijderingen
  1. 2 4
      tracim/command/webdav.py
  2. 8 13
      tracim/lib/webdav/__init__.py
  3. 16 0
      wsgi/__init__.py
  4. 2 4
      wsgi/web.py
  5. 3 7
      wsgi/webdav.py

+ 2 - 4
tracim/command/webdav.py Bestand weergeven

@@ -6,6 +6,7 @@ from waitress import serve
6 6
 
7 7
 from tracim.command import AppContextCommand
8 8
 from tracim.lib.webdav import WebdavAppFactory
9
+from wsgi import webdav_app
9 10
 
10 11
 
11 12
 class WebdavRunnerCommand(AppContextCommand):
@@ -22,8 +23,5 @@ class WebdavRunnerCommand(AppContextCommand):
22 23
         super(WebdavRunnerCommand, self).take_action(parsed_args)
23 24
         tracim_config = parsed_args.config_file
24 25
         # TODO - G.M - 16-04-2018 - Allow specific webdav config file
25
-        app_factory = WebdavAppFactory(
26
-            tracim_config_file_path=tracim_config,
27
-        )
28
-        app = app_factory.get_wsgi_app()
26
+        app = webdav_app(tracim_config)
29 27
         serve(app, port=app.config['port'], host=app.config['host'])

+ 8 - 13
tracim/lib/webdav/__init__.py Bestand weergeven

@@ -27,22 +27,17 @@ from tracim.models import get_engine, get_session_factory
27 27
 class WebdavAppFactory(object):
28 28
 
29 29
     def __init__(self,
30
-                 webdav_config_file_path: str = None,
31 30
                  tracim_config_file_path: str = None,
32 31
                  ):
33 32
         self.config = self._initConfig(
34
-            webdav_config_file_path,
35 33
             tracim_config_file_path
36 34
         )
37 35
 
38 36
     def _initConfig(self,
39
-                    webdav_config_file_path: str = None,
40 37
                     tracim_config_file_path: str = None
41 38
                     ):
42 39
         """Setup configuration dictionary from default,
43 40
          command line and configuration file."""
44
-        if not webdav_config_file_path:
45
-            webdav_config_file_path = DEFAULT_WEBDAV_CONFIG_FILE
46 41
         if not tracim_config_file_path:
47 42
             tracim_config_file_path = DEFAULT_TRACIM_CONFIG_FILE
48 43
 
@@ -50,20 +45,20 @@ class WebdavAppFactory(object):
50 45
         config = DEFAULT_CONFIG.copy()
51 46
         temp_verbose = config["verbose"]
52 47
 
53
-        default_config_file = os.path.abspath(webdav_config_file_path)
54
-        webdav_config_file = self._readConfigFile(
55
-            webdav_config_file_path,
56
-            temp_verbose
57
-            )
58
-        # Configuration file overrides defaults
59
-        config.update(webdav_config_file)
60
-
61 48
         # Get pyramid Env
62 49
         tracim_config_file_path = os.path.abspath(tracim_config_file_path)
63 50
         config['tracim_config'] = tracim_config_file_path
64 51
         settings = get_appsettings(config['tracim_config'])
65 52
         app_config = CFG(settings)
66 53
 
54
+        default_config_file = os.path.abspath(settings['wsgidav.config_path'])
55
+        webdav_config_file = self._readConfigFile(
56
+            default_config_file,
57
+            temp_verbose
58
+            )
59
+        # Configuration file overrides defaults
60
+        config.update(webdav_config_file)
61
+
67 62
         if not useLxml and config["verbose"] >= 1:
68 63
             print(
69 64
                 "WARNING: Could not import lxml: using xml instead (slower). "

+ 16 - 0
wsgi/__init__.py Bestand weergeven

@@ -0,0 +1,16 @@
1
+# coding=utf-8
2
+import pyramid.paster
3
+
4
+from tracim.lib.webdav import WebdavAppFactory
5
+
6
+
7
+def web_app(config_uri):
8
+    pyramid.paster.setup_logging(config_uri)
9
+    return pyramid.paster.get_app(config_uri)
10
+
11
+
12
+def webdav_app(config_uri):
13
+    app_factory = WebdavAppFactory(
14
+        tracim_config_file_path=config_uri,
15
+    )
16
+    return app_factory.get_wsgi_app()

+ 2 - 4
wsgi/web.py Bestand weergeven

@@ -1,9 +1,7 @@
1 1
 # coding=utf-8
2 2
 # Runner for uwsgi
3 3
 import os
4
-import pyramid.paster
4
+from wsgi import web_app
5 5
 
6 6
 config_uri = os.environ['TRACIM_CONF_PATH']
7
-
8
-pyramid.paster.setup_logging(config_uri)
9
-application = pyramid.paster.get_app(config_uri)
7
+application = web_app(config_uri)

+ 3 - 7
wsgi/webdav.py Bestand weergeven

@@ -1,12 +1,8 @@
1 1
 # coding=utf-8
2 2
 # Runner for uwsgi
3
-from tracim.lib.webdav import WebdavAppFactory
4 3
 import os
5 4
 
5
+from wsgi import webdav_app
6
+
6 7
 config_uri = os.environ['TRACIM_CONF_PATH']
7
-webdav_config_uri = os.environ['TRACIM_WEBDAV_CONF_PATH']
8
-app_factory = WebdavAppFactory(
9
-    tracim_config_file_path=config_uri,
10
-    webdav_config_file_path=webdav_config_uri,
11
-)
12
-application = app_factory.get_wsgi_app()
8
+application = webdav_app(config_uri)