Package etl :: Package component :: Package transform :: Module merge'
[hide private]
[frames] | no frames]

Source Code for Module etl.component.transform.merge'

 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 merge all input flows. 
24   
25   Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).  
26   GNU General Public License. 
27  """ 
28   
29  from etl.component import component 
30  import sys 
31   
32 -class merge(component):
33 """ 34 This is an ETL Component that merge all input flows into only one output flow. 35 36 Type : Data Component. 37 Computing Performance : Streamline. 38 Input Flows : 0-x. 39 * .* : The main data flow with input data. 40 Output Flows : 1. 41 * .* : Returns the main flow. 42 """ 43
44 - def process(self):
45 my_gen_list = [] 46 for list_trans in self.input_get().values(): 47 my_gen_list += list_trans 48 p = -1 49 while my_gen_list: 50 p = (p+1) % len(my_gen_list) 51 try: 52 data = my_gen_list[p].next() 53 yield data, 'main' 54 except StopIteration, e: 55 del my_gen_list[p] 56 p = 0
57 58 if __name__ == '__main__': 59 # implement blackbox test 60 # Input: 61 # 'main': [{'name':'test'}], 'second': [{'name':'test2'}] 62 # Output: 63 # 'concat' 64 pass 65