Package etl :: Package connector :: Module localfile
[hide private]
[frames] | no frames]

Source Code for Module etl.connector.localfile

 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  """ 
24   To provide connectivity with Local File . 
25   
26   Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). 
27   GNU General Public License. 
28  """ 
29  from etl.connector import connector 
30   
31 -class localfile(connector):
32 """ 33 This is an ETL connector that is used to provide connectivity with Local File. 34 """
35 - def __init__(self, uri, bufsize=-1, encoding='utf-8', name='localfile'):
36 """ 37 Required Parameters 38 uri : Path of file. 39 40 Extra Parameters 41 bufsize : Buffer size for reading data. 42 encoding : Encoding format. 43 name : Name of connector. 44 """ 45 super(localfile, self).__init__(name) 46 self._type = 'connector.localfile' 47 self.bufsize = bufsize 48 self.encoding = encoding 49 self.uri = uri
50
51 - def open(self, mode='r'):
52 """ 53 Opens a file connection. 54 """ 55 # TODO : pass encoding in file 56 super(localfile, self).open() 57 return file(self.uri, mode)
58 #self.file.encoding=self.encoding 59
60 - def close(self,connector):
61 """ 62 Closes a file connection. 63 """ 64 super(localfile, self).close() 65 if connector: 66 connector.close()
67
68 - def __copy__(self):
69 """ 70 Overrides copy method. 71 """ 72 res = localfile(self.uri, self.bufsize, self.encoding, self.name) 73 return res
74 -def test():
75 76 from etl_test import etl_test 77 import etl 78 file_conn=localfile('../../demo/input/partner1.csv') 79 test = etl_test.etl_component_test(etl.component.input.csv_in(file_conn, name='csv test')) 80 test.check_output([{'tel': '+32.81.81.37.00', 'id': '11', 'name': 'Fabien'}]) 81 res=test.output() 82 print res
83 84 if __name__ == '__main__': 85 test() 86