##// END OF EJS Templates
svn-support: Remove commented code.
Martin Bornhold -
r1018:003babb4 default
parent child Browse files
Show More
@@ -1,156 +1,109 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2016-2016 RhodeCode GmbH
3 # Copyright (C) 2016-2016 RhodeCode GmbH
4 #
4 #
5 # This program is free software: you can redistribute it and/or modify
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License, version 3
6 # it under the terms of the GNU Affero General Public License, version 3
7 # (only), as published by the Free Software Foundation.
7 # (only), as published by the Free Software Foundation.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU Affero General Public License
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
16 #
17 # This program is dual-licensed. If you wish to learn more about the
17 # This program is dual-licensed. If you wish to learn more about the
18 # RhodeCode Enterprise Edition, including its added features, Support services,
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
20
21 import logging
21 import logging
22 import Queue
22 import Queue
23 import subprocess32
23 import subprocess32
24 from threading import Thread
24 from threading import Thread
25
25
26
26
27 from .utils import generate_mod_dav_svn_config
27 from .utils import generate_mod_dav_svn_config
28
28
29
29
30 log = logging.getLogger(__name__)
30 log = logging.getLogger(__name__)
31
31
32
32
33 def generate_config_subscriber(event):
33 def generate_config_subscriber(event):
34 """
34 """
35 Subscriber to the `rhodcode.events.RepoGroupEvent`. This triggers the
35 Subscriber to the `rhodcode.events.RepoGroupEvent`. This triggers the
36 automatic generation of mod_dav_svn config file on repository group
36 automatic generation of mod_dav_svn config file on repository group
37 changes.
37 changes.
38 """
38 """
39 try:
39 try:
40 generate_mod_dav_svn_config(event.request.registry)
40 generate_mod_dav_svn_config(event.request.registry)
41 except Exception:
41 except Exception:
42 log.exception(
42 log.exception(
43 'Exception while generating subversion mod_dav_svn configuration.')
43 'Exception while generating subversion mod_dav_svn configuration.')
44
44
45
45
46 class Subscriber(object):
46 class Subscriber(object):
47 def __call__(self, event):
47 def __call__(self, event):
48 self.run(event)
48 self.run(event)
49
49
50 def run(self, event):
50 def run(self, event):
51 raise NotImplementedError('Subclass has to implement this.')
51 raise NotImplementedError('Subclass has to implement this.')
52
52
53
53
54 class AsyncSubscriber(Subscriber):
54 class AsyncSubscriber(Subscriber):
55 def __init__(self):
55 def __init__(self):
56 self._stop = False
56 self._stop = False
57 self._eventq = Queue.Queue()
57 self._eventq = Queue.Queue()
58 self._worker = self.create_worker()
58 self._worker = self.create_worker()
59 self._worker.start()
59 self._worker.start()
60
60
61 def __call__(self, event):
61 def __call__(self, event):
62 self._eventq.put(event)
62 self._eventq.put(event)
63
63
64 def create_worker(self):
64 def create_worker(self):
65 worker = Thread(target=self.do_work)
65 worker = Thread(target=self.do_work)
66 worker.daemon = True
66 worker.daemon = True
67 return worker
67 return worker
68
68
69 def stop_worker(self):
69 def stop_worker(self):
70 self._stop = False
70 self._stop = False
71 self._eventq.put(None)
71 self._eventq.put(None)
72 self._worker.join()
72 self._worker.join()
73
73
74 def do_work(self):
74 def do_work(self):
75 while not self._stop:
75 while not self._stop:
76 event = self._eventq.get()
76 event = self._eventq.get()
77 if event is not None:
77 if event is not None:
78 self.run(event)
78 self.run(event)
79
79
80
80
81 class AsyncSubprocessSubscriber(AsyncSubscriber):
81 class AsyncSubprocessSubscriber(AsyncSubscriber):
82
82
83 def __init__(self, cmd, timeout=None):
83 def __init__(self, cmd, timeout=None):
84 super(AsyncSubprocessSubscriber, self).__init__()
84 super(AsyncSubprocessSubscriber, self).__init__()
85 self._cmd = cmd
85 self._cmd = cmd
86 self._timeout = timeout
86 self._timeout = timeout
87
87
88 def run(self, event):
88 def run(self, event):
89 cmd = self._cmd
89 cmd = self._cmd
90 timeout = self._timeout
90 timeout = self._timeout
91 log.debug('Executing command %s.', cmd)
91 log.debug('Executing command %s.', cmd)
92
92
93 try:
93 try:
94 output = subprocess32.check_output(
94 output = subprocess32.check_output(
95 cmd, timeout=timeout, stderr=subprocess32.STDOUT)
95 cmd, timeout=timeout, stderr=subprocess32.STDOUT)
96 log.debug('Command finished %s', cmd)
96 log.debug('Command finished %s', cmd)
97 if output:
97 if output:
98 log.debug('Command output: %s', output)
98 log.debug('Command output: %s', output)
99 except subprocess32.TimeoutExpired as e:
99 except subprocess32.TimeoutExpired as e:
100 log.exception('Timeout while executing command.')
100 log.exception('Timeout while executing command.')
101 if e.output:
101 if e.output:
102 log.error('Command output: %s', e.output)
102 log.error('Command output: %s', e.output)
103 except subprocess32.CalledProcessError as e:
103 except subprocess32.CalledProcessError as e:
104 log.exception('Error while executing command.')
104 log.exception('Error while executing command.')
105 if e.output:
105 if e.output:
106 log.error('Command output: %s', e.output)
106 log.error('Command output: %s', e.output)
107 except:
107 except:
108 log.exception(
108 log.exception(
109 'Exception while executing command %s.', cmd)
109 'Exception while executing command %s.', cmd)
110
111
112 # class ReloadApacheSubscriber(object):
113 # """
114 # Subscriber to pyramids event system. It executes the Apache reload command
115 # if set in ini-file. The command is executed asynchronously in a separate
116 # task. This is done to prevent a delay of the function which triggered the
117 # event in case of a longer running command. If a timeout is passed to the
118 # constructor the command will be terminated after expiration.
119 # """
120 # def __init__(self, settings, timeout=None):
121 # self.thread = None
122 # cmd = self.get_command_from_settings(settings)
123 # if cmd:
124 # kwargs = {
125 # 'cmd': cmd,
126 # 'timeout': timeout,
127 # }
128 # self.thread = Thread(target=self.run, kwargs=kwargs)
129
130 # def __call__(self, event):
131 # if self.thread is not None:
132 # self.thread.start()
133
134 # def get_command_from_settings(self, settings):
135 # cmd = settings[config_keys.reload_command]
136 # return cmd.split(' ') if cmd else cmd
137
138 # def run(self, cmd, timeout=None):
139 # log.debug('Executing svn proxy reload command %s.', cmd)
140 # try:
141 # output = subprocess32.check_output(
142 # cmd, timeout=timeout, stderr=subprocess32.STDOUT)
143 # log.debug('Svn proxy reload command finished.')
144 # if output:
145 # log.debug('Command output: %s', output)
146 # except subprocess32.TimeoutExpired as e:
147 # log.exception('Timeout while executing svn proxy reload command.')
148 # if e.output:
149 # log.error('Command output: %s', e.output)
150 # except subprocess32.CalledProcessError as e:
151 # log.exception('Error while executing svn proxy reload command.')
152 # if e.output:
153 # log.error('Command output: %s', e.output)
154 # except:
155 # log.exception(
156 # 'Exception while executing svn proxy reload command %s.', cmd)
General Comments 0
You need to be logged in to leave comments. Login now