[IMP] Warn if an assertion has not been evaluated.
[odoo/odoo.git] / bin / tools / yaml_import.py
1 # -*- encoding: utf-8 -*-
2 import types
3 import time # used to eval time.strftime expressions
4 import logging
5
6 import pooler
7 import netsvc
8 import misc
9 from config import config
10 import yaml_tag
11
12 import yaml
13
14 logger_channel = 'tests'
15
16 class YamlImportException(Exception):
17     pass
18
19 class YamlImportAbortion(Exception):
20     pass
21
22 def _is_yaml_mapping(node, tag_constructor):
23     value = isinstance(node, types.DictionaryType) \
24         and len(node.keys()) == 1 \
25         and isinstance(node.keys()[0], tag_constructor)
26     return value
27
28 def is_comment(node):
29     return isinstance(node, types.StringTypes)
30
31 def is_assert(node):
32     return _is_yaml_mapping(node, yaml_tag.Assert)
33
34 def is_record(node):
35     return _is_yaml_mapping(node, yaml_tag.Record)
36
37 def is_python(node):
38     return _is_yaml_mapping(node, yaml_tag.Python)
39
40 def is_menuitem(node):
41     return isinstance(node, yaml_tag.Menuitem) \
42         or _is_yaml_mapping(node, yaml_tag.Menuitem)
43
44 def is_function(node):
45     return isinstance(node, yaml_tag.Function) \
46         or _is_yaml_mapping(node, yaml_tag.Function)
47
48 def is_report(node):
49     return isinstance(node, yaml_tag.Report)
50
51 def is_workflow(node):
52     return isinstance(node, yaml_tag.Workflow)
53
54 def is_act_window(node):
55     return isinstance(node, yaml_tag.ActWindow)
56
57 def is_delete(node):
58     return isinstance(node, yaml_tag.Delete)
59
60 def is_context(node):
61     return isinstance(node, yaml_tag.Context)
62
63 def is_url(node):
64     return isinstance(node, yaml_tag.Url)
65
66 def is_eval(node):
67     return isinstance(node, yaml_tag.Eval)
68     
69 def is_ref(node):
70     return isinstance(node, yaml_tag.Ref) \
71         or _is_yaml_mapping(node, yaml_tag.Ref)
72     
73 def is_ir_set(node):
74     return _is_yaml_mapping(node, yaml_tag.IrSet)
75
76
77 class TestReport(object):
78     def __init__(self):
79         self._report = {}
80
81     def record(self, success, severity):
82         """
83         Records the result of an assertion for the failed/success count.
84         Returns success.
85         """
86         if severity in self._report:
87             self._report[severity][success] += 1
88         else:
89             self._report[severity] = {success: 1, not success: 0}
90         return success
91
92     def __str__(self):
93         res = []
94         res.append('\nAssertions report:\nLevel\tsuccess\tfailure')
95         success = failure = 0
96         for severity in self._report:
97             res.append("%s\t%s\t%s" % (severity, self._report[severity][True], self._report[severity][False]))
98             success += self._report[severity][True]
99             failure += self._report[severity][False]
100         res.append("total\t%s\t%s" % (success, failure))
101         res.append("end of report (%s assertion(s) checked)" % success + failure)
102         return "\n".join(res)
103
104 class RecordDictWrapper(dict):
105     """
106     Used to pass a record as locals in eval:
107     records do not strictly behave like dict, so we force them to.
108     """
109     def __init__(self, record):
110         self.record = record 
111     def __getitem__(self, key):
112         if key in self.record:
113             return self.record[key]
114         return dict.__getitem__(self, key)
115  
116 class YamlInterpreter(object):
117     def __init__(self, cr, module, id_map, mode, filename, noupdate=False):
118         self.cr = cr
119         self.module = module
120         self.id_map = id_map
121         self.mode = mode
122         self.filename = filename
123         self.assert_report = TestReport()
124         self.noupdate = noupdate
125         self.logger = logging.getLogger("%s.%s" % (logger_channel, self.module))
126         self.pool = pooler.get_pool(cr.dbname)
127         self.uid = 1
128         self.context = {} # opererp context
129         self.eval_context = {'ref': self._ref, '_ref': self._ref, 'time': time} # added '_ref' so that record['ref'] is possible
130
131     def _ref(self):
132         return lambda xml_id: self.get_id(xml_id)
133
134     def get_model(self, model_name):
135         model = self.pool.get(model_name)
136         assert model, "The model %s does not exist." % (model_name,)
137         return model
138     
139     def validate_xml_id(self, xml_id):
140         id = xml_id
141         if '.' in xml_id:
142             module, id = xml_id.split('.', 1)
143             assert '.' not in id, "The ID reference '%s' must contains maximum one dot.\n" \
144                                   "It is used to refer to other modules ID, in the form: module.record_id" \
145                                   % (xml_id,)
146             if module != self.module:
147                 module_count = self.pool.get('ir.module.module').search_count(self.cr, self.uid, \
148                         ['&', ('name', '=', module), ('state', 'in', ['installed'])])
149                 assert module_count == 1, 'The ID "%s" refers to an uninstalled module.' % (xml_id,)
150         if len(id) > 64: # TODO where does 64 come from (DB is 128)? should be a constant or loaded form DB
151             self.logger.log(logging.ERROR, 'id: %s is to long (max: 64)', id)
152
153     def get_id(self, xml_id):
154         if not xml_id:
155             raise YamlImportException("The xml_id should be a non empty string.")
156         if isinstance(xml_id, types.IntType):
157             id = xml_id
158         elif xml_id in self.id_map:
159             id = self.id_map[xml_id]
160         else:
161             if '.' in xml_id:
162                 module, checked_xml_id = xml_id.split('.', 1)
163             else:
164                 module = self.module
165                 checked_xml_id = xml_id
166             ir_id = self.pool.get('ir.model.data')._get_id(self.cr, self.uid, module, checked_xml_id)
167             obj = self.pool.get('ir.model.data').read(self.cr, self.uid, ir_id, ['res_id'])
168             id = int(obj['res_id'])
169             self.id_map[xml_id] = id
170         return id
171     
172     def get_context(self, node, eval_dict):
173         context = self.context.copy()
174         if node.context:
175             context.update(eval(node.context, eval_dict))
176         return context
177
178     def isnoupdate(self, node):
179         return self.noupdate or node.noupdate or False
180     
181     def process_comment(self, node):
182         return node
183
184     def _log_assert_failure(self, severity, msg, *args):
185         self.assert_report.record(False, severity)
186         self.logger.log(severity, msg, *args)
187         if severity >= config['assert_exit_level']:
188             raise YamlImportAbortion('Severe assertion failure (%s), aborting.' % logging.getLevelName(severity))
189         return
190
191     def _get_assertion_id(self, assertion):
192         if assertion.id:
193             ids = [self.get_id(assertion.id)]
194         elif assertion.search:
195             q = eval(assertion.search, self.eval_context)
196             ids = self.pool.get(assertion.model).search(self.cr, self.uid, q, context=assertion.context)
197         if not ids:
198             raise YamlImportException('Nothing to assert: you must give either an id or a search criteria.')
199         return ids
200
201     def process_assert(self, node):
202         assertion, expressions = node.items()[0]
203
204         if self.isnoupdate(assertion) and self.mode != 'init':
205             self.logger.warn('This assertion was not evaluated ("%s").' % assertion.string)
206             return
207         model = self.get_model(assertion.model)
208         ids = self._get_assertion_id(assertion)
209         if assertion.count and len(ids) != assertion.count:
210             msg = 'assertion "%s" failed!\n'   \
211                   ' Incorrect search count:\n' \
212                   ' expected count: %d\n'      \
213                   ' obtained count: %d\n'
214             args = (assertion.string, assertion.count, len(ids))
215             self._log_assert_failure(assertion.severity, msg, *args)
216         else:
217             context = self.get_context(assertion, self.eval_context)
218             for id in ids:
219                 record = model.browse(self.cr, self.uid, id, context)
220                 for test in expressions.get('test', ''):
221                     try:
222                         success = eval(test, self.eval_context, RecordDictWrapper(record))
223                     except Exception, e:
224                         raise YamlImportAbortion(e)
225                     if not success:
226                         msg = 'Assertion "%s" FAILED\ntest: %s\n'
227                         args = (assertion.string, test)
228                         self._log_assert_failure(assertion.severity, msg, *args)
229                         return
230             else: # all tests were successful for this assertion tag (no break)
231                 self.assert_report.record(True, assertion.severity)
232
233     def _coerce_bool(self, value, default=False):
234         if isinstance(value, types.BooleanType):
235             b = value
236         if isinstance(value, types.StringTypes):
237             b = value.strip().lower() not in ('0', 'false', 'off', 'no')
238         elif isinstance(value, types.IntType):
239             b = bool(value)
240         else:
241             b = default
242         return b 
243     
244     def process_record(self, node):
245         record, fields = node.items()[0]
246
247         self.validate_xml_id(record.id)
248         if self.isnoupdate(record) and self.mode != 'init':
249             id = self.pool.get('ir.model.data')._update_dummy(self.cr, self.uid, record.model, self.module, record.id)
250             # check if the resource already existed at the last update
251             if id:
252                 self.id_map[record] = int(id)
253                 return None
254             else:
255                 if not self._coerce_bool(record.forcecreate):
256                     return None
257
258         model = self.get_model(record.model)
259         record_dict = self._create_record(model, fields)
260         self.logger.debug("RECORD_DICT %s" % record_dict)
261         id = self.pool.get('ir.model.data')._update(self.cr, self.uid, record.model, \
262                 self.module, record_dict, record.id, noupdate=self.isnoupdate(record), mode=self.mode)
263         self.id_map[record.id] = int(id)
264         if config.get('import_partial', False):
265             self.cr.commit()
266     
267     def _create_record(self, model, fields):
268         record_dict = {}
269         for field_name, expression in fields.items():
270             field_value = self._eval_field(model, field_name, expression)
271             record_dict[field_name] = field_value
272         return record_dict        
273     
274     def _eval_field(self, model, field_name, expression):
275         column = model._columns[field_name]
276         if is_ref(expression):
277             if expression.model:
278                 other_model_name = expression.model
279             else:
280                 other_model_name = column._obj
281             other_model = self.get_model(other_model_name)
282             if expression.search:
283                 q = eval(expression.search, self.eval_context)
284                 ids = other_model.search(self.cr, self.uid, q)
285                 if expression.use:
286                     instances = other_model.browse(self.cr, self.uid, ids)
287                     elements = [inst[expression.use] for inst in instances]
288                 else:
289                     elements = ids
290                 if column._type in ("many2many", "one2many"):
291                     value = [(6, 0, elements)]
292                 else: # many2one
293                     value = elements[0]
294         elif column._type == "many2one":
295             value = self.get_id(expression)
296         elif column._type == "one2many":
297             other_model = self.get_model(column._obj)
298             value = [(0, 0, self._create_record(other_model, fields)) for fields in expression]
299         elif column._type == "many2many":
300             ids = [self.get_id(xml_id) for xml_id in expression]
301             value = [(6, 0, ids)]
302         else: # scalar field
303             if is_eval(expression):
304                 value = eval(expression.expression, self.eval_context)
305             else:
306                 value = expression
307             # raise YamlImportException('Unsupported column "%s" or value %s:%s' % (field_name, type(expression), expression))
308         return value
309     
310     def process_context(self, node):
311         self.context = node.__dict__
312         if node.uid:
313             self.uid = self.get_id(node.uid)
314         if node.noupdate:
315             self.noupdate = node.noupdate
316     
317     def process_python(self, node):
318         def log(msg, *args):
319             self.logger.log(logging.TEST, msg, *args)
320         python, statements = node.items()[0]
321         model = self.get_model(python.model)
322         statements = statements.replace("\r\n", "\n")
323         code_context = {'self': model, 'cr': self.cr, 'uid': self.uid, 'log': log, 'context': self.context}
324         try:
325             code = compile(statements, self.filename, 'exec')
326             eval(code, {'ref': self.get_id}, code_context)
327         except AssertionError, e:
328             self._log_assert_failure(python.severity, 'AssertionError in Python code %s: %s', python.name, e)
329             return
330         except Exception, e:
331             raise YamlImportAbortion(e)
332         else:
333             self.assert_report.record(True, python.severity)
334     
335     def process_workflow(self, node):
336         workflow, values = node.items()[0]
337         if self.isnoupdate(workflow) and self.mode != 'init':
338             return
339         model = self.get_model(workflow.model)
340         if workflow.ref:
341             id = self.get_id(workflow.ref)
342         else:
343             if not values:
344                 raise YamlImportException('You must define a child node if you do not give a ref.')
345             if not len(values) == 1:
346                 raise YamlImportException('Only one child node is accepted (%d given).' % len(values))
347             value = values[0]
348             if not 'model' in value and (not 'eval' in value or not 'search' in value):
349                 raise YamlImportException('You must provide a "model" and an "eval" or "search" to evaluate.')
350             value_model = self.get_model(value['model'])
351             local_context = {'obj': lambda x: value_model.browse(self.cr, self.uid, x, context=self.context)}
352             local_context.update(self.id_map)
353             id = eval(value['eval'], self.eval_context, local_context)
354         
355         if workflow.uid is not None:
356             uid = workflow.uid
357         else:
358             uid = self.uid
359         wf_service = netsvc.LocalService("workflow")
360         wf_service.trg_validate(uid, model, id, workflow.action, self.cr)
361         
362     def process_function(self, node):
363         function, values = node.items()[0]
364         if self.isnoupdate(function) and self.mode != 'init':
365             return
366         context = self.get_context(function, self.eval_context)
367         args = []
368         if function.eval:
369             args = eval(function.eval, self.eval_context)
370         for value in values:
371             if not 'model' in value and (not 'eval' in value or not 'search' in value):
372                 raise YamlImportException('You must provide a "model" and an "eval" or "search" to evaluate.')
373             value_model = self.get_model(value['model'])
374             local_context = {'obj': lambda x: value_model.browse(self.cr, self.uid, x, context=context)}
375             local_context.update(self.id_map)
376             id = eval(value['eval'], self.eval_context, local_context)
377             if id != None:
378                 args.append(id)
379         model = self.get_model(function.model)
380         method = function.name
381         getattr(model, method)(self.cr, self.uid, *args)
382     
383     def _set_group_values(self, node, values):
384         if node.groups:
385             group_names = node.groups.split(',')
386             groups_value = []
387             for group in group_names:
388                 if group.startswith('-'):
389                     group_id = self.get_id(group[1:])
390                     groups_value.append((3, group_id))
391                 else:
392                     group_id = self.get_id(group)
393                     groups_value.append((4, group_id))
394             values['groups_id'] = groups_value
395
396     def process_menuitem(self, node):
397         self.validate_xml_id(node.id)
398
399         if not node.parent:
400             parent_id = False
401             self.cr.execute('select id from ir_ui_menu where parent_id is null and name=%s', (node.name,))
402             res = self.cr.fetchone()
403             values = {'parent_id': parent_id, 'name': node.name}
404         else:
405             parent_id = self.get_id(node.parent)
406             values = {'parent_id': parent_id}
407             if node.name:
408                 values['name'] = node.name
409             try:
410                 res = [ self.get_id(node.id) ]
411             except: # which exception ?
412                 res = None
413
414         if node.action:
415             action_type = node.type or 'act_window'
416             icons = {
417                 "act_window": 'STOCK_NEW',
418                 "report.xml": 'STOCK_PASTE',
419                 "wizard": 'STOCK_EXECUTE',
420                 "url": 'STOCK_JUMP_TO',
421             }
422             values['icon'] = icons.get(action_type, 'STOCK_NEW')
423             if action_type == 'act_window':
424                 action_id = self.get_id(node.action)
425                 self.cr.execute('select view_type,view_mode,name,view_id,target from ir_act_window where id=%s', (action_id,))
426                 ir_act_window_result = self.cr.fetchone()
427                 assert ir_act_window_result, "No window action defined for this id %s !\n" \
428                         "Verify that this is a window action or add a type argument." % (node.action,)
429                 action_type, action_mode, action_name, view_id, target = ir_act_window_result
430                 if view_id:
431                     self.cr.execute('SELECT type FROM ir_ui_view WHERE id=%s', (view_id,))
432                     # TODO guess why action_mode is ir_act_window.view_mode above and ir_ui_view.type here
433                     action_mode = self.cr.fetchone()
434                 self.cr.execute('SELECT view_mode FROM ir_act_window_view WHERE act_window_id=%s ORDER BY sequence LIMIT 1', (action_id,))
435                 if self.cr.rowcount:
436                     action_mode = self.cr.fetchone()
437                 if action_type == 'tree':
438                     values['icon'] = 'STOCK_INDENT'
439                 elif action_mode and action_mode.startswith('tree'):
440                     values['icon'] = 'STOCK_JUSTIFY_FILL'
441                 elif action_mode and action_mode.startswith('graph'):
442                     values['icon'] = 'terp-graph'
443                 elif action_mode and action_mode.startswith('calendar'):
444                     values['icon'] = 'terp-calendar'
445                 if target == 'new':
446                     values['icon'] = 'STOCK_EXECUTE'
447                 if not values.get('name', False):
448                     values['name'] = action_name
449             elif action_type == 'wizard':
450                 action_id = self.get_id(node.action)
451                 self.cr.execute('select name from ir_act_wizard where id=%s', (action_id,))
452                 ir_act_wizard_result = self.cr.fetchone()
453                 if (not values.get('name', False)) and ir_act_wizard_result:
454                     values['name'] = ir_act_wizard_result[0]
455             else:
456                 raise YamlImportException("Unsupported type '%s' in menuitem tag." % action_type)
457         if node.sequence:
458             values['sequence'] = node.sequence
459         if node.icon:
460             values['icon'] = node.icon
461
462         self._set_group_values(node, values)
463         
464         pid = self.pool.get('ir.model.data')._update(self.cr, self.uid, \
465                 'ir.ui.menu', self.module, values, node.id, mode=self.mode, \
466                 noupdate=self.isnoupdate(node), res_id=res and res[0] or False)
467
468         if node.id and parent_id:
469             self.id_map[node.id] = int(parent_id)
470
471         if node.action and pid:
472             action_type = node.type or 'act_window'
473             action_id = self.get_id(node.action)
474             action = "ir.actions.%s,%d" % (action_type, action_id)
475             self.pool.get('ir.model.data').ir_set(self.cr, self.uid, 'action', \
476                     'tree_but_open', 'Menuitem', [('ir.ui.menu', int(parent_id))], action, True, True, xml_id=node.id)
477
478     def process_act_window(self, node):
479         self.validate_xml_id(node.id)
480         view_id = False
481         if node.view:
482             view_id = self.get_id(node.view)
483         context = eval(node.context, self.eval_context)
484
485         values = {
486             'name': node.name,
487             'type': type or 'ir.actions.act_window',
488             'view_id': view_id,
489             'domain': node.domain,
490             'context': context,
491             'res_model': node.res_model,
492             'src_model': node.src_model,
493             'view_type': node.view_type or 'form',
494             'view_mode': node.view_mode or 'tree,form',
495             'usage': node.usage,
496             'limit': node.limit,
497             'auto_refresh': node.auto_refresh,
498         }
499
500         self._set_group_values(node, values)
501
502         if node.target:
503             values['target'] = node.target
504         id = self.pool.get('ir.model.data')._update(self.cr, self.uid, \
505                 'ir.actions.act_window', self.module, values, node.id, mode=self.mode)
506         self.id_map[node.id] = int(id)
507
508         if node.src_model:
509             keyword = 'client_action_relate'
510             value = 'ir.actions.act_window,%s' % id
511             replace = node.replace or True
512             self.pool.get('ir.model.data').ir_set(self.cr, self.uid, 'action', keyword, \
513                     node.id, [node.src_model], value, replace=replace, noupdate=self.isnoupdate(node), isobject=True, xml_id=node.id)
514         # TODO add remove ir.model.data
515
516     def process_delete(self, node):
517         ids = []
518         if len(node.search):
519             ids = self.pool.get(node.model).search(self.cr, self.uid, eval(node.search, self.eval_context))
520         if len(node.id):
521             try:
522                 ids.append(self.get_id(node.id))
523             except:
524                 pass
525         if len(ids):
526             self.pool.get(node.model).unlink(self.cr, self.uid, ids)
527             self.pool.get('ir.model.data')._unlink(self.cr, self.uid, node.model, ids, direct=True)
528     
529     def process_url(self, node):
530         self.validate_xml_id(node.id)
531
532         res = {'name': node.name, 'url': node.url, 'target': node.target}
533
534         id = self.pool.get('ir.model.data')._update(self.cr, self.uid, \
535                 "ir.actions.url", self.module, res, node.id, mode=self.mode)
536         self.id_map[node.id] = int(id)
537         # ir_set
538         if (not node.menu or eval(node.menu)) and id:
539             keyword = node.keyword or 'client_action_multi'
540             value = 'ir.actions.url,%s' % id
541             replace = node.replace or True
542             self.pool.get('ir.model.data').ir_set(self.cr, self.uid, 'action', \
543                     keyword, node.url, ["ir.actions.url"], value, replace=replace, \
544                     noupdate=self.isnoupdate(node), isobject=True, xml_id=node.id)
545     
546     def process_ir_set(self, node):
547         if not self.mode == 'init':
548             return False
549         _, fields = node.items()[0]
550         res = {}
551         for fieldname, expression in fields.items():
552             if isinstance(expression, Eval):
553                 value = eval(expression.expression, self.eval_context)
554             else:
555                 value = expression
556             res[fieldname] = value
557         self.pool.get('ir.model.data').ir_set(self.cr, self.uid, res['key'], res['key2'], \
558                 res['name'], res['models'], res['value'], replace=res.get('replace',True), \
559                 isobject=res.get('isobject', False), meta=res.get('meta',None))
560
561     def process_report(self, node):
562         values = {}
563         for dest, f in (('name','string'), ('model','model'), ('report_name','name')):
564             values[dest] = getattr(node, f)
565             assert values[dest], "Attribute %s of report is empty !" % (f,)
566         for field,dest in (('rml','report_rml'),('xml','report_xml'),('xsl','report_xsl'),('attachment','attachment'),('attachment_use','attachment_use')):
567             if getattr(node, field):
568                 values[dest] = getattr(node, field)
569         if node.auto:
570             values['auto'] = eval(node.auto)
571         if node.sxw:
572             sxw_content = misc.file_open(node.sxw).read()
573             values['report_sxw_content'] = sxw_content
574         if node.header:
575             values['header'] = eval(node.header)
576         values['multi'] = node.multi and eval(node.multi)
577         xml_id = node.id
578         self.validate_xml_id(xml_id)
579
580         self._set_group_values(node, values)
581
582         id = self.pool.get('ir.model.data')._update(self.cr, self.uid, "ir.actions.report.xml", \
583                 self.module, values, xml_id, noupdate=self.isnoupdate(node), mode=self.mode)
584         self.id_map[xml_id] = int(id)
585
586         if not node.menu or eval(node.menu):
587             keyword = node.keyword or 'client_print_multi'
588             value = 'ir.actions.report.xml,%s' % id
589             replace = node.replace or True
590             self.pool.get('ir.model.data').ir_set(self.cr, self.uid, 'action', \
591                     keyword, values['name'], [values['model']], value, replace=replace, isobject=True, xml_id=xml_id)
592             
593     def process_none(self):
594         """
595         Empty node or commented node should not pass silently.
596         """
597         self._log_assert_failure(logging.WARNING, "You have an empty block in your tests.")
598         
599
600     def process(self, yaml_string):
601         """
602         Processes a Yaml string. Custom tags are interpreted by 'process_' instance methods.
603         """
604         is_preceded_by_comment = False
605         for node in yaml.load(yaml_string):
606             is_preceded_by_comment = self._log(node, is_preceded_by_comment)
607             try:
608                 self._process_node(node)
609             except YamlImportException, e:
610                 self.logger.log(logging.ERROR, e)
611             except Exception, e:
612                 self.logger.log(logging.ERROR, e)
613                 raise e
614     
615     def _process_node(self, node):
616         if is_comment(node):
617             self.process_comment(node)
618         elif is_assert(node):
619             self.process_assert(node)
620         elif is_record(node):
621             self.process_record(node)
622         elif is_python(node):
623             self.process_python(node)
624         elif is_menuitem(node):
625             self.process_menuitem(node)
626         elif is_delete(node):
627             self.process_delete(node)
628         elif is_url(node):
629             self.process_url(node)
630         elif is_context(node):
631             self.process_context(node)
632         elif is_ir_set(node):
633             self.process_ir_set(node)
634         elif is_act_window(node):
635             self.process_act_window(node)
636         elif is_report(node):
637             self.process_report(node)
638         elif is_workflow(node):
639             if isinstance(node, types.DictionaryType):
640                 self.process_workflow(node)
641             else:
642                 self.process_workflow({node: []})
643         elif is_function(node):
644             if isinstance(node, types.DictionaryType):
645                 self.process_function(node)
646             else:
647                 self.process_function({node: []})
648         elif node is None:
649             self.process_none()
650         else:
651             raise YamlImportException("Can not process YAML block: %s" % node)
652     
653     def _log(self, node, is_preceded_by_comment):
654         if is_comment(node):
655             is_preceded_by_comment = True
656             self.logger.log(logging.TEST, node)
657         elif not is_preceded_by_comment:
658             if isinstance(node, types.DictionaryType):
659                 msg = "Creating %s\n with %s"
660                 args = node.items()[0]
661                 self.logger.log(logging.TEST, msg, *args)
662             else:
663                 self.logger.log(logging.TEST, node)
664         else:
665             is_preceded_by_comment = False
666         return is_preceded_by_comment
667
668 def yaml_import(cr, module, yamlfile, idref=None, mode='init', noupdate=False, report=None):
669     if idref is None:
670         idref = {}
671     yaml_string = yamlfile.read()
672     yaml_interpreter = YamlInterpreter(cr, module, idref, mode, filename=yamlfile.name, noupdate=noupdate)
673     yaml_interpreter.process(yaml_string)
674
675 # keeps convention of convert.py
676 convert_yaml_import = yaml_import
677
678 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: