Browse Source

Module base_module_doc_rst migrated from version 6.1

pull/257/head
Matjaž Mozetič 9 years ago
parent
commit
e63aa02ac4
  1. 60
      base_module_doc_rst/README.rst
  2. 8
      base_module_doc_rst/__init__.py
  3. 43
      base_module_doc_rst/__openerp__.py
  4. 180
      base_module_doc_rst/base_module_doc_rst.py
  5. 25
      base_module_doc_rst/base_module_doc_rst_view.xml
  6. 114
      base_module_doc_rst/i18n/base_module_doc_rst.pot
  7. 125
      base_module_doc_rst/i18n/it.po
  8. 119
      base_module_doc_rst/i18n/sl.po
  9. 9
      base_module_doc_rst/module_report.xml
  10. 23
      base_module_doc_rst/report/__init__.py
  11. 270
      base_module_doc_rst/report/ir_module_reference_graph.rml
  12. BIN
      base_module_doc_rst/report/ir_module_reference_graph.sxw
  13. 94
      base_module_doc_rst/report/ir_module_reference_print_graph.py
  14. 118
      base_module_doc_rst/report/report_proximity_graph.py
  15. 23
      base_module_doc_rst/wizard/__init__.py
  16. 45
      base_module_doc_rst/wizard/generate_relation_graph.py
  17. 28
      base_module_doc_rst/wizard/generate_relation_graph_view.xml
  18. 28
      base_module_doc_rst/wizard/tech_guide_rst_view.xml
  19. 523
      base_module_doc_rst/wizard/tech_rst_guide.py

60
base_module_doc_rst/README.rst

@ -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.

8
base_module_doc_rst/__init__.py

@ -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

43
base_module_doc_rst/__openerp__.py

@ -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": "1.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,
}

180
base_module_doc_rst/base_module_doc_rst.py

@ -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)}

25
base_module_doc_rst/base_module_doc_rst_view.xml

@ -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>

114
base_module_doc_rst/i18n/base_module_doc_rst.pot

@ -0,0 +1,114 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * base_module_doc_rst
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-09-17 11:49+0000\n"
"PO-Revision-Date: 2015-09-17 11:49+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: base_module_doc_rst
#: view:create.relation.graph:base_module_doc_rst.view_relationship_graph
msgid "Cancel"
msgstr ""
#. module: base_module_doc_rst
#: view:create.relation.graph:base_module_doc_rst.view_relationship_graph
msgid "Create Graphs"
msgstr ""
#. module: base_module_doc_rst
#: model:ir.actions.act_window,name:base_module_doc_rst.wiz_tech_guide_rst
msgid "Create RST Technical Guide2"
msgstr ""
#. module: base_module_doc_rst
#: view:tech.guide.rst:base_module_doc_rst.view_technical_guide
msgid "Create Technical Guide in rst format"
msgstr ""
#. module: base_module_doc_rst
#: field:create.relation.graph,create_uid:0
#: field:tech.guide.rst,create_uid:0
msgid "Created by"
msgstr ""
#. module: base_module_doc_rst
#: field:create.relation.graph,create_date:0
#: field:tech.guide.rst,create_date:0
msgid "Created on"
msgstr ""
#. module: base_module_doc_rst
#: field:tech.guide.rst,rst_file:0
msgid "File"
msgstr ""
#. module: base_module_doc_rst
#: view:create.relation.graph:base_module_doc_rst.view_relationship_graph
#: model:ir.actions.act_window,name:base_module_doc_rst.generate_relationship_graph_values
msgid "Generate Relationship Graph"
msgstr ""
#. module: base_module_doc_rst
#: field:create.relation.graph,id:0
#: field:tech.guide.rst,id:0
msgid "ID"
msgstr ""
#. module: base_module_doc_rst
#: field:create.relation.graph,write_uid:0
#: field:tech.guide.rst,write_uid:0
msgid "Last Updated by"
msgstr ""
#. module: base_module_doc_rst
#: field:create.relation.graph,write_date:0
#: field:tech.guide.rst,write_date:0
msgid "Last Updated on"
msgstr ""
#. module: base_module_doc_rst
#: model:ir.model,name:base_module_doc_rst.model_ir_module_module
msgid "Module"
msgstr ""
#. module: base_module_doc_rst
#: view:tech.guide.rst:base_module_doc_rst.view_technical_guide
msgid "Please choose a file where the Technical Guide will be written."
msgstr ""
#. module: base_module_doc_rst
#: model:ir.actions.report.xml,name:base_module_doc_rst.report_proximity_graph
msgid "Proximity graph"
msgstr ""
#. module: base_module_doc_rst
#: view:ir.module.module:base_module_doc_rst.view_module_module_graph
#: field:ir.module.module,file_graph:0
msgid "Relationship Graph"
msgstr ""
#. module: base_module_doc_rst
#: view:create.relation.graph:base_module_doc_rst.view_relationship_graph
msgid "Relationship Graphs"
msgstr ""
#. module: base_module_doc_rst
#: view:tech.guide.rst:base_module_doc_rst.view_technical_guide
msgid "Technical Guide in rst format"
msgstr ""
#. module: base_module_doc_rst
#: view:ir.module.module:base_module_doc_rst.view_module_module_graph
msgid "You can save this image as .png file"
msgstr ""

125
base_module_doc_rst/i18n/it.po

