|
@@ -1,14 +1,13 @@
|
1
|
1
|
import threading
|
2
|
2
|
from wsgiref.simple_server import make_server
|
3
|
|
-
|
4
|
3
|
import signal
|
|
4
|
+import transaction
|
5
|
5
|
|
6
|
6
|
from radicale import Application as RadicaleApplication
|
7
|
|
-from radicale import HTTPServer as RadicaleHTTPServer
|
8
|
|
-from radicale import HTTPSServer as RadicaleHTTPSServer
|
|
7
|
+from radicale import HTTPServer as BaseRadicaleHTTPServer
|
|
8
|
+from radicale import HTTPSServer as BaseRadicaleHTTPSServer
|
9
|
9
|
from radicale import RequestHandler as RadicaleRequestHandler
|
10
|
10
|
from radicale import config as radicale_config
|
11
|
|
-from tg import TGApp
|
12
|
11
|
|
13
|
12
|
from tracim.lib.base import logger
|
14
|
13
|
from tracim.lib.exceptions import AlreadyRunningDaemon
|
|
@@ -74,6 +73,24 @@ class DaemonsManager(object):
|
74
|
73
|
self._running_daemons = {}
|
75
|
74
|
|
76
|
75
|
|
|
76
|
+class TracimSocketServerMixin(object):
|
|
77
|
+ """
|
|
78
|
+ Mixin to use with socketserver.BaseServer who add _after_serve_actions
|
|
79
|
+ method executed after end of server execution.
|
|
80
|
+ """
|
|
81
|
+ def serve_forever(self, *args, **kwargs):
|
|
82
|
+ super().serve_forever(*args, **kwargs)
|
|
83
|
+ # After serving (in case of stop) do following:
|
|
84
|
+ self._after_serve_actions()
|
|
85
|
+
|
|
86
|
+ def _after_serve_actions(self):
|
|
87
|
+ """
|
|
88
|
+ Override (and call super if needed) to execute actions when server
|
|
89
|
+ finish it's job.
|
|
90
|
+ """
|
|
91
|
+ transaction.commit()
|
|
92
|
+
|
|
93
|
+
|
77
|
94
|
class Daemon(threading.Thread):
|
78
|
95
|
"""
|
79
|
96
|
Thread who contains daemon. You must implement start and stop methods to
|
|
@@ -86,6 +103,14 @@ class Daemon(threading.Thread):
|
86
|
103
|
raise NotImplementedError()
|
87
|
104
|
|
88
|
105
|
|
|
106
|
+class RadicaleHTTPSServer(TracimSocketServerMixin, BaseRadicaleHTTPSServer):
|
|
107
|
+ pass
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+class RadicaleHTTPServer(TracimSocketServerMixin, BaseRadicaleHTTPServer):
|
|
111
|
+ pass
|
|
112
|
+
|
|
113
|
+
|
89
|
114
|
class RadicaleDaemon(Daemon):
|
90
|
115
|
def __init__(self, *args, **kwargs):
|
91
|
116
|
super().__init__(*args, **kwargs)
|