-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Module base_module_doc_rst migrated from version 6.1 #257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e63aa02
Module base_module_doc_rst migrated from version 6.1
sysadminmatmoz 7dfef5c
Remove deprecated module reference
sysadminmatmoz 5742769
Restore import from openerp.osv
sysadminmatmoz 3727908
Final clean
sysadminmatmoz 7ca087f
Correct version (typo)
sysadminmatmoz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| .. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg | ||
| :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
| :alt: License AGPL-3 | ||
|
|
||
| ================================================================================================= | ||
| This module generates the Technical Guides of selected modules in Restructured Text format (RST). | ||
| ================================================================================================= | ||
|
|
||
| Originally developed by OpenERP SA, migrated from the OpenERP version 6.1 to Odoo version 8.0 | ||
| by the Odoo Community Association. | ||
|
|
||
| * It uses the Sphinx (http://sphinx.pocoo.org) implementation of RST | ||
| * It creates a tarball (.tgz file suffix) containing an index file and one file per module | ||
| * Generates Relationship Graph | ||
|
|
||
| It performs its actions only on the modules that are actually installed in the same database | ||
| (being available in the module list is not enough). | ||
|
|
||
| Installation | ||
| ============ | ||
|
|
||
| * The module automatically takes care of its dependencies and is ready for use after the installation | ||
|
|
||
| TODO | ||
| ======= | ||
| * Hide "Relationship Graph" page if module not installed. | ||
| * Raise an exception when clicking on "Generate Relationship..." if the module is not installed. | ||
|
|
||
|
|
||
| Credits | ||
| ======= | ||
|
|
||
| Contributors | ||
| ------------ | ||
|
|
||
| * OpenERP SA <http://www.odoo.com> | ||
| * Matjaž Mozetič <m.mozetic@matmoz.si> | ||
|
|
||
| Bug Tracker | ||
| =========== | ||
|
|
||
| Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_. | ||
| In case of trouble, please check there if your issue has already been reported. | ||
| If you spotted it first, help us smashing it by providing a detailed and welcomed feedback | ||
| `here <https://github.com/OCA/server-tools/issues/new?body=module:%20base_module_doc_rst%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
|
||
| Maintainer | ||
| ---------- | ||
|
|
||
| .. image:: https://odoo-community.org/logo.png | ||
| :alt: Odoo Community Association | ||
| :target: https://odoo-community.org | ||
|
|
||
| This module is maintained by the OCA. | ||
|
|
||
| OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
| mission is to support the collaborative development of Odoo features and | ||
| promote its widespread use. | ||
|
|
||
| To contribute to this module, please visit http://odoo-community.org. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # © 2004-2009 Tiny SPRL <http://tiny.be> (original author) | ||
| # | ||
| # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
|
||
| from . import base_module_doc_rst | ||
| from . import wizard | ||
| from . import report |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # -*- coding: utf-8 -*- | ||
| ############################################################################## | ||
| # | ||
| # OpenERP, Open Source Management Solution | ||
| # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). | ||
| # | ||
| # This program is free software: you can redistribute it and/or modify | ||
| # it under the terms of the GNU Affero General Public License as | ||
| # published by the Free Software Foundation, either version 3 of the | ||
| # License, or (at your option) any later version. | ||
| # | ||
| # This program is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU Affero General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU Affero General Public License | ||
| # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| # | ||
| ############################################################################## | ||
|
|
||
| { | ||
| "name": "Generate Docs of Modules", | ||
| "version": "8.0.1.0.0", | ||
| "category": "Tools", | ||
| "summary": "Modules Technical Guides in RST and Relationship Graphs", | ||
| "website": "https://odoo-community.org/", | ||
| "author": "OpenERP SA,Odoo Community Association (OCA)", | ||
| "contributors": [ | ||
| "OpenERP SA <http://www.odoo.com>", | ||
| "Matjaž Mozetič <m.mozetic@matmoz.si>", | ||
| ], | ||
| "license": "AGPL-3", | ||
| "depends": ["base"], | ||
| "data": [ | ||
| "base_module_doc_rst_view.xml", | ||
| "wizard/generate_relation_graph_view.xml", | ||
| "wizard/tech_guide_rst_view.xml", | ||
| "module_report.xml", | ||
| ], | ||
| "demo": [], | ||
| "installable": True, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| # -*- coding: utf-8 -*- | ||
| ############################################################################## | ||
| # | ||
| # OpenERP, Open Source Management Solution | ||
| # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). | ||
| # | ||
| # This program is free software: you can redistribute it and/or modify | ||
| # it under the terms of the GNU Affero General Public License as | ||
| # published by the Free Software Foundation, either version 3 of the | ||
| # License, or (at your option) any later version. | ||
| # | ||
| # This program is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU Affero General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU Affero General Public License | ||
| # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| # | ||
| ############################################################################## | ||
| import os | ||
| import base64 | ||
| import openerp.modules.registry | ||
| from openerp import models, fields | ||
|
|
||
|
|
||
| class Module(models.Model): | ||
| _inherit = 'ir.module.module' | ||
| _description = 'Module With Relationship Graph' | ||
|
|
||
| file_graph = fields.Binary('Relationship Graph') | ||
|
|
||
| def _get_graphical_representation( | ||
| self, cr, uid, model_ids, level=1, context=None | ||
| ): | ||
| obj_model = self.pool.get('ir.model') | ||
| if level == 0: | ||
| return tuple() | ||
| relation = [] | ||
| for id in model_ids: | ||
| model_data = obj_model.browse(cr, uid, id, context=context) | ||
| for field in ( | ||
| f for f in model_data.field_id if f.ttype in ( | ||
| 'many2many', 'many2one', 'one2many' | ||
| ) | ||
| ): | ||
| relation.append( | ||
| ( | ||
| model_data.model, | ||
| field.name, | ||
| field.ttype, | ||
| field.relation, | ||
| field.field_description | ||
| ) | ||
| ) | ||
| new_model_ids = obj_model.search( | ||
| cr, | ||
| uid, | ||
| [('model', '=', field.relation)], | ||
| context=context | ||
| ) | ||
| if new_model_ids: | ||
| model = obj_model.read( | ||
| cr, | ||
| uid, | ||
| new_model_ids, | ||
| ['id', 'name'], | ||
| context=context | ||
| )[0] | ||
| relation.extend( | ||
| self._get_graphical_representation( | ||
| cr, uid, model['id'], level - 1 | ||
| ) | ||
| ) | ||
| return tuple(relation) | ||
|
|
||
| def _get_structure(self, relations, main_element): | ||
| res = {} | ||
| for rel in relations: | ||
| # if we have to display the string along with field name, | ||
| # then uncomment the first line n comment the second line | ||
| res.setdefault(rel[0], set()).add(rel[1]) | ||
| res.setdefault(rel[3], set()) | ||
| val = [] | ||
| for obj, fieldsx in res.items(): | ||
| val.append('"%s" [%s label="{<id>%s|%s}"];' % ( | ||
| obj, | ||
| obj in | ||
| main_element and | ||
| 'fillcolor=yellow, style="filled,rounded"' or | ||
| "", | ||
| obj, | ||
| "|".join(["<%s> %s" % (fn, fn) for fn in fieldsx]) | ||
| )) | ||
| return "\n".join(val) | ||
|
|
||
| def _get_arrow(self, field_type='many2one'): | ||
| return { | ||
| 'many2one': ( | ||
| 'arrowtail="none" arrowhead="normal" color="red" label="m2o"' | ||
| ), | ||
| 'many2many': ( | ||
| 'arrowtail="crow" arrowhead="crow" color="green" label="m2m"' | ||
| ), | ||
| 'one2many': ( | ||
| 'arrowtail="none" arrowhead="crow" color="blue" label="o2m"' | ||
| ), | ||
| }[field_type] | ||
|
|
||
| def get_graphical_representation(self, cr, uid, model_ids, context=None): | ||
| obj_model = self.pool.get('ir.model') | ||
| if context is None: | ||
| context = {} | ||
| res = {} | ||
| models = [] | ||
| for obj in obj_model.browse(cr, uid, model_ids, context=context): | ||
| models.append(obj.model) | ||
| relations = set( | ||
| self._get_graphical_representation( | ||
| cr, uid, model_ids, context.get('level', 1) | ||
| ) | ||
| ) | ||
| res[obj.model] = ( | ||
| "digraph G {\nnode [style=rounded, shape=record];\n%s\n%s }" % ( | ||
| self._get_structure(relations, models), | ||
| ''.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), | ||
| ) | ||
| ) | ||
| return res | ||
|
|
||
| def _get_module_objects(self, cr, uid, module, context=None): | ||
| obj_model = self.pool.get('ir.model') | ||
| obj_mod_data = self.pool.get('ir.model.data') | ||
| obj_ids = [] | ||
| model_data_ids = obj_mod_data.search( | ||
| cr, uid, | ||
| [('module', '=', module), ('model', '=', 'ir.model')], | ||
| context=context | ||
| ) | ||
| model_ids = [] | ||
| for mod in obj_mod_data.browse( | ||
| cr, uid, model_data_ids, context=context | ||
| ): | ||
| model_ids.append(mod.res_id) | ||
| models = obj_model.browse(cr, uid, model_ids, context=context) | ||
| map(lambda x: obj_ids.append(x.id), models) | ||
| return obj_ids | ||
|
|
||
| def get_relation_graph(self, cr, uid, module_name, context=None): | ||
| if context is None: | ||
| context = {} | ||
| object_ids = self._get_module_objects( | ||
| cr, uid, module_name, context=context | ||
| ) | ||
| if not object_ids: | ||
| return {'module_file': False} | ||
| # context.update({'level': 1}) | ||
| dots = self.get_graphical_representation( | ||
| cr, uid, object_ids, context=context | ||
| ) | ||
| # todo: use os.realpath | ||
| file_path = openerp.modules.module.get_module_path( | ||
| 'base_module_doc_rst' | ||
| ) | ||
| path_png = file_path + "/module.png" | ||
| for key, val in dots.items(): | ||
| path_dotfile = file_path + "/%s.dot" % (key,) | ||
| fp = file(path_dotfile, "w") | ||
| fp.write(val) | ||
| fp.close() | ||
| os.popen( | ||
| 'dot -Tpng' + ' ' + path_dotfile + ' ' + '-o' + ' ' + path_png | ||
| ) | ||
| fp = file(path_png, "r") | ||
| x = fp.read() | ||
| fp.close() | ||
| os.popen('rm ' + path_dotfile + ' ' + path_png) | ||
| return {'module_file': base64.encodestring(x)} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| <?xml version="1.0"?> | ||
| <openerp> | ||
| <data> | ||
|
|
||
| <!-- | ||
| Relationship Graph on Module object | ||
| --> | ||
|
|
||
| <record model="ir.ui.view" id="view_module_module_graph"> | ||
| <field name="name">ir.module.module.form.graph</field> | ||
| <field name="model">ir.module.module</field> | ||
| <field name="inherit_id" ref="base.module_form"/> | ||
| <field name="type">form</field> | ||
| <field name="arch" type="xml"> | ||
| <notebook position="inside"> | ||
| <page string="Relationship Graph"> | ||
| <separator colspan="4" string="You can save this image as .png file"/> | ||
| <field name="file_graph" widget="image" nolabel="1" /> | ||
| </page> | ||
| </notebook> | ||
| </field> | ||
| </record> | ||
|
|
||
| </data> | ||
| </openerp> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is a valid key here. Contributors belong in the README.rst where you already put them.