@ -0,0 +1,125 @@
# Translation of OpenERP Server.
# This file contains the translation of the following modules:
# * base_module_doc_rst
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 6.0dev\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-09-17 13:51+0200\n"
"PO-Revision-Date: 2015-09-17 13:52+0200\n"
"Last-Translator: Matjaz Mozetic <m.mozetic@matmoz.si>\n"
"Language-Team: \n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Launchpad-Export-Date: 2013-05-29 06:51+0000\n"
"X-Generator: Poedit 1.8.4\n"
#. module: base_module_doc_rst
#: view:create.relation.graph:base_module_doc_rst.view_relationship_graph
msgid "Cancel"
msgstr "Cancella"
#. module: base_module_doc_rst
#: view:create.relation.graph:base_module_doc_rst.view_relationship_graph
msgid "Create Graphs"
msgstr "Creazione dei grafici"
#. module: base_module_doc_rst
#: model:ir.actions.act_window,name:base_module_doc_rst.wiz_tech_guide_rst
msgid "Create RST Technical Guide2"
msgstr "Creazione della Guida Tecnica in 'rst'"
#. module: base_module_doc_rst
#: view:tech.guide.rst:base_module_doc_rst.view_technical_guide
msgid "Create Technical Guide in rst format"
msgstr "Creazione della Guida Tecnica nel formato 'rst'"
#. module: base_module_doc_rst
#: field:create.relation.graph,create_uid:0 field:tech.guide.rst,create_uid:0
msgid "Created by"
msgstr "Creato da"
#. module: base_module_doc_rst
#: field:create.relation.graph,create_date:0 field:tech.guide.rst,create_date:0
msgid "Created on"
msgstr "Creato il"
#. module: base_module_doc_rst
#: field:tech.guide.rst,rst_file:0
msgid "File"
msgstr "File"
#. module: base_module_doc_rst
#: view:create.relation.graph:base_module_doc_rst.view_relationship_graph
#: model:ir.actions.act_window,name:base_module_doc_rst.generate_relationship_graph_values
msgid "Generate Relationship Graph"
msgstr "Genera grafici relazioni"
#. module: base_module_doc_rst
#: field:create.relation.graph,id:0 field:tech.guide.rst,id:0
msgid "ID"
msgstr "ID"
#. module: base_module_doc_rst
#: field:create.relation.graph,write_uid:0 field:tech.guide.rst,write_uid:0
msgid "Last Updated by"
msgstr "Ultimo aggiornamento da"
#. module: base_module_doc_rst
#: field:create.relation.graph,write_date:0 field:tech.guide.rst,write_date:0
msgid "Last Updated on"
msgstr "Ultimo aggiornamento il"
#. module: base_module_doc_rst
#: model:ir.model,name:base_module_doc_rst.model_ir_module_module
msgid "Module"
msgstr "Modulo"
#. module: base_module_doc_rst
#: view:tech.guide.rst:base_module_doc_rst.view_technical_guide
msgid "Please choose a file where the Technical Guide will be written."
msgstr "Selezionare un file dove la Guida Tecnica potrebbe essere scritta."
#. module: base_module_doc_rst
#: model:ir.actions.report.xml,name:base_module_doc_rst.report_proximity_graph
msgid "Proximity graph"
msgstr "Grafico prossimità"
#. module: base_module_doc_rst
#: view:ir.module.module:base_module_doc_rst.view_module_module_graph
#: field:ir.module.module,file_graph:0
msgid "Relationship Graph"
msgstr "Grafico relazioni"
#. module: base_module_doc_rst
#: view:create.relation.graph:base_module_doc_rst.view_relationship_graph
msgid "Relationship Graphs"
msgstr "Grafico relazioni"
#. module: base_module_doc_rst
#: view:tech.guide.rst:base_module_doc_rst.view_technical_guide
msgid "Technical Guide in rst format"
msgstr "Guida tecnica nel formato 'rst'"
#. module: base_module_doc_rst
#: view:ir.module.module:base_module_doc_rst.view_module_module_graph
msgid "You can save this image as .png file"
msgstr "E' possibile salvare questa immagine come file .PNG"
#~ msgid "Ok"
#~ msgstr "Ok"
#~ msgid "(Relationship Graphs generated)"
#~ msgstr "(Grafici relazioni generati)"
#~ msgid "filename"
#~ msgstr "nome file"
#~ msgid "file"
#~ msgstr "file"
#~ msgid "Close"
#~ msgstr "Chiudi"

119
base_module_doc_rst/i18n/sl.po

