kernel: don't use mutable as default value in function defintion.
[odoo/odoo.git] / bin / tools / convert.py
1 #----------------------------------------------------------
2 # Convert 
3 #----------------------------------------------------------
4 import re
5 import StringIO,xml.dom.minidom
6 import osv,ir,pooler
7
8 import csv
9 import os.path
10 import misc
11 import netsvc
12
13 from config import config
14
15
16 # Number of imported lines between two commit (see convert_csv_import()):
17 COMMIT_STEP = 500 
18
19
20 class ConvertError(Exception):
21         def __init__(self, doc, orig_excpt):
22                 self.d = doc
23                 self.orig = orig_excpt
24         
25         def __str__(self):
26                 return 'Exception:\n\t%s\nUsing file:\n%s' % (self.orig, self.d)
27
28 def _eval_xml(self,node, pool, cr, uid, idref):
29         if node.nodeType == node.TEXT_NODE:
30                 return node.data.encode("utf8")
31         elif node.nodeType == node.ELEMENT_NODE:
32                 if node.nodeName in ('field','value'):
33                         t = node.getAttribute('type') or 'char'
34                         if len(node.getAttribute('search')):
35                                 f_search = node.getAttribute("search").encode('utf-8')
36                                 f_model = node.getAttribute("model").encode('ascii')
37                                 f_use = node.getAttribute("use").encode('ascii')
38                                 f_name = node.getAttribute("name").encode('utf-8')
39                                 if len(f_use)==0:
40                                         f_use = "id"
41                                 q = eval(f_search, idref)
42                                 ids = pool.get(f_model).search(cr, uid, q)
43                                 if f_use<>'id':
44                                         ids = map(lambda x: x[f_use], pool.get(f_model).read(cr, uid, ids, [f_use]))
45                                 _cols = pool.get(f_model)._columns
46                                 if (f_name in _cols) and _cols[f_name]._type=='many2many':
47                                         return ids
48                                 f_val = False
49                                 if len(ids):
50                                         f_val = ids[0]
51                                         if isinstance(f_val, tuple):
52                                                 f_val = f_val[0]
53                                 return f_val
54                         a_eval = node.getAttribute('eval')
55                         if len(a_eval):
56                                 import time
57                                 idref['time'] = time
58                                 idref['ref'] = lambda x: self.id_get(cr, False, x)
59                                 try:
60                                         import pytz
61                                 except:
62                                         logger = netsvc.Logger()
63                                         logger.notifyChannel("init", netsvc.LOG_INFO, 'could not find pytz library')
64                                         class pytzclass(object):
65                                                 all_timezones=[]
66                                         pytz=pytzclass()
67                                 idref['pytz'] = pytz
68                                 return eval(a_eval, idref)
69                         if t == 'xml':
70                                 def _process(s, idref):
71                                         m = re.findall('[^%]%\((.*?)\)[ds]', s)
72                                         for id in m:
73                                                 if not id in idref:
74                                                         idref[id]=self.id_get(cr, False, id)
75                                         return s % idref
76                                 txt = '<?xml version="1.0"?>\n'+_process("".join([i.toxml().encode("utf8") for i in node.childNodes]), idref)
77 #                               txt = '<?xml version="1.0"?>\n'+"".join([i.toxml().encode("utf8") for i in node.childNodes]) % idref
78
79                                 return txt
80                         if t in ('char', 'int', 'float'):
81                                 d = ""
82                                 for n in [i for i in node.childNodes]:
83                                         d+=str(_eval_xml(self,n,pool,cr,uid,idref))
84                                 if t == 'int':
85                                         d = d.strip()
86                                         if d=='None':
87                                                 return None
88                                         else:
89                                                 d=int(d.strip())
90                                 elif t=='float':
91                                         d=float(d.strip())
92                                 return d
93                         elif t in ('list','tuple'):
94                                 res=[]
95                                 for n in [i for i in node.childNodes if (i.nodeType == i.ELEMENT_NODE and i.nodeName=='value')]:
96                                         res.append(_eval_xml(self,n,pool,cr,uid,idref))
97                                 if t=='tuple':
98                                         return tuple(res)
99                                 return res
100                 elif node.nodeName=="getitem":
101                         for n in [i for i in node.childNodes if (i.nodeType == i.ELEMENT_NODE)]:
102                                 res=_eval_xml(self,n,pool,cr,uid,idref)
103                         if not res:
104                                 raise LookupError
105                         elif node.getAttribute('type') in ("int", "list"):
106                                 return res[int(node.getAttribute('index'))]
107                         else:
108                                 return res[node.getAttribute('index').encode("utf8")]
109                 elif node.nodeName=="function":
110                         args = []
111                         a_eval = node.getAttribute('eval')
112                         if len(a_eval):
113                                 idref['ref'] = lambda x: self.id_get(cr, False, x)
114                                 args = eval(a_eval, idref)
115                         for n in [i for i in node.childNodes if (i.nodeType == i.ELEMENT_NODE)]:
116                                 args.append(_eval_xml(self,n, pool, cr, uid, idref))
117                         model = pool.get(node.getAttribute('model'))
118                         method = node.getAttribute('name')
119                         res = getattr(model, method)(cr, uid, *args)
120                         return res
121
122 escape_re = re.compile(r'(?<!\\)/')
123 def escape(x):
124         return x.replace('\\/', '/')
125
126 class xml_import(object):
127
128         def _test_xml_id(self, xml_id):
129                 id = xml_id
130                 if '.' in xml_id:
131                         base, id = xml_id.split('.')
132                 if len(id) > 64:
133                         self.logger.notifyChannel('init', netsvc.LOG_ERROR, 'id: %s is to long (max: 64)'%xml_id)
134         def _tag_delete(self, cr, rec, data_node=None):
135                 d_model = rec.getAttribute("model")
136                 d_search = rec.getAttribute("search")
137                 ids = self.pool.get(d_model).search(cr,self.uid,eval(d_search))
138                 if len(ids):
139                         self.pool.get(d_model).unlink(cr, self.uid, ids)
140                         #self.pool.get('ir.model.data')._unlink(cr, self.uid, d_model, ids, direct=True)
141                 return False
142
143         def _tag_report(self, cr, rec, data_node=None):
144                 res = {}
145                 for dest,f in (('name','string'),('model','model'),('report_name','name')):
146                         res[dest] = rec.getAttribute(f).encode('utf8')
147                         assert res[dest], "Attribute %s of report is empty !" % (f,)
148                 for field,dest in (('rml','report_rml'),('xml','report_xml'),('xsl','report_xsl')):
149                         if rec.hasAttribute(field):
150                                 res[dest] = rec.getAttribute(field).encode('utf8')
151                 if rec.hasAttribute('auto'):
152                         res['auto'] = eval(rec.getAttribute('auto'))
153                 if rec.hasAttribute('sxw'):
154                         sxw_content = misc.file_open(rec.getAttribute('sxw')).read()
155                         res['report_sxw_content'] = sxw_content
156                 if rec.hasAttribute('header'):
157                         res['header'] = eval(rec.getAttribute('header'))
158                 res['multi'] = rec.hasAttribute('multi') and  eval(rec.getAttribute('multi'))
159                 xml_id = rec.getAttribute('id').encode('utf8')
160                 self._test_xml_id(xml_id)
161                 id = self.pool.get('ir.model.data')._update(cr, self.uid, "ir.actions.report.xml", self.module, res, xml_id, mode=self.mode)
162                 self.idref[xml_id] = id
163                 if not rec.hasAttribute('menu') or eval(rec.getAttribute('menu')):
164                         keyword = str(rec.getAttribute('keyword') or 'client_print_multi')
165                         keys = [('action',keyword),('res_model',res['model'])]
166                         value = 'ir.actions.report.xml,'+str(id)
167                         replace = rec.hasAttribute('replace') and rec.getAttribute("replace")
168                         self.pool.get('ir.model.data').ir_set(cr, self.uid, 'action', keyword, res['name'], [res['model']], value, replace=replace, isobject=True, xml_id=xml_id)
169                 return False
170
171         def _tag_function(self, cr, rec, data_node=None):
172                 _eval_xml(self,rec, self.pool, cr, self.uid, self.idref)
173                 return False
174
175         def _tag_wizard(self, cr, rec, data_node=None):
176                 string = rec.getAttribute("string").encode('utf8')
177                 model = rec.getAttribute("model").encode('utf8')
178                 name = rec.getAttribute("name").encode('utf8')
179                 xml_id = rec.getAttribute('id').encode('utf8')
180                 self._test_xml_id(xml_id)
181                 multi = rec.hasAttribute('multi') and  eval(rec.getAttribute('multi'))
182                 res = {'name': string, 'wiz_name': name, 'multi':multi}
183
184                 id = self.pool.get('ir.model.data')._update(cr, self.uid, "ir.actions.wizard", self.module, res, xml_id, mode=self.mode)
185                 self.idref[xml_id] = id
186                 # ir_set
187                 if not rec.hasAttribute('menu') or eval(rec.getAttribute('menu')):
188                         keyword = str(rec.getAttribute('keyword') or 'client_action_multi')
189                         keys = [('action',keyword),('res_model',model)]
190                         value = 'ir.actions.wizard,'+str(id)
191                         replace = rec.hasAttribute('replace') and rec.getAttribute("replace")
192                         self.pool.get('ir.model.data').ir_set(cr, self.uid, 'action', keyword, string, [model], value, replace=replace, isobject=True, xml_id=xml_id)
193                 return False
194
195         def _tag_act_window(self, cr, rec, data_node=None):
196                 name = rec.hasAttribute('name') and rec.getAttribute('name').encode('utf-8')
197                 xml_id = rec.getAttribute('id').encode('utf8')
198                 self._test_xml_id(xml_id)
199                 type = rec.hasAttribute('type') and rec.getAttribute('type').encode('utf-8') or 'ir.actions.act_window'
200                 view_id = False
201                 if rec.hasAttribute('view'):
202                         view_id = self.id_get(cr, 'ir.actions.act_window', rec.getAttribute('view').encode('utf-8'))
203                 domain = rec.hasAttribute('domain') and rec.getAttribute('domain').encode('utf-8')
204                 context = rec.hasAttribute('context') and rec.getAttribute('context').encode('utf-8') or '{}'
205                 res_model = rec.getAttribute('res_model').encode('utf-8')
206                 src_model = rec.hasAttribute('src_model') and rec.getAttribute('src_model').encode('utf-8')
207                 view_type = rec.hasAttribute('view_type') and rec.getAttribute('view_type').encode('utf-8') or 'form'
208                 view_mode = rec.hasAttribute('view_mode') and rec.getAttribute('view_mode').encode('utf-8') or 'tree,form'
209                 usage = rec.hasAttribute('usage') and rec.getAttribute('usage').encode('utf-8')
210
211                 res = {'name': name, 'type': type, 'view_id': view_id, 'domain': domain, 'context': context, 'res_model': res_model, 'src_model': src_model, 'view_type': view_type, 'view_mode': view_mode, 'usage': usage }
212
213                 id = self.pool.get('ir.model.data')._update(cr, self.uid, 'ir.actions.act_window', self.module, res, xml_id, mode=self.mode)
214                 self.idref[xml_id] = id
215
216                 if src_model:
217                         keyword = 'client_action_relate'
218                         keys = [('action', keyword), ('res_model', res_model)]
219                         value = 'ir.actions.act_window,'+str(id)
220                         replace = rec.hasAttribute('replace') and rec.getAttribute('replace')
221                         self.pool.get('ir.model.data').ir_set(cr, self.uid, 'action', keyword, xml_id, [src_model], value, replace=replace, isobject=True, xml_id=xml_id)
222                 return False
223
224         def _tag_ir_set(self, cr, rec, data_node=None):
225                 if not self.mode=='init':
226                         return False
227                 res = {}
228                 for field in [i for i in rec.childNodes if (i.nodeType == i.ELEMENT_NODE and i.nodeName=="field")]:
229                         f_name = field.getAttribute("name").encode('utf-8')
230                         f_val = _eval_xml(self,field,self.pool, cr, self.uid, self.idref)
231                         res[f_name] = f_val
232                 self.pool.get('ir.model.data').ir_set(cr, self.uid, res['key'], res['key2'], res['name'], res['models'], res['value'], replace=res.get('replace',True), isobject=res.get('isobject', False), meta=res.get('meta',None))
233                 return False
234
235         def _tag_workflow(self, cr, rec, data_node=None):
236                 model = str(rec.getAttribute('model'))
237                 wf_service = netsvc.LocalService("workflow")
238                 wf_service.trg_validate(self.uid, model,
239                         self.id_get(cr, model, rec.getAttribute('ref')),
240                         str(rec.getAttribute('action')), cr)
241                 return False
242
243         def _tag_menuitem(self, cr, rec, data_node=None):
244                 rec_id = rec.getAttribute("id").encode('ascii')
245                 self._test_xml_id(rec_id)
246                 m_l = map(escape, escape_re.split(rec.getAttribute("name").encode('utf8')))
247                 pid = False
248                 for idx, menu_elem in enumerate(m_l):
249                         if pid:
250                                 cr.execute('select id from ir_ui_menu where parent_id=%d and name=%s', (pid, menu_elem))
251                         else:
252                                 cr.execute('select id from ir_ui_menu where parent_id is null and name=%s', (menu_elem,))
253                         res = cr.fetchone()
254                         if idx==len(m_l)-1:
255                                 # we are at the last menu element/level (it's a leaf)
256                                 values = {'parent_id': pid,'name':menu_elem}
257
258                                 if rec.hasAttribute('action'):
259                                         a_action = rec.getAttribute('action').encode('utf8')
260                                         a_type = rec.getAttribute('type').encode('utf8') or 'act_window'
261                                         icons = {
262                                                 "act_window": 'STOCK_NEW',
263                                                 "report.xml": 'STOCK_PASTE',
264                                                 "wizard": 'STOCK_EXECUTE',
265                                         }
266                                         values['icon'] = icons.get(a_type,'STOCK_NEW')
267                                         if a_type=='act_window':
268                                                 a_id = self.id_get(cr, 'ir.actions.%s'% a_type, a_action)
269                                                 cr.execute('select view_type,view_mode,name,view_id from ir_act_window where id=%d', (int(a_id),))
270                                                 action_type,action_mode,action_name,view_id = cr.fetchone()
271                                                 if view_id:
272                                                         cr.execute('SELECT type FROM ir_ui_view WHERE id=%d', (int(view_id),))
273                                                         action_mode, = cr.fetchone()
274                                                 cr.execute('SELECT view_mode FROM ir_act_window_view WHERE act_window_id=%d ORDER BY sequence LIMIT 1', (int(a_id),))
275                                                 if cr.rowcount:
276                                                         action_mode, = cr.fetchone()
277                                                 if action_type=='tree':
278                                                         values['icon'] = 'STOCK_INDENT'
279                                                 elif action_mode and action_mode.startswith('tree'):
280                                                         values['icon'] = 'STOCK_JUSTIFY_FILL'
281                                                 elif action_mode and action_mode.startswith('graph'):
282                                                         values['icon'] = 'terp-account'
283                                                 if not values['name']:
284                                                         values['name'] = action_name
285                                 if rec.hasAttribute('sequence'):
286                                         values['sequence'] = int(rec.getAttribute('sequence'))
287                                 if rec.hasAttribute('icon'):
288                                         values['icon'] = str(rec.getAttribute('icon'))
289                                 if rec.hasAttribute('groups'):
290                                         g_names = rec.getAttribute('groups').split(',')
291                                         g_ids = []
292                                         for group in g_names:
293                                                 g_ids.extend(self.pool.get('res.groups').search(cr, self.uid, [('name', '=', group)]))
294                                         values['groups_id'] = [(6, 0, g_ids)]
295                                 xml_id = rec.getAttribute('id').encode('utf8')
296                                 self._test_xml_id(xml_id)
297                                 pid = self.pool.get('ir.model.data')._update(cr, self.uid, 'ir.ui.menu', self.module, values, xml_id, idx==len(m_l)-1, mode=self.mode, res_id=res and res[0] or False)
298                         elif res:
299                                 # the menuitem already exists
300                                 pid = res[0]
301                                 xml_id = idx==len(m_l)-1 and rec.getAttribute('id').encode('utf8')
302                                 try:
303                                         npid = self.pool.get('ir.model.data')._update_dummy(cr, self.uid, 'ir.ui.menu', self.module, xml_id, idx==len(m_l)-1)
304                                 except:
305                                         print 'Menu Error', self.module, xml_id, idx==len(m_l)-1
306                         else:
307                                 # the menuitem does't exist but we are in branch (not a leaf)
308                                 pid = self.pool.get('ir.ui.menu').create(cr, self.uid, {'parent_id' : pid, 'name' : menu_elem})
309                 if rec_id and pid:
310                         self.idref[rec_id] = pid
311
312                 if rec.hasAttribute('action') and pid:
313                         a_action = rec.getAttribute('action').encode('utf8')
314                         a_type = rec.getAttribute('type').encode('utf8') or 'act_window'
315                         a_id = self.id_get(cr, 'ir.actions.%s' % a_type, a_action)
316                         action = "ir.actions.%s,%d" % (a_type, a_id)
317                         self.pool.get('ir.model.data').ir_set(cr, self.uid, 'action', 'tree_but_open', 'Menuitem', [('ir.ui.menu', int(pid))], action, True, True, xml_id=rec_id)
318                 return ('ir.ui.menu', pid)
319
320         def _tag_assert(self, cr, rec, data_node=None):
321                 rec_model = rec.getAttribute("model").encode('ascii')
322                 model = self.pool.get(rec_model)
323                 assert model, "The model %s does not exist !" % (rec_model,)
324                 rec_id = rec.getAttribute("id").encode('ascii')
325                 self._test_xml_id(rec_id)
326                 id = self.id_get(cr, False, rec_id)
327                 if data_node.getAttribute('noupdate') and not self.mode == 'init':
328                         for test in [i for i in rec.childNodes if (i.nodeType == i.ELEMENT_NODE and i.nodeName=="test")]:
329                                 f_expr = test.getAttribute("expr").encode('utf-8')
330                                 class d(dict):
331                                         def __getitem__(self2, key):
332                                                 return getattr(model.browse(cr, self.uid, id), key)
333
334         def _tag_record(self, cr, rec, data_node=None):
335                 rec_model = rec.getAttribute("model").encode('ascii')
336                 model = self.pool.get(rec_model)
337                 assert model, "The model %s does not exist !" % (rec_model,)
338                 rec_id = rec.getAttribute("id").encode('ascii')
339                 self._test_xml_id(rec_id)
340
341 #               if not rec_id and not data_node.getAttribute('noupdate'):
342 #                       print "Warning", rec_model
343
344                 if data_node.getAttribute('noupdate') and not self.mode == 'init':
345                         # check if the xml record has an id string
346                         if rec_id:
347                                 id = self.pool.get('ir.model.data')._update_dummy(cr, self.uid, rec_model, self.module, rec_id)
348                                 # check if the resource already existed at the last update
349                                 if id:
350                                         # if it existed, we don't update the data, but we need to 
351                                         # know the id of the existing record anyway
352                                         self.idref[rec_id] = id
353                                         return None
354                                 else:
355                                         # if the resource didn't exist
356                                         if rec.getAttribute("forcecreate"):
357                                                 # we want to create it, so we let the normal "update" behavior happen
358                                                 pass
359                                         else:
360                                                 # otherwise do nothing
361                                                 return None
362                         else:
363                                 # otherwise it is skipped
364                                 return None
365                                 
366                 res = {}
367                 for field in [i for i in rec.childNodes if (i.nodeType == i.ELEMENT_NODE and i.nodeName=="field")]:
368 #TODO: most of this code is duplicated above (in _eval_xml)...
369                         f_name = field.getAttribute("name").encode('utf-8')
370                         f_ref = field.getAttribute("ref").encode('ascii')
371                         f_search = field.getAttribute("search").encode('utf-8')
372                         f_model = field.getAttribute("model").encode('ascii')
373                         if not f_model and model._columns.get(f_name,False):
374                                 f_model = model._columns[f_name]._obj
375                         f_use = field.getAttribute("use").encode('ascii') or 'id'
376                         f_val = False
377
378                         if len(f_search):
379                                 q = eval(f_search, self.idref)
380                                 field = []
381                                 assert f_model, 'Define an attribute model="..." in your .XML file !'
382                                 f_obj = self.pool.get(f_model)
383                                 # browse the objects searched
384                                 s = f_obj.browse(cr, self.uid, f_obj.search(cr, self.uid, q))
385                                 # column definitions of the "local" object
386                                 _cols = self.pool.get(rec_model)._columns
387                                 # if the current field is many2many
388                                 if (f_name in _cols) and _cols[f_name]._type=='many2many':
389                                         f_val = [(6, 0, map(lambda x: x[f_use], s))]
390                                 elif len(s):
391                                         # otherwise (we are probably in a many2one field),
392                                         # take the first element of the search
393                                         f_val = s[0][f_use]
394                         elif len(f_ref):
395                                 if f_ref=="null":
396                                         f_val = False
397                                 else:
398                                         f_val = self.id_get(cr, f_model, f_ref)
399                         else:
400                                 f_val = _eval_xml(self,field, self.pool, cr, self.uid, self.idref)
401                                 if model._columns.has_key(f_name):
402                                         if isinstance(model._columns[f_name], osv.fields.integer):
403                                                 f_val = int(f_val)
404                         res[f_name] = f_val
405                 id = self.pool.get('ir.model.data')._update(cr, self.uid, rec_model, self.module, res, rec_id or False, not data_node.getAttribute('noupdate'), noupdate=data_node.getAttribute('noupdate'), mode=self.mode )
406                 if rec_id:
407                         self.idref[rec_id] = id
408                 return rec_model, id
409
410         def id_get(self, cr, model, id_str):
411                 if id_str in self.idref:
412                         return self.idref[id_str]
413                 mod = self.module
414                 if '.' in id_str:
415                         mod,id_str = id_str.split('.')
416                 result = self.pool.get('ir.model.data')._get_id(cr, self.uid, mod, id_str)
417                 return self.pool.get('ir.model.data').read(cr, self.uid, [result], ['res_id'])[0]['res_id']
418
419         def parse(self, xmlstr):
420                 d = xml.dom.minidom.parseString(xmlstr)
421                 de = d.documentElement
422                 for n in [i for i in de.childNodes if (i.nodeType == i.ELEMENT_NODE and i.nodeName=="data")]:
423                         for rec in n.childNodes:
424                                 if rec.nodeType == rec.ELEMENT_NODE:
425                                         if rec.nodeName in self._tags:
426                                                 try:
427                                                         self._tags[rec.nodeName](self.cr, rec, n)
428                                                 except:
429                                                         self.logger.notifyChannel("init", netsvc.LOG_INFO, '\n'+rec.toxml())
430                                                         self.cr.rollback()
431                                                         raise
432                 self.cr.commit()
433                 return True
434
435         def __init__(self, cr, module, idref, mode):
436                 self.logger = netsvc.Logger()
437                 self.mode = mode
438                 self.module = module
439                 self.cr = cr
440                 self.idref = idref
441                 self.pool = pooler.get_pool(cr.dbname)
442 #               self.pool = osv.osv.FakePool(module)
443                 self.uid = 1
444                 self._tags = {
445                         'menuitem': self._tag_menuitem,
446                         'record': self._tag_record,
447                         'assert': self._tag_assert,
448                         'report': self._tag_report,
449                         'wizard': self._tag_wizard,
450                         'delete': self._tag_delete,
451                         'ir_set': self._tag_ir_set,
452                         'function': self._tag_function,
453                         'workflow': self._tag_workflow,
454                         'act_window': self._tag_act_window,
455                 }
456
457 #
458 # Import a CSV file:
459 #     quote: "
460 #     delimiter: ,
461 #     encoding: UTF8
462 #
463 def convert_csv_import(cr, module, fname, csvcontent, idref=None, mode='init', noupdate=False):
464         if not idref:
465                 idref={}
466         model = ('.'.join(fname.split('.')[:-1]).split('-'))[0]
467         #remove folder path from model
468         head, model = os.path.split(model)
469
470         pool = pooler.get_pool(cr.dbname)
471
472         input=StringIO.StringIO(csvcontent)
473         reader = csv.reader(input, quotechar='"', delimiter=',')
474         fields = reader.next()
475         
476         if not (mode == 'init' or 'id' in fields):
477                 return
478         
479         uid = 1
480         datas = []
481         for line in reader:
482                 datas.append( map(lambda x:x.decode('utf8').encode('utf8'), line))
483                 if len(datas) > COMMIT_STEP:
484                         pool.get(model).import_data(cr, uid, fields, datas,mode, module,noupdate)
485                         cr.commit()
486                         datas=[]
487
488         if datas:
489                 pool.get(model).import_data(cr, uid, fields, datas,mode, module,noupdate)
490                 cr.commit()
491
492 #
493 # xml import/export
494 #
495 def convert_xml_import(cr, module, xmlstr, idref=None, mode='init'):
496         if not idref:
497                 idref={}
498         obj = xml_import(cr, module, idref, mode)
499         obj.parse(xmlstr)
500         del obj
501         return True
502
503 def convert_xml_export(res):
504         uid=1
505         pool=pooler.get_pool(cr.dbname)
506         cr=pooler.db.cursor()
507         idref = {}
508         d = xml.dom.minidom.getDOMImplementation().createDocument(None, "terp", None)
509         de = d.documentElement
510         data=d.createElement("data")
511         de.appendChild(data)
512         de.appendChild(d.createTextNode('Some textual content.'))
513         cr.commit()
514         cr.close()
515