Merge lp:~openerp-groupes/openobject-addons/base_module_doc_rst_improvements into lp:openobject-addons

Proposed by Olivier Ligot
Status: Superseded
Proposed branch: lp:~openerp-groupes/openobject-addons/base_module_doc_rst_improvements
Merge into: lp:openobject-addons
Diff against target: 162 lines (+46/-21)
4 files modified
base_module_doc_rst/base_module_doc_rst.py (+39/-18)
base_module_doc_rst/base_module_doc_rst_view.xml (+4/-0)
base_module_doc_rst/report/report_proximity_graph.py (+1/-1)
base_module_doc_rst/wizard/generate_relation_graph.py (+2/-2)
To merge this branch: bzr merge lp:~openerp-groupes/openobject-addons/base_module_doc_rst_improvements
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+37568@code.launchpad.net

This proposal has been superseded by a proposal from 2011-10-05.

Description of the change

This branch improves the module base_module_doc_rst by adding 3 news fields on ir.module.module:
- level: number of times a model is processed when it is in relation with another model
- filter_model_ids: filter the models taken into account to generate the relationship graph
- dot_graph: save the generated graph as a DOT file

To post a comment you must log in.
Revision history for this message
Fabien (Open ERP) (fp-tinyerp) wrote :

seems good

Revision history for this message
Julien Thewys (julien-thewys) wrote :

Looks like this has actually never been merged.
Could you make it so?

Unmerged revisions

4152. By Olivier Ligot

[ADD] dot_graph field on ir.module.module object

This new field allows to save the generated graph as a DOT file

4151. By Olivier Ligot

[FIX] same variable name (id)

4150. By Olivier Ligot

[ADD] filter_model_ids field on ir.module.module object

This new field allows to filter the models taken into account to generate the relationship graph

4149. By Olivier Ligot

[ADD] level field on ir.module.module object

This new field allows to specify the number of times a model is processed when it is in relation with another model.

4148. By Olivier Ligot

[REM] Useless code

4147. By Olivier Ligot

[FIX] DOT file label

4146. By Xavier (Open ERP)

[FIX] account_voucher: fix sales_reicept tests to assert on the status of 'reconciled' rather than print random stuff to stdout

4145. By Launchpad Translations on behalf of openerp

Launchpad automatic translations update.

4144. By Borja (Pexego)

[FIX] Merged Borja's branch for correction on Invoice correctd workflow action of sale order

4143. By Harry (OpenERP)