@ -0,0 +1,119 @@
# Translation of OpenERP Server.
# This file contains the translation of the following modules:
# * base_module_doc_rst
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 6.0dev\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-09-17 13:50+0200\n"
"PO-Revision-Date: 2015-09-17 13:51+0200\n"
"Last-Translator: Matjaz Mozetic <m.mozetic@matmoz.si>\n"
"Language-Team: \n"
"Language: sl\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Launchpad-Export-Date: 2013-05-29 06:51+0000\n"
"X-Generator: Poedit 1.8.4\n"
#. module: base_module_doc_rst
#: view:create.relation.graph:base_module_doc_rst.view_relationship_graph
msgid "Cancel"
msgstr "Preklic"
#. module: base_module_doc_rst
#: view:create.relation.graph:base_module_doc_rst.view_relationship_graph
msgid "Create Graphs"
msgstr "Ustvari grafe"
#. module: base_module_doc_rst
#: model:ir.actions.act_window,name:base_module_doc_rst.wiz_tech_guide_rst
msgid "Create RST Technical Guide2"
msgstr "Izdelaj RST tehnična navodila"
#. module: base_module_doc_rst
#: view:tech.guide.rst:base_module_doc_rst.view_technical_guide
msgid "Create Technical Guide in rst format"
msgstr "Izdelaj tehnična navodila v formatu rst"
#. module: base_module_doc_rst
#: field:create.relation.graph,create_uid:0 field:tech.guide.rst,create_uid:0
msgid "Created by"
msgstr "Ustvaril"
#. module: base_module_doc_rst
#: field:create.relation.graph,create_date:0 field:tech.guide.rst,create_date:0
msgid "Created on"
msgstr "Ustvarjeno"
#. module: base_module_doc_rst
#: field:tech.guide.rst,rst_file:0
msgid "File"
msgstr "Datoteka"
#. module: base_module_doc_rst
#: view:create.relation.graph:base_module_doc_rst.view_relationship_graph
#: model:ir.actions.act_window,name:base_module_doc_rst.generate_relationship_graph_values
msgid "Generate Relationship Graph"
msgstr "Ustvari relacijski diagram"
#. module: base_module_doc_rst
#: field:create.relation.graph,id:0 field:tech.guide.rst,id:0
msgid "ID"
msgstr "ID"
#. module: base_module_doc_rst
#: field:create.relation.graph,write_uid:0 field:tech.guide.rst,write_uid:0
msgid "Last Updated by"
msgstr "Zadnjič posodobil"
#. module: base_module_doc_rst
#: field:create.relation.graph,write_date:0 field:tech.guide.rst,write_date:0
msgid "Last Updated on"
msgstr "Zadnjič posodobljeno"
#. module: base_module_doc_rst
#: model:ir.model,name:base_module_doc_rst.model_ir_module_module
msgid "Module"
msgstr "Modul"
#. module: base_module_doc_rst
#: view:tech.guide.rst:base_module_doc_rst.view_technical_guide
msgid "Please choose a file where the Technical Guide will be written."
msgstr "Prosimo, izberite datoteko, v katero se bodo zapisala tehnična navodila"
#. module: base_module_doc_rst
#: model:ir.actions.report.xml,name:base_module_doc_rst.report_proximity_graph
msgid "Proximity graph"
msgstr "Graf bližine"
#. module: base_module_doc_rst
#: view:ir.module.module:base_module_doc_rst.view_module_module_graph
#: field:ir.module.module,file_graph:0
msgid "Relationship Graph"
msgstr "Relacijski diagram"
#. module: base_module_doc_rst
#: view:create.relation.graph:base_module_doc_rst.view_relationship_graph
msgid "Relationship Graphs"
msgstr "Relacijski diagrami"
#. module: base_module_doc_rst
#: view:tech.guide.rst:base_module_doc_rst.view_technical_guide
msgid "Technical Guide in rst format"
msgstr "Tehnična navodila v rst formatu"
#. module: base_module_doc_rst
#: view:ir.module.module:base_module_doc_rst.view_module_module_graph
msgid "You can save this image as .png file"
msgstr "To sliko lahko shranite kot .png datoteko."
#~ msgid "filename"
#~ msgstr "ime datoteke"
#~ msgid "file"
#~ msgstr "datoteka"
#~ msgid "Close"
#~ msgstr "Zapri"

9
base_module_doc_rst/module_report.xml

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<report auto="False" id="base.ir_module_reference_print" model="ir.module.module" name="ir.module.reference.graph" rml="base_module_doc_rst/report/ir_module_reference_graph.rml" string="Technical guide"/>
<report id="report_proximity_graph" model="ir.module.module" name="proximity.graph" string="Proximity graph"/>
</data>
</openerp>

23
base_module_doc_rst/report/__init__.py

@ -0,0 +1,23 @@
# -*- 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/>.
#
##############################################################################
from . import ir_module_reference_print_graph
from . import report_proximity_graph

270
base_module_doc_rst/report/ir_module_reference_graph.rml

