Browse Source

convert webdav as plaster pastedeploy app

Guénaël Muller 6 years ago
parent
commit
ed1db2f320
7 changed files with 37 additions and 10 deletions
  1. 9 1
      development.ini.sample
  2. 2 1
      setup.py
  3. 13 1
      tracim/__init__.py
  4. 4 1
      tracim/lib/webdav/__init__.py
  5. 4 1
      tracim/lib/webdav/middlewares.py
  6. 5 4
      wsgi/__init__.py
  7. 0 1
      wsgi/webdav.py

+ 9 - 1
development.ini.sample View File

@@ -2,7 +2,9 @@
2 2
 # app configuration
3 3
 # https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html
4 4
 ###
5
-[app:main]
5
+[pipeline:main]
6
+pipeline = tracim_web
7
+[app:tracim_web]
6 8
 use = egg:tracim_backend
7 9
 
8 10
 pyramid.reload_templates = true
@@ -13,6 +15,12 @@ pyramid.default_locale_name = en
13 15
 pyramid.includes =
14 16
     pyramid_debugtoolbar
15 17
 
18
+[pipeline:webdav]
19
+pipeline = tracim_webdav
20
+[app:tracim_webdav]
21
+use = egg:tracim_backend#webdav
22
+
23
+[DEFAULT]
16 24
 sqlalchemy.url = sqlite:///%(here)s/tracim.sqlite
17 25
 
18 26
 retry.attempts = 3

+ 2 - 1
setup.py View File

@@ -89,7 +89,8 @@ setup(
89 89
     install_requires=requires,
90 90
     entry_points={
91 91
         'paste.app_factory': [
92
-            'main = tracim:main',
92
+            'main = tracim:web',
93
+            'webdav = tracim:webdav'
93 94
         ],
94 95
         'console_scripts': [
95 96
             'tracimcli = tracim.command:main',

+ 13 - 1
tracim/__init__.py View File

@@ -13,15 +13,18 @@ from tracim.lib.utils.authentification import basic_auth_check_credentials
13 13
 from tracim.lib.utils.authentification import BASIC_AUTH_WEBUI_REALM
14 14
 from tracim.lib.utils.authorization import AcceptAllAuthorizationPolicy
15 15
 from tracim.lib.utils.authorization import TRACIM_DEFAULT_PERM
16
+from tracim.lib.webdav import WebdavAppFactory
16 17
 from tracim.views import BASE_API_V2
17 18
 from tracim.views.core_api.session_controller import SessionController
18 19
 from tracim.views.errors import ErrorSchema
19 20
 from tracim.lib.utils.cors import add_cors_support
20 21
 
21 22
 
22
-def main(global_config, **settings):
23
+def web(global_config, **local_settings):
23 24
     """ This function returns a Pyramid WSGI application.
24 25
     """
26
+    settings = global_config
27
+    settings.update(local_settings)
25 28
     # set CFG object
26 29
     app_config = CFG(settings)
27 30
     app_config.configure_filedepot()
@@ -64,3 +67,12 @@ def main(global_config, **settings):
64 67
         'API of Tracim v2',
65 68
     )
66 69
     return configurator.make_wsgi_app()
70
+
71
+
72
+def webdav(global_config, **local_settings):
73
+    settings = global_config
74
+    settings.update(local_settings)
75
+    app_factory = WebdavAppFactory(
76
+        tracim_config_file_path=settings['__file__'],
77
+    )
78
+    return app_factory.get_wsgi_app()

+ 4 - 1
tracim/lib/webdav/__init__.py View File

@@ -48,7 +48,10 @@ class WebdavAppFactory(object):
48 48
         # Get pyramid Env
49 49
         tracim_config_file_path = os.path.abspath(tracim_config_file_path)
50 50
         config['tracim_config'] = tracim_config_file_path
51
-        settings = get_appsettings(config['tracim_config'])
51
+        global_conf = get_appsettings(config['tracim_config']).global_conf
52
+        local_conf = get_appsettings(config['tracim_config'], 'tracim_web')
53
+        settings = global_conf
54
+        settings.update(local_conf)
52 55
         app_config = CFG(settings)
53 56
 
54 57
         default_config_file = os.path.abspath(settings['wsgidav.config_path'])

+ 4 - 1
tracim/lib/webdav/middlewares.py View File

@@ -256,7 +256,10 @@ class TracimEnv(BaseMiddleware):
256 256
         super().__init__(application, config)
257 257
         self._application = application
258 258
         self._config = config
259
-        self.settings = get_appsettings(config['tracim_config'])
259
+        global_conf = get_appsettings(config['tracim_config']).global_conf
260
+        local_conf = get_appsettings(config['tracim_config'], 'tracim_web')
261
+        self.settings = global_conf
262
+        self.settings.update(local_conf)
260 263
         self.engine = get_engine(self.settings)
261 264
         self.session_factory = get_session_factory(self.engine)
262 265
         self.app_config = CFG(self.settings)

+ 5 - 4
wsgi/__init__.py View File

@@ -1,4 +1,5 @@
1 1
 # coding=utf-8
2
+import plaster
2 3
 import pyramid.paster
3 4
 
4 5
 from tracim.lib.webdav import WebdavAppFactory
@@ -10,7 +11,7 @@ def web_app(config_uri):
10 11
 
11 12
 
12 13
 def webdav_app(config_uri):
13
-    app_factory = WebdavAppFactory(
14
-        tracim_config_file_path=config_uri,
15
-    )
16
-    return app_factory.get_wsgi_app()
14
+    config_uri = '{}#webdav'.format(config_uri)
15
+    plaster.setup_logging(config_uri)
16
+    loader = plaster.get_loader(config_uri, protocols=['wsgi'])
17
+    return loader.get_wsgi_app()

+ 0 - 1
wsgi/webdav.py View File

@@ -1,7 +1,6 @@
1 1
 # coding=utf-8
2 2
 # Runner for uwsgi
3 3
 import os
4
-
5 4
 from wsgi import webdav_app
6 5
 
7 6
 config_uri = os.environ['TRACIM_CONF_PATH']