Package etl :: Module signal'
[hide private]
[frames] | no frames]

Source Code for Module etl.signal'

 1  # -*- encoding: utf-8 -*- 
 2  ############################################################################## 
 3  # 
 4  #    ETL system- Extract Transfer Load system 
 5  #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved 
 6  #    $Id$ 
 7  # 
 8  #    This program is free software: you can redistribute it and/or modify 
 9  #    it under the terms of the GNU General Public License as published by 
10  #    the Free Software Foundation, either version 3 of the License, or 
11  #    (at your option) any later version. 
12  # 
13  #    This program is distributed in the hope that it will be useful, 
14  #    but WITHOUT ANY WARRANTY; without even the implied warranty of 
15  #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
16  #    GNU General Public License for more details. 
17  # 
18  #    You should have received a copy of the GNU General Public License 
19  #    along with this program.  If not, see <http://www.gnu.org/licenses/>. 
20  # 
21  ############################################################################## 
22  """  
23   To handle ETL signal. 
24   
25   Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).  
26   GNU General Public License. 
27   
28  """ 
29 -class signal(object):
30 """ 31 ETL Signal. 32 Each component can send signals. Trigger Transitions can listen to these signals. 33 Signals are automatically generated: 34 - start : When the component starts. 35 - start_input : At the first row received by the component. 36 - start_output : At the first row sent by the component. 37 - no_input : At the end of the process, when no data is received. 38 - stop : When the component is paused. 39 - continue : When the component restarts after a pause. 40 - end : When the component finishes its process. 41 - error : When the component gives error. 42 """
43 - def __init__(self, *args, **argv):
44 self.__connects = {}
45
46 - def signal(self, signal, signal_data=None):
47 for fnct, data, key in self.__connects.get(signal, []): 48 fnct(key, signal_data, *data)
49 50
51 - def signal_connect(self, key, signal, fnct, *data):
52 self.__connects.setdefault(signal, []) 53 if (fnct, data, key) not in self.__connects[signal]: 54 self.__connects[signal].append((fnct, data, key))
55 56
57 - def signal_unconnect(self, key, signal=None):
58 if not signal: 59 signal = self.__connects.keys() 60 else: 61 signal = [signal] 62 for sig in signal: 63 i = 0 64 while i < len(self.__connects[sig]): 65 if self.__connects[sig][i][2] == key: 66 del self.__connects[sig][i] 67 else: 68 i += 1
69