Package etl :: Package component :: Package output :: Module openobject_out
[hide private]
[frames] | no frames]

Source Code for Module etl.component.output.openobject_out

  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 write data into open object model. 
 24   
 25   Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). 
 26   GNU General Public License. 
 27  """ 
 28  from etl.component import component 
 29   
30 -class openobject_out(component):
31 """ 32 This is an ETL Component that writes data in open object model. 33 34 Type : Data Component. 35 Computing Performance : Streamline. 36 Fields : A mapping {OpenObject Field Name : Flow Name}. 37 Input Flows : 0-x. 38 * .* : The main data flow with input data. 39 Output Flows : 0-1. 40 * main : Returns all data. 41 """ 42
43 - def __init__(self, openobject_connector, model, fields=None, name='component.output.openobject_out', transformer=None, row_limit=0):
44 """ 45 Parameters 46 openobject_connector : Open object connector to connect with OpenERP server. 47 model : Open object model name. 48 49 Extra Parameters 50 name : Name of Component. 51 transformer : Transformer object to transform string data into particular object. 52 fields : Fields of open object model. 53 model : Open object model name. 54 """ 55 super(openobject_out, self).__init__(name=name, connector=openobject_connector, transformer=transformer, row_limit=row_limit) 56 self._type = 'component.output.openobject_out' 57 self.fields = fields 58 self.model = model
59
60 - def __copy__(self):
61 res = openobject_out(self.connector, self.model, self.fields, self.name, self.transformer, self.row_limit) 62 return res
63
64 - def end(self):
65 super(openobject_out, self).end() 66 if self.op_oc: 67 self.connector.close(self.op_oc) 68 self.op_oc = False
69
70 - def process(self):
71 datas = [] 72 self.fields_keys = None 73 self.op_oc = False 74 for channel, trans in self.input_get().items(): 75 for iterator in trans: 76 for d in iterator: 77 if not self.fields: 78 self.fields = dict(map(lambda x: (x, x), d.keys())) 79 if type(self.fields) == type([]): 80 self.fields_keys = self.fields 81 self.fields = dict(map(lambda x: (x, x), self.fields)) 82 if not self.fields_keys: 83 self.fields_keys = self.fields.keys() 84 if not self.op_oc: 85 self.op_oc = self.connector.open() 86 self.connector.execute(self.op_oc, 'execute', self.model, 'import_data', self.fields_keys, [map(lambda x: d[self.fields[x]], self.fields_keys)]) 87 yield d, 'main'
88
89 -def test():
90 from etl_test import etl_test 91 import etl 92 openobject_conn = etl.connector.openobject_connector('http://localhost:8069', 'trunk', 'admin', 'admin', con_type='xmlrpc') 93 test = etl_test.etl_component_test(openobject_out(openobject_conn, 'res.country')) 94 test.check_input({'main': [{'name': 'India_test', 'code':'India_test'}]}) 95 test.check_output([{'name': 'India_test', 'code':'India_test'}], 'main') 96 res = test.output()
97 98 if __name__ == '__main__': 99 test() 100