[FIX] stock_planning, hr_attendance: resolve regression after rev:4139

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'base_module_doc_rst/base_module_doc_rst.py'
--- base_module_doc_rst/base_module_doc_rst.py 2010-08-19 11:51:57 +0000
+++ base_module_doc_rst/base_module_doc_rst.py 2010-10-05 07:51:48 +0000
@@ -32,21 +32,32 @@
32 _description = 'Module With Relationship Graph'32 _description = 'Module With Relationship Graph'
33 _columns = {33 _columns = {
34 'file_graph': fields.binary('Relationship Graph'),34 'file_graph': fields.binary('Relationship Graph'),
35 'level': fields.integer('Level', help="""Number of times a model is processed
36when it is in relation with another model."""),
37 'filter_model_ids': fields.many2many('ir.model', 'module_filter_model_rel', 'module_id', 'model_id', 'Filter models'),
38 'dot_graph': fields.binary('Graph (DOT file)'),
35 }39 }
3640
37 def _get_graphical_representation(self, cr, uid, model_ids, level=1, context={}):41 _defaults = {
42 'level': 1
43 }
44
45 def _get_graphical_representation(self, cr, uid, module_id, model_ids, level=1, context={}):
38 obj_model = self.pool.get('ir.model')46 obj_model = self.pool.get('ir.model')
39 if level == 0:47 if level == 0:
40 return tuple()48 return tuple()
41 relation = []49 relation = []
50 module = self.browse(cr, uid, module_id, context=context)
51 filter_models = [model.model for model in module.filter_model_ids]
42 for id in model_ids:52 for id in model_ids:
43 model_data = obj_model.browse(cr, uid, id, context=context)53 model_data = obj_model.browse(cr, uid, id, context=context)
44 for field in (f for f in model_data.field_id if f.ttype in ('many2many', 'many2one', 'one2many')):54 for field in (f for f in model_data.field_id if f.ttype in ('many2many', 'many2one', 'one2many')):
45 relation.append((model_data.model, field.name, field.ttype, field.relation, field.field_description))55 if not filter_models or field.relation in filter_models:
46 new_model_ids = obj_model.search(cr, uid, [('model', '=', field.relation)], context=context)56 relation.append((model_data.model, field.name, field.ttype, field.relation, field.field_description))
47 if new_model_ids:57 new_model_ids = obj_model.search(cr, uid, [('model', '=', field.relation)], context=context)
48 model = obj_model.read(cr, uid, new_model_ids, ['id', 'name'], context=context)[0]58 if new_model_ids:
49 relation.extend(self._get_graphical_representation(cr, uid, model['id'], level - 1))59 model = obj_model.read(cr, uid, new_model_ids, ['id', 'name'], context=context)[0]
60 relation.extend(self._get_graphical_representation(cr, uid, module_id, [model['id']], level - 1))
50 return tuple(relation)61 return tuple(relation)
5162
52 def _get_structure(self, relations, main_element):63 def _get_structure(self, relations, main_element):
@@ -70,7 +81,7 @@
70 'one2many': 'arrowtail="none" arrowhead="crow" color="blue" label="o2m"',81 'one2many': 'arrowtail="none" arrowhead="crow" color="blue" label="o2m"',
71 }[field_type]82 }[field_type]
7283
73 def get_graphical_representation(self, cr, uid, model_ids, context=None):84 def get_graphical_representation(self, cr, uid, id, model_ids, context=None):
74 obj_model = self.pool.get('ir.model')85 obj_model = self.pool.get('ir.model')
75 if context is None:86 if context is None:
76 context = {}87 context = {}
@@ -78,7 +89,7 @@
78 models = []89 models = []
79 for obj in obj_model.browse(cr, uid, model_ids, context=context):90 for obj in obj_model.browse(cr, uid, model_ids, context=context):
80 models.append(obj.model)91 models.append(obj.model)
81 relations = set(self._get_graphical_representation(cr, uid, model_ids, context.get('level', 1)))92 relations = set(self._get_graphical_representation(cr, uid, id, model_ids, context.get('level', 1)))
82 res[obj.model] = "digraph G {\nnode [style=rounded, shape=record];\n%s\n%s }" % (93 res[obj.model] = "digraph G {\nnode [style=rounded, shape=record];\n%s\n%s }" % (
83 self._get_structure(relations, models),94 self._get_structure(relations, models),
84 ''.join('"%s":%s -> "%s":id:n [%s]; // %s\n' % (m, fn, fr, self._get_arrow(ft),ft) for m, fn, ft, fr, fl in relations),95 ''.join('"%s":%s -> "%s":id:n [%s]; // %s\n' % (m, fn, fr, self._get_arrow(ft),ft) for m, fn, ft, fr, fl in relations),
@@ -86,23 +97,28 @@
86 return res97 return res
8798
88 def _get_module_objects(self, cr, uid, module, context={}):99 def _get_module_objects(self, cr, uid, module, context={}):
89 obj_model = self.pool.get('ir.model')
90 obj_mod_data = self.pool.get('ir.model.data')100 obj_mod_data = self.pool.get('ir.model.data')
91 obj_ids = []
92 model_data_ids = obj_mod_data.search(cr, uid, [('module', '=', module), ('model', '=', 'ir.model')], context=context)101 model_data_ids = obj_mod_data.search(cr, uid, [('module', '=', module), ('model', '=', 'ir.model')], context=context)
93 model_ids = []102 model_ids = []
103 module_id = self.search(cr, uid, [('name', '=', module)])[0]
104 module = self.browse(cr, uid, module_id, context=context)
105 filter_model_ids = [model.id for model in module.filter_model_ids]
94 for mod in obj_mod_data.browse(cr, uid, model_data_ids, context=context):106 for mod in obj_mod_data.browse(cr, uid, model_data_ids, context=context):
95 model_ids.append(mod.res_id)107 if not filter_model_ids or mod.res_id in filter_model_ids:
96 models = obj_model.browse(cr, uid, model_ids, context=context)108 model_ids.append(mod.res_id)
97 map(lambda x: obj_ids.append(x.id),models)109 return model_ids
98 return obj_ids
99110
100 def get_relation_graph(self, cr, uid, module_name, context=None):111 def get_relation_graph(self, cr, uid, module_name, context=None):
112 if context is None:
113 context = {}
114 result = {}
101 object_ids = self._get_module_objects(cr, uid, module_name, context=context)115 object_ids = self._get_module_objects(cr, uid, module_name, context=context)
102 if not object_ids:116 if not object_ids:
103 return {'module_file': False}117 return False
104 context.update({'level': 1})118 module_id = self.search(cr, uid, [('name', '=', module_name)])[0]
105 dots = self.get_graphical_representation(cr, uid, object_ids, context=context)119 module = self.browse(cr, uid, module_id)
120 context.update({'level': module.level})
121 dots = self.get_graphical_representation(cr, uid, module_id, object_ids, context=context)
106 # todo: use os.realpath122 # todo: use os.realpath
107 file_path = tools.config['addons_path']+"/base_module_doc_rst/"123 file_path = tools.config['addons_path']+"/base_module_doc_rst/"
108 path_png = file_path + "/module.png"124 path_png = file_path + "/module.png"
@@ -111,12 +127,17 @@
111 fp = file(path_dotfile, "w")127 fp = file(path_dotfile, "w")
112 fp.write(val)128 fp.write(val)
113 fp.close()129 fp.close()
130 fp = file(path_dotfile, "r")
131 x = fp.read()
132 fp.close()
133 result['dot_graph'] = base64.encodestring(x)
114 os.popen('dot -Tpng' +' '+ path_dotfile + ' '+ '-o' +' ' + path_png)134 os.popen('dot -Tpng' +' '+ path_dotfile + ' '+ '-o' +' ' + path_png)
115 fp = file(path_png, "r")135 fp = file(path_png, "r")
116 x = fp.read()136 x = fp.read()
117 fp.close()137 fp.close()
118 os.popen('rm ' + path_dotfile + ' ' + path_png)138 os.popen('rm ' + path_dotfile + ' ' + path_png)
119 return {'module_file': base64.encodestring(x)}139 result['file_graph'] = base64.encodestring(x)
140 return result
120141
121module()142module()
122143
123144
=== modified file 'base_module_doc_rst/base_module_doc_rst_view.xml'
--- base_module_doc_rst/base_module_doc_rst_view.xml 2010-05-19 15:57:31 +0000
+++ base_module_doc_rst/base_module_doc_rst_view.xml 2010-10-05 07:51:48 +0000
@@ -14,8 +14,12 @@
14 <field name="arch" type="xml">14 <field name="arch" type="xml">
15 <notebook position="inside">15 <notebook position="inside">
16 <page string="Relationship Graph">16 <page string="Relationship Graph">
17 <separator colspan="4" string="You can filter the models taken into account to generate the graph"/>
18 <field name="filter_model_ids" colspan="4" nolabel="1"/>
19 <field name="level"/>
17 <separator colspan="4" string="You can save this image as .png file"/>20 <separator colspan="4" string="You can save this image as .png file"/>
18 <field name="file_graph" widget="image" nolabel="1" />21 <field name="file_graph" widget="image" nolabel="1" />
22 <field name="dot_graph"/>
19 </page>23 </page>
20 </notebook>24 </notebook>
21 </field>25 </field>
2226
=== modified file 'base_module_doc_rst/report/report_proximity_graph.py'
--- base_module_doc_rst/report/report_proximity_graph.py 2010-08-19 11:51:57 +0000
+++ base_module_doc_rst/report/report_proximity_graph.py 2010-10-05 07:51:48 +0000
@@ -48,7 +48,7 @@
48 if id:48 if id:
49 get_dpend_module(id[0].id)49 get_dpend_module(id[0].id)
50 get_dpend_module(module_id)50 get_dpend_module(module_id)
51 graph = pydot.Dot(graph_type='digraph',fontsize='10', label="\\nProximity Graph. \\n\\nGray Color:Official Modules, Red Color:Extra Addons Modules, Blue Color:Community Modules, Purple Color:Unknow Modules"51 graph = pydot.Dot(graph_type='digraph',fontsize='10', label='"\\nProximity Graph. \\n\\nGray Color:Official Modules, Red Color:Extra Addons Modules, Blue Color:Community Modules, Purple Color:Unknow Modules"'
52 , center='1')52 , center='1')
53 for node in nodes:53 for node in nodes:
54 if node[1] == "official":54 if node[1] == "official":
5555
=== modified file 'base_module_doc_rst/wizard/generate_relation_graph.py'
--- base_module_doc_rst/wizard/generate_relation_graph.py 2010-05-19 15:57:31 +0000
+++ base_module_doc_rst/wizard/generate_relation_graph.py 2010-10-05 07:51:48 +0000
@@ -33,8 +33,8 @@
33 modules = mod_obj.browse(cr, uid, datas['ids'], context=context)33 modules = mod_obj.browse(cr, uid, datas['ids'], context=context)
34 for module in modules:34 for module in modules:
35 module_data = mod_obj.get_relation_graph(cr, uid, module.name, context=context)35 module_data = mod_obj.get_relation_graph(cr, uid, module.name, context=context)
36 if module_data['module_file']:36 if module_data:
37 mod_obj.write(cr, uid, [module.id], {'file_graph': module_data['module_file']}, context=context)37 mod_obj.write(cr, uid, [module.id], module_data, context=context)
38 return {}38 return {}
3939
40class create_graph(wizard.interface):40class create_graph(wizard.interface):

Subscribers

People subscribed via source and target branches

to all changes: