Launchpad automatic translations update.
[odoo/odoo.git] / tools / 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 def load_information_from_description_file(module):
31     """
32     :param module: The name of the module (sale, purchase, ...)
33     """
34     for filename in ['__openerp__.py', '__terp__.py']:
35         description_file = os.path.join(module, filename)
36         if os.path.isfile(description_file):
37             return eval(file(description_file).read())
38
39     return {}
40
41 def get_valid_path(paths, module):
42     for path in paths:
43         full = os.path.join(path, module)
44         if os.path.exists(full):
45             return full
46     return None
47
48 parser = optparse.OptionParser(usage="%prog [options] [module1 [module2 ...]]")
49 parser.add_option("-p", "--addons-path", dest="path", help="addons directory", action="append")
50 (opt, args) = parser.parse_args()
51
52 modules = []
53 if not opt.path:
54     opt.path = ["."]
55
56 if not args:
57     for path in opt.path:
58         modules += map(os.path.dirname, glob.glob(os.path.join(path, '*', '__openerp__.py')))
59         modules += map(os.path.dirname, glob.glob(os.path.join(path, '*', '__terp__.py')))
60 else:
61     for module in args:
62         valid_path = get_valid_path(opt.path, module)
63         if valid_path:
64             modules.append(valid_path)
65
66 all_modules = set(map(os.path.basename, modules))
67 print 'digraph G {'
68 while len(modules):
69     f = modules.pop(0)
70     module_name = os.path.basename(f)
71     all_modules.add(module_name)
72     info = load_information_from_description_file(f)
73     if info.get('installable', True):
74         for name in info.get('depends',[]):
75             valid_path = get_valid_path(opt.path, name)
76             if name not in all_modules:
77                 if valid_path:
78                     modules.append(valid_path)
79                 else:
80                     all_modules.add(name)
81                     print '\t%s [color=red]' % (name,)
82             print '\t%s -> %s;' % (module_name, name)
83 print '}'
84
85 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
86