@ -0,0 +1,270 @@
<?xml version="1.0"?>
<document filename="test.pdf">
<template title="Introspection report on objects" author="OpenERP S.A. (sales@openerp.com)" allowSplitting="20">
<pageTemplate id="first">
<frame id="first" x1="42.0" y1="42.0" width="511" height="758"/>
<header>
<pageGraphics>
<setFont name="Helvetica-Bold" size="9"/>
<drawString x="1.0cm" y="28.1cm">[[ company.name ]]</drawString>
<drawRightString x="20cm" y="28.1cm"> Reference Guide </drawRightString>
<lineMode width="0.7"/>
<stroke color="black"/>
<lines>1cm 28cm 20cm 28cm</lines>
</pageGraphics>
</header>
</pageTemplate>
</template>
<stylesheet>
<blockTableStyle id="Standard_Outline">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
</blockTableStyle>
<blockTableStyle id="Table1">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
</blockTableStyle>
<blockTableStyle id="module_tbl_heading">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
<lineStyle kind="LINEBEFORE" colorName="#e6e6e6" start="0,0" stop="0,-1"/>
<lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="0,0" stop="0,0"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,-1" stop="0,-1"/>
<lineStyle kind="LINEBEFORE" colorName="#e6e6e6" start="1,0" stop="1,-1"/>
<lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="1,0" stop="1,0"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="1,-1" stop="1,-1"/>
<lineStyle kind="LINEBEFORE" colorName="#e6e6e6" start="2,0" stop="2,-1"/>
<lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="2,0" stop="2,0"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="2,-1" stop="2,-1"/>
<lineStyle kind="LINEBEFORE" colorName="#e6e6e6" start="3,0" stop="3,-1"/>
<lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="3,0" stop="3,0"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="3,-1" stop="3,-1"/>
<lineStyle kind="LINEBEFORE" colorName="#e6e6e6" start="4,0" stop="4,-1"/>
<lineStyle kind="LINEAFTER" colorName="#e6e6e6" start="4,0" stop="4,-1"/>
<lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="4,0" stop="4,0"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="4,-1" stop="4,-1"/>
</blockTableStyle>
<blockTableStyle id="module_tbl_content">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
<lineStyle kind="LINEBEFORE" colorName="#e6e6e6" start="0,0" stop="0,-1"/>
<lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="0,0" stop="0,0"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,-1" stop="0,-1"/>
<lineStyle kind="LINEBEFORE" colorName="#e6e6e6" start="1,0" stop="1,-1"/>
<lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="1,0" stop="1,0"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="1,-1" stop="1,-1"/>
<lineStyle kind="LINEBEFORE" colorName="#e6e6e6" start="2,0" stop="2,-1"/>
<lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="2,0" stop="2,0"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="2,-1" stop="2,-1"/>
<lineStyle kind="LINEBEFORE" colorName="#e6e6e6" start="3,0" stop="3,-1"/>
<lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="3,0" stop="3,0"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="3,-1" stop="3,-1"/>
<lineStyle kind="LINEBEFORE" colorName="#e6e6e6" start="4,0" stop="4,-1"/>
<lineStyle kind="LINEAFTER" colorName="#e6e6e6" start="4,0" stop="4,-1"/>
<lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="4,0" stop="4,0"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="4,-1" stop="4,-1"/>
</blockTableStyle>
<blockTableStyle id="depen_tbl">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
</blockTableStyle>
<blockTableStyle id="Tableau3">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
<lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="0,-1"/>
</blockTableStyle>
<blockTableStyle id="Table2">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,-1" stop="0,-1"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="1,-1" stop="1,-1"/>
</blockTableStyle>
<initialize>
<paraStyle name="all" alignment="justify"/>
</initialize>
<paraStyle name="P1" fontName="Helvetica-Oblique" fontSize="2.0" leading="3" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
<paraStyle name="Standard" fontName="Times-Roman"/>
<paraStyle name="Text body" fontName="Times-Roman" spaceBefore="0.0" spaceAfter="6.0"/>
<paraStyle name="Heading" fontName="Helvetica" fontSize="14.0" leading="17" spaceBefore="12.0" spaceAfter="6.0"/>
<paraStyle name="List" fontName="Times-Roman" spaceBefore="0.0" spaceAfter="6.0"/>
<paraStyle name="Table Contents" fontName="Times-Roman" spaceBefore="0.0" spaceAfter="6.0"/>
<paraStyle name="Table Heading" fontName="Times-Roman" alignment="CENTER" spaceBefore="0.0" spaceAfter="6.0"/>
<paraStyle name="Caption" fontName="Times-Roman" fontSize="12.0" leading="15" spaceBefore="6.0" spaceAfter="6.0"/>
<paraStyle name="Index" fontName="Times-Roman"/>
<paraStyle name="Footer" fontName="Times-Roman"/>
<paraStyle name="Horizontal Line" fontName="Times-Roman" fontSize="6.0" leading="8" spaceBefore="0.0" spaceAfter="14.0"/>
<paraStyle name="terp_header" fontName="Helvetica-Bold" fontSize="15.0" leading="19" alignment="LEFT" spaceBefore="12.0" spaceAfter="6.0"/>
<paraStyle name="Heading 9" fontName="Helvetica-Bold" fontSize="75%" leading="NaN" spaceBefore="12.0" spaceAfter="6.0"/>
<paraStyle name="terp_tblheader_General" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/>
<paraStyle name="terp_tblheader_Details" fontName="Helvetica-Bold" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/>
<paraStyle name="terp_default_8" fontName="Helvetica" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
<paraStyle name="terp_default_Bold_8" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
<paraStyle name="terp_tblheader_General_Centre" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="CENTER" spaceBefore="6.0" spaceAfter="6.0"/>
<paraStyle name="terp_tblheader_General_Right" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="RIGHT" spaceBefore="6.0" spaceAfter="6.0"/>
<paraStyle name="terp_tblheader_Details_Centre" fontName="Helvetica-Bold" fontSize="9.0" leading="11" alignment="CENTER" spaceBefore="6.0" spaceAfter="6.0"/>
<paraStyle name="terp_tblheader_Details_Right" fontName="Helvetica-Bold" fontSize="9.0" leading="11" alignment="RIGHT" spaceBefore="6.0" spaceAfter="6.0"/>
<paraStyle name="terp_default_Right_8" fontName="Helvetica" fontSize="8.0" leading="10" alignment="RIGHT" spaceBefore="0.0" spaceAfter="0.0"/>
<paraStyle name="terp_default_Centre_8" fontName="Helvetica" fontSize="8.0" leading="10" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/>
<paraStyle name="terp_header_Right" fontName="Helvetica-Bold" fontSize="15.0" leading="19" alignment="LEFT" spaceBefore="12.0" spaceAfter="6.0"/>
<paraStyle name="terp_header_Centre" fontName="Helvetica-Bold" fontSize="11.0" leading="14" alignment="CENTER" spaceBefore="12.0" spaceAfter="6.0"/>
<paraStyle name="terp_default_address" fontName="Helvetica" fontSize="10.0" leading="13" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
<paraStyle name="terp_default_9" fontName="Helvetica" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
<paraStyle name="terp_default_Bold_9" fontName="Helvetica-Bold" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
<paraStyle name="terp_default_Centre_9" fontName="Helvetica" fontSize="9.0" leading="11" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/>
<paraStyle name="terp_default_Right_9" fontName="Helvetica" fontSize="9.0" leading="11" alignment="RIGHT" spaceBefore="0.0" spaceAfter="0.0"/>
<paraStyle name="terp_default_1" fontName="Helvetica" fontSize="2.0" leading="3" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
<paraStyle name="terp_default_8_underline" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
</stylesheet>
<images/>
<story>
<para style="terp_default_9">
<font color="white"> </font>
</para>
<blockTable colWidths="139.0,220.0,152.0" repeatRows="1" style="Table1">
<tr>
<td>
<para style="terp_header_Centre">
<font color="white"> </font>
</para>
</td>
<td>
<para style="terp_header_Centre">Introspection report on objects</para>
</td>
<td>
<para style="terp_header_Centre">
<font color="white"> </font>
</para>
</td>
</tr>
</blockTable>
<para style="Standard">
<font color="white"> </font>
</para>
<para style="Standard">
<font color="white"> </font>
</para>
<section>
<para style="Text body">[[ repeatIn(objects,'module') ]]</para>
<blockTable colWidths="102.0,102.0,102.0,102.0,102.0" style="module_tbl_heading">
<tr>
<td>
<para style="terp_tblheader_General_Centre">Module</para>
</td>
<td>
<para style="terp_tblheader_General_Centre">Name</para>
</td>
<td>
<para style="terp_tblheader_General_Centre">Version</para>
</td>
<td>
<para style="terp_tblheader_General_Centre">Directory</para>
</td>
<td>
<para style="terp_tblheader_General_Centre">Web</para>
</td>
</tr>
</blockTable>
<blockTable colWidths="102.0,102.0,102.0,102.0,102.0" style="module_tbl_content">
<tr>
<td>
<para style="terp_default_Centre_8">[[ module.name ]]</para>
</td>
<td>
<para style="terp_default_Centre_8">[[ module.shortdesc]]</para>
</td>
<td>
<para style="terp_default_Centre_8">[[module.latest_version]]</para>
</td>
<td>
<para style="terp_default_Centre_8">[[ module.name ]]</para>
</td>
<td>
<para style="terp_default_Centre_8">[[ module.website ]]</para>
</td>
</tr>
</blockTable>
<para style="terp_default_8">
<font color="white"> </font>
</para>
<para style="terp_default_8">[[ module.description ]]</para>
<para style="terp_default_Bold_8">
<font color="white"> </font>
</para>
<para style="terp_default_8_underline">Reports :</para>
<para style="terp_default_8">[[ format(module.reports_by_module) ]]</para>
<para style="terp_default_8">
<font color="white"> </font>
</para>
<para style="terp_default_8_underline">Menu :</para>
<para style="terp_default_8">[[ format(module.menus_by_module) ]]</para>
<para style="terp_default_8">
<font color="white"> </font>
</para>
<para style="terp_default_8_underline">View :</para>
<para style="terp_default_8">[[ format(module.views_by_module) ]]</para>
<para style="terp_default_8">
<font color="white"> </font>
</para>
<blockTable colWidths="510.0" style="depen_tbl">
<tr>
<td>
<para style="terp_default_8_underline">Dependencies :</para>
</td>
</tr>
<tr>
<td>
<para style="terp_default_8">[[ repeatIn(module.dependencies_id,'dependencies_id') ]]</para>
<para style="terp_default_8">[[ dependencies_id.name ]] - [[ dependencies_id.state ]]</para>
</td>
</tr>
</blockTable>
<section>
<para style="terp_default_9">
<font color="white"> </font>
</para>
<para style="terp_default_9">[[ repeatIn(findobj(module.name) ,'object') ]]</para>
<para style="terp_default_1">
<font color="white"> </font>
</para>
<blockTable colWidths="510.0" repeatRows="1" style="Tableau3">
<tr>
<td>
<para style="terp_tblheader_Details">Object: [[ object.model ]] [[ objdoc(object.model) ]]</para>
</td>
</tr>
<tr>
<td>
<para style="terp_default_9">[[ repeatIn(objdoc2(object.model) or [], 'sline') ]]</para>
<para style="terp_default_9"> [[ sline ]] </para>
</td>
</tr>
</blockTable>
<section>
<para style="terp_default_1">
<font color="white"> </font>
</para>
</section>
<section>
<para style="P1">[[ repeatIn(findflds(object.model), 'field') ]]</para>
<blockTable colWidths="113.0,397.0" repeatRows="1" style="Table2">
<tr>
<td>
<para style="terp_default_9">[[ field[0] ]]</para>
</td>
<td>
<para style="terp_default_9">[[ field[1].get('string', 'Unknown') ]], [[ field[1]['type'] ]] [[field[1].get('required',False) and ', required']] [[field[1].get('readonly',False) and ', readonly']] </para>
<para style="terp_default_9">[[ field[1].get('help', '') ]]</para>
</td>
</tr>
</blockTable>
<para style="terp_default_1">
<font color="white"> </font>
</para>
</section>
</section>
<pageBreak/>
<para style="terp_default_9"> [[ module.file_graph and setTag('para','image', {'width':'300.0','height':'250.0'}) ]][[ module.file_graph ]] </para>
</section>
</story>
</document>

