[IMP] hw_proxy: adding a few troubleshoot info to the manual + add the compiled pdf...
[odoo/odoo.git] / history / module_graph.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 ##############################################################################
4 #
5 #    OpenERP, Open Source Management Solution
6 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
7 #
8 #    This program is free software: you can redistribute it and/or modify
9 #    it under the terms of the GNU Affero General Public License as
10 #    published by the Free Software Foundation, either version 3 of the
11 #    License, or (at your option) any later version.
12 #
13 #    This program is distributed in the hope that it will be useful,
14 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 #    GNU Affero General Public License for more details.
17 #
18 #    You should have received a copy of the GNU Affero General Public License
19 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 #
21 ##############################################################################
22
23 # TODO handle the case of zip modules
24
25 import os
26 import optparse
27 import sys
28 import glob
29
30 # TODO use the same function provided in openerp.modules
31 def load_information_from_description_file(module):
32     """
33     :param module: The name of the module (sale, purchase, ...)
34     """
35     for filename in ['__openerp__.py', '__terp__.py']:
36         description_file = os.path.join(module, filename)
37         if os.path.isfile(description_file):
38             return eval(file(description_file).read())
39
40     return {}
41
42 def get_valid_path(paths, module):
43     for path in paths:
44         full = os.path.join(path, module)
45         if os.path.exists(full):
46             return full
47     return None
48
49 parser = optparse.OptionParser(usage="%prog [options] [module1 [module2 ...]]")
50 parser.add_option("-p", "--addons-path", dest="path", help="addons directory", action="append")
51 (opt, args) = parser.parse_args()
52
53 modules = []
54 if not opt.path:
55     opt.path = ["."]
56
57 if not args:
58     for path in opt.path:
59         modules += map(os.path.dirname, glob.glob(os.path.join(path, '*', '__openerp__.py')))
60         modules += map(os.path.dirname, glob.glob(os.path.join(path, '*', '__terp__.py')))
61 else:
62     for module in args:
63         valid_path = get_valid_path(opt.path, module)
64         if valid_path:
65             modules.append(valid_path)
66
67 all_modules = set(map(os.path.basename, modules))
68 print 'digraph G {'
69 while len(modules):
70     f = modules.pop(0)
71     module_name = os.path.basename(f)
72     all_modules.add(module_name)
73     info = load_information_from_description_file(f)
74     if info.get('installable', True):
75         for name in info.get('depends',[]):
76             valid_path = get_valid_path(opt.path, name)
77             if name not in all_modules:
78                 if valid_path:
79                     modules.append(valid_path)
80                 else:
81                     all_modules.add(name)
82                     print '\t%s [color=red]' % (name,)
83             print '\t%s -> %s;' % (module_name, name)
84 print '}'
85
86 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
87