[IMP] module_graph.py: unknow modules are in red
[odoo/odoo.git] / bin / addons / module_graph.py
1 #!/usr/bin/python
2 # -*- encoding: utf-8 -*-
3 ##############################################################################
4 #
5 #    OpenERP, Open Source Management Solution   
6 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
7 #    $Id$
8 #
9 #    This program is free software: you can redistribute it and/or modify
10 #    it under the terms of the GNU General Public License as published by
11 #    the Free Software Foundation, either version 3 of the License, or
12 #    (at your option) any later version.
13 #
14 #    This program is distributed in the hope that it will be useful,
15 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
16 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 #    GNU General Public License for more details.
18 #
19 #    You should have received a copy of the GNU General Public License
20 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 #
22 ##############################################################################
23
24 # TODO handle the case of zip modules
25
26 import os
27 import sys
28 import glob
29
30 if len(sys.argv) == 2 and (sys.argv[1] in ['-h', '--help']):
31     print >>sys.stderr, 'Usage: module_graph.py [module1 module2 module3]\n\tWhen no module is specified, all modules in current directory are used'
32     sys.exit(1)
33
34 modules = sys.argv[1:]
35 if not len(modules):
36     modules = map(os.path.dirname, glob.glob(os.path.join('*', '__terp__.py')))
37
38 done = []
39
40 print 'digraph G {'
41 while len(modules):
42     f = modules.pop(0)
43     done.append(f)
44     if os.path.isfile(os.path.join(f,"__terp__.py")):
45         info=eval(file(os.path.join(f,"__terp__.py")).read())
46         if info.get('installable', True):
47             for name in info['depends']:
48                 if name not in done+modules:
49                     modules.append(name)
50                 if not os.path.exists(name):
51                     print '\t%s [color=red]' % (name,)
52                 print '\t%s -> %s;' % (f, name)
53 print '}'
54
55 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
56