BIN
base_module_doc_rst/report/ir_module_reference_graph.sxw

94
base_module_doc_rst/report/ir_module_reference_print_graph.py

@ -0,0 +1,94 @@
# -*- 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 time
from openerp.report import report_sxw
class IrModuleReferencePrintGraph(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(IrModuleReferencePrintGraph, self).__init__(
cr, uid, name, context=context
)
self.localcontext.update({
'time': time,
'findobj': self._object_find,
'objdoc': self._object_doc,
'objdoc2': self._object_doc2,
'findflds': self._fields_find,
})
def _object_doc(self, obj):
modobj = self.pool.get(obj)
strdocs = modobj.__doc__
if not strdocs:
return None
else:
strdocs = strdocs.strip().splitlines(True)
res = ''
for stre in strdocs:
if not stre or stre.isspace():
break
res += stre
return res
def _object_doc2(self, obj):
modobj = self.pool.get(obj)
strdocs = modobj.__doc__
if not strdocs:
return None
else:
strdocs = strdocs.strip().splitlines(True)
res = []
fou = False
for stre in strdocs:
if fou:
res.append(stre.strip())
elif not stre or stre.isspace():
fou = True
return res
def _object_find(self, module):
ids2 = self.pool.get('ir.model.data').search(
self.cr, self.uid, [
('module', '=', module), ('model', '=', 'ir.model')
]
)
ids = []
for mod in self.pool.get('ir.model.data').browse(
self.cr, self.uid, ids2
):
ids.append(mod.res_id)
modobj = self.pool.get('ir.model')
return modobj.browse(self.cr, self.uid, ids)
def _fields_find(self, obj):
modobj = self.pool.get(obj)
res = modobj.fields_get(self.cr, self.uid).items()
return res
report_sxw.report_sxw(
'report.ir.module.reference.graph',
'ir.module.module',
'addons/base_module_doc_rst/report/ir_module_reference_graph.rml',
parser=IrModuleReferencePrintGraph,
header=False
)

118
base_module_doc_rst/report/report_proximity_graph.py

@ -0,0 +1,118 @@
# -*- 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 pydot
from openerp import report
from openerp import pooler
from openerp import tools
class ReportGraph(report.interface.report_int):
def __init__(self, name, table):
report.interface.report_int.__init__(self, name)
self.table = table
def get_proximity_graph(self, cr, uid, module_id, context=None):
pool_obj = pooler.get_pool(cr.dbname)
module_obj = pool_obj.get('ir.module.module')
nodes = [('base', 'unknown')]
edges = []
def get_depend_module(module_id):
module_record = module_obj.browse(
cr, uid, module_id, context=context
)
if module_record.name not in nodes:
# Add new field ir.module.module object in server side.
# field name = module_type/
nodes.append((module_record.name, "unknown"))
if module_record.dependencies_id:
for depen in module_record.dependencies_id:
if (module_record.name, depen.name) not in edges:
edges.append((module_record.name, depen.name))
if depen.name == "base":
continue
id = module_obj.browse(cr, uid, module_obj.search(
cr, uid, [('name', '=', depen.name)]), context=context
)
if id:
get_depend_module(id[0].id)
get_depend_module(module_id)
graph = pydot.Dot(
graph_type='digraph',
fontsize='10',
label="""
Proximity Graph.
Gray Color-Official Modules,
Red Color-Extra Addons Modules,
Blue Color-Community Modules,
Purple Color-Unknow Modules
""",
center='1'
)
for node in nodes:
if node[1] == "official":
graph.add_node(
pydot.Node(
node[0], style="filled", fillcolor="lightgray"
)
)
elif node[1] == "extra_addons":
graph.add_node(
pydot.Node(
node[0], style="filled", fillcolor="red"
)
)
elif node[1] == "community":
graph.add_node(
pydot.Node(
node[0], style="filled", fillcolor="#000FFF"
)
)
elif node[1] == "unknown":
graph.add_node(
pydot.Node(
node[0], style="filled", fillcolor="purple"
)
)
for edge in edges:
graph.add_edge(pydot.Edge(edge[0], edge[1]))
ps_string = graph.create(prog='dot', format='ps')
if os.name == "nt":
prog = 'ps2pdf.bat'
else:
prog = 'ps2pdf'
args = (prog, '-', '-')
input, output = tools.exec_command_pipe(*args)
input.write(ps_string)
input.close()
return output.read()
def create(self, cr, uid, ids, data, context=None):
pdf_string = self.get_proximity_graph(
cr, uid, context.get('active_id')
)
return (pdf_string, 'pdf')
ReportGraph('report.proximity.graph', 'ir.module.module')

23
base_module_doc_rst/wizard/__init__.py

@ -0,0 +1,23 @@
# -*- 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/>.
#
##############################################################################
from . import tech_rst_guide
from . import generate_relation_graph

45
base_module_doc_rst/wizard/generate_relation_graph.py

@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 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/>.
#
##############################################################################
from openerp.osv import orm
class CreateGraph(orm.TransientModel):
_name = "create.relation.graph"
def get_graph(self, cr, uid, datas, context=None):
mod_obj = self.pool.get('ir.module.module')
modules = mod_obj.browse(
cr, uid, context['active_ids'], context=context
)
for module in modules:
module_data = mod_obj.get_relation_graph(
cr, uid, module.name, context=context
)
if module_data['module_file']:
mod_obj.write(
cr,
uid,
[module.id],
{'file_graph': module_data['module_file']},
context=context
)
return {'type': 'ir.actions.act_window_close'}

28
base_module_doc_rst/wizard/generate_relation_graph_view.xml

@ -0,0 +1,28 @@
<?xml version="1.0"?>
<openerp>
<data>
<record id="view_relationship_graph" model="ir.ui.view">
<field name="name">create.relation.graph.form</field>
<field name="model">create.relation.graph</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Generate Relationship Graph">
<separator string="Relationship Graphs" colspan="6"/>
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
<button name="get_graph" string="Create Graphs" type="object" icon="gtk-ok"/>
</form>
</field>
</record>
<act_window id="generate_relationship_graph_values"
name="Generate Relationship Graph"
src_model="ir.module.module"
res_model="create.relation.graph"
view_mode="form"
view_id="view_relationship_graph"
target="new"
key2="client_action_multi"/>
</data>
</openerp>

28
base_module_doc_rst/wizard/tech_guide_rst_view.xml

@ -0,0 +1,28 @@
<?xml version="1.0"?>
<openerp>
<data>
<record id="view_technical_guide" model="ir.ui.view">
<field name="name">tech.guide.rst.form</field>
<field name="model">tech.guide.rst</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Create Technical Guide in rst format">
<separator string="Technical Guide in rst format" colspan="4"/>
<label string="Please choose a file where the Technical Guide will be written." colspan="4"/>
<field name="rst_file" />
</form>
</field>
</record>
<act_window id="wiz_tech_guide_rst"
name="Create RST Technical Guide2"
src_model="ir.module.module"
res_model="tech.guide.rst"
view_mode="form"
view_id="view_technical_guide"
target="new"
key2="client_action_multi"/>
</data>
</openerp>

523
base_module_doc_rst/wizard/tech_rst_guide.py

@ -0,0 +1,523 @@
# -*- 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/>.
#
##############################################################################
from openerp.osv import orm, fields
from openerp import netsvc
import base64
import tempfile
import tarfile
import httplib
import os
class RstDoc(object):
def __init__(self, module, objects):
self.dico = {
'name': module.name,
'shortdesc': module.shortdesc,
'latest_version': module.latest_version,
'website': module.website,
'description': self._handle_text(
module.description.strip() or 'None'
),
'report_list': self._handle_list_items(module.reports_by_module),
'menu_list': self._handle_list_items(module.menus_by_module),
'view_list': self._handle_list_items(module.views_by_module),
'depends': module.dependencies_id,
'author': module.author,
}
self.objects = objects
self.module = module
def _handle_list_items(self, list_item_as_string):
list_item_as_string = list_item_as_string.strip()
if list_item_as_string:
return [
item.replace("*", r"\*") for
item in
list_item_as_string.split('\n')
]
else:
return []
def _handle_text(self, txt):
lst = [' %s' % line for line in txt.split('\n')]
return '\n'.join(lst)
def _get_download_links(self):
def _is_connection_status_good(link):
server = "openerp.com"
status_good = False
try:
conn = httplib.HTTPConnection(server)
conn.request("HEAD", link)
res = conn.getresponse()
if res.status in (200, ):
status_good = True
except (Exception, ), e:
logger = netsvc.Logger()
msg = """
error connecting to server '%s' with link '%s'.
Error message: %s
""" % (server, link, str(e))
logger.notifyChannel(
"base_module_doc_rst", netsvc.LOG_ERROR, msg
)
status_good = False
return status_good
versions = ('4.2', '5.0', 'trunk')
download_links = []
for ver in versions:
link = 'http://www.openerp.com/download/modules/%s/%s.zip' % (
ver, self.dico['name']
)
if _is_connection_status_good(link):
download_links.append(" * `%s <%s>`_" % (ver, link))
if download_links:
res = '\n'.join(download_links)
else:
res = "(No download links available)"
return res
def _write_header(self):
dico = self.dico
title = "%s (*%s*)" % (dico['shortdesc'], dico['name'])
title_underline = "=" * len(title)
dico['title'] = title
dico['title_underline'] = title_underline
dico['download_links'] = self._get_download_links()
sl = [
"",
".. module:: %(name)s",
" :synopsis: %(shortdesc)s",
" :noindex:",
".. ",
"",
".. raw:: html",
"",
" <br />",
"""
<link rel="stylesheet"
href="../_static/hide_objects_in_sidebar.css"
type="text/css" />
""",
"",
"""
.. tip:: This module is part of the OpenERP software,
the leading Open Source
""",
""" enterprise management system. If you want to discover OpenERP,
check our
""",
""" `screencasts <http://openerp.tv>`_ or download """,
""" `OpenERP <http://openerp.com>`_ directly.""",
"",
".. raw:: html",
"",
"""
<div class="js-kit-rating"
title="" permalink="" standalone="yes" path="/%s"></div>
""" % (dico['name'],),
""" <script src="http://js-kit.com/ratings.js"></script>""",
"",
"%(title)s",
"%(title_underline)s",
":Module: %(name)s",
":Name: %(shortdesc)s",
":Version: %(latest_version)s",
":Author: %(author)s",
":Directory: %(name)s",
":Web: %(website)s",
"",
"Description",
"-----------",
"",
"::",
"",
"%(description)s",
"",
"Download links",
"--------------",
"",
"You can download this module as a zip file in following version:",
"",
"%(download_links)s",
"",
""]
return '\n'.join(sl) % (dico)
def _write_reports(self):
sl = ["",
"Reports",
"-------"]
reports = self.dico['report_list']
if reports:
for report in reports:
if report:
sl.append("")
sl.append(" * %s" % report)
else:
sl.extend(["", "None", ""])
sl.append("")
return '\n'.join(sl)
def _write_menus(self):
sl = ["",
"Menus",
"-------",
""]
menus = self.dico['menu_list']
if menus:
for menu in menus:
if menu:
sl.append(" * %s" % menu)
else:
sl.extend(["", "None", ""])
sl.append("")
return '\n'.join(sl)
def _write_views(self):
sl = ["",
"Views",
"-----",
""]
views = self.dico['view_list']
if views:
for view in views:
if view:
sl.append(" * %s" % view)
else:
sl.extend(["", "None", ""])
sl.append("")
return '\n'.join(sl)
def _write_depends(self):
sl = ["",
"Dependencies",
"------------",
""]
depends = self.dico['depends']
if depends:
for dependency in depends:
sl.append(" * :mod:`%s`" % (dependency.name))
else:
sl.extend(["", "None", ""])
sl.append("")
return '\n'.join(sl)
def _write_objects(self):
def write_field(field_def):
if not isinstance(field_def, tuple):
logger = netsvc.Logger()
msg = "Error on Object %s: field_def: %s [type: %s]" % (
obj_name.encode('utf8'),
field_def.encode('utf8'),
type(field_def)
)
logger.notifyChannel(
"base_module_doc_rst", netsvc.LOG_ERROR, msg
)
return ""
field_name = field_def[0]
field_dict = field_def[1]
field_required = field_dict.get('required', '') and ', required'
field_readonly = field_dict.get('readonly', '') and ', readonly'
field_help_s = field_dict.get('help', '')
if field_help_s:
field_help_s = "*%s*" % (field_help_s)
field_help = '\n'.join(
[
' %s' % line.strip() for
line in
field_help_s.split('\n')
]
)
else:
field_help = ''
sl = [
"",
":%s: %s, %s%s%s" % (field_name,
field_dict.get('string', 'Unknown'),
field_dict['type'],
field_required,
field_readonly),
"",
field_help,
]
return '\n'.join(sl)
sl = ["",
"",
"Objects",
"-------"]
if self.objects:
for obj in self.objects:
obj_name = obj['object'].name
obj_model = obj['object'].model
title = "Object: %s (%s)" % (obj_name, obj_model)
slo = [
"",
title,
'#' * len(title),
"",
]
for field in obj['fields']:
slf = [
"",
write_field(field),
"",
]
slo.extend(slf)
sl.extend(slo)
else:
sl.extend(["", "None", ""])
return u'\n'.join([a.decode('utf8') for a in sl])
def _write_relationship_graph(self, module_name=False):
sl = ["",
"Relationship Graph",
"------------------",
"",
".. figure:: %s_module.png" % (module_name, ),
" :scale: 50",
" :align: center",
""]
sl.append("")
return '\n'.join(sl)
def write(self, module_name=False):
s = ''
s += self._write_header()
s += self._write_depends()
s += self._write_reports()
s += self._write_menus()
s += self._write_views()
s += self._write_objects()
if module_name:
s += self._write_relationship_graph(module_name)
return s
class WizardTechGuideRst(orm.TransientModel):
_name = "tech.guide.rst"
_columns = {
'rst_file': fields.binary('File', required=True, readonly=True),
}
def _generate(self, cr, uid, context):
module_model = self.pool.get('ir.module.module')
module_ids = context['active_ids']
module_index = []
# create a temporary gzipped tarfile:
tgz_tmp_filename = tempfile.mktemp('_rst_module_doc.tgz')
try:
tarf = tarfile.open(tgz_tmp_filename, 'w:gz')
modules = module_model.browse(cr, uid, module_ids)
for module in modules:
index_dict = {
'name': module.name,
'shortdesc': module.shortdesc,
}
module_index.append(index_dict)
objects = self._get_objects(cr, uid, module)
module.test_views = self._get_views(
cr, uid, module.id, context=context
)
rstdoc = RstDoc(module, objects)
# Append Relationship Graph on rst
graph_mod = False
module_name = False
if module.file_graph:
graph_mod = base64.decodestring(module.file_graph)
else:
module_data = module_model.get_relation_graph(
cr, uid, module.name, context=context
)
if module_data['module_file']:
graph_mod = base64.decodestring(
module_data['module_file']
)
if graph_mod:
module_name = module.name
try:
tmp_file_graph = tempfile.NamedTemporaryFile()
tmp_file_graph.write(graph_mod)
tmp_file_graph.file.flush()
tarf.add(
tmp_file_graph.name,
arcname=module.name + '_module.png'
)
finally:
tmp_file_graph.close()
out = rstdoc.write(module_name)
try:
tmp_file = tempfile.NamedTemporaryFile()
tmp_file.write(out.encode('utf8'))
tmp_file.file.flush() # write content to file
tarf.add(tmp_file.name, arcname=module.name + '.rst')
finally:
tmp_file.close()
# write index file:
tmp_file = tempfile.NamedTemporaryFile()
out = self._create_index(module_index)
tmp_file.write(out.encode('utf8'))
tmp_file.file.flush()
tarf.add(tmp_file.name, arcname='index.rst')
finally:
tarf.close()
f = open(tgz_tmp_filename, 'rb')
out = f.read()
f.close()
if os.path.exists(tgz_tmp_filename):
try:
os.unlink(tgz_tmp_filename)
except Exception, e:
logger = netsvc.Logger()
msg = "Temporary file %s could not be deleted. (%s)" % (
tgz_tmp_filename, e
)
logger.notifyChannel("warning", netsvc.LOG_WARNING, msg)
return base64.encodestring(out)
def _get_views(self, cr, uid, module_id, context=None):
module_module_obj = self.pool.get('ir.module.module')
model_data_obj = self.pool.get('ir.model.data')
view_obj = self.pool.get('ir.ui.view')
report_obj = self.pool.get('ir.actions.report.xml')
menu_obj = self.pool.get('ir.ui.menu')
res = {}
mlist = module_module_obj.browse(cr, uid, [module_id], context=context)
mnames = {}
for m in mlist:
mnames[m.name] = m.id
res[m.id] = {
'menus_by_module': [],
'reports_by_module': [],
'views_by_module': []
}
view_id = model_data_obj.search(
cr,
uid,
[
('module', 'in', mnames.keys()),
('model', 'in', (
'ir.ui.view', 'ir.actions.report.xml', 'ir.ui.menu'
))
]
)
for data_id in model_data_obj.browse(cr, uid, view_id, context):
# We use try except, because views or menus may not exist
try:
key = data_id['model']
if key == 'ir.ui.view':
v = view_obj.browse(cr, uid, data_id.res_id)
v_dict = {
'name': v.name,
'inherit': v.inherit_id,
'type': v.type}
res[mnames[data_id.module]]['views_by_module'].append(
v_dict
)
elif key == 'ir.actions.report.xml':
res[mnames[data_id.module]]['reports_by_module'].append(
report_obj.browse(cr, uid, data_id.res_id).name
)
elif key == 'ir.ui.menu':
res[mnames[data_id.module]]['menus_by_module'].append(
menu_obj.browse(cr, uid, data_id.res_id).complete_name
)
except (KeyError, ):
pass
return res
def _create_index(self, module_index):
sl = ["",
".. _module-technical-guide-link:",
"",
"Module Technical Guide: Introspection report on objects",
"=======================================================",
"",
".. toctree::",
" :maxdepth: 1",
"",
]
for mod in module_index:
sl.append(" %s" % mod['name'])
sl.append("")
return '\n'.join(sl)
def _get_objects(self, cr, uid, module):
res = []
objects = self._object_find(cr, uid, module)
for obj in objects:
fields = self._fields_find(cr, uid, obj.model)
dico = {
'object': obj,
'fields': fields
}
res.append(dico)
return res
def _object_find(self, cr, uid, module):
ir_model_data = self.pool.get('ir.model.data')
ids2 = ir_model_data.search(
cr, uid, [('module', '=', module.name), ('model', '=', 'ir.model')]
)
ids = []
for mod in ir_model_data.browse(cr, uid, ids2):
ids.append(mod.res_id)
return self.pool.get('ir.model').browse(cr, uid, ids)
def _fields_find(self, cr, uid, obj):
modobj = self.pool.get(obj)
if modobj:
res = modobj.fields_get(cr, uid).items()
return res
else:
logger = netsvc.Logger()
msg = "Object %s not found" % (obj)
logger.notifyChannel("base_module_doc_rst", netsvc.LOG_ERROR, msg)
return ""
_defaults = {
'rst_file': _generate,
}
Loading…
Cancel
Save