[FIX] website_forum: fixed controller creating a new forum tha was crashing.
[odoo/odoo.git] / openerpcommand / module.py
1 """
2 Show module information for a given database or from the file-system.
3 """
4 import os
5 import sys
6 import textwrap
7
8 from . import common
9
10 # TODO provide a --rpc flag to use XML-RPC (with a specific username) instead
11 # of server-side library.
12 def run(args):
13     assert args.database
14     import openerp
15
16     config = openerp.tools.config
17     config['log_handler'] = [':CRITICAL']
18     if args.addons:
19         args.addons = args.addons.split(':')
20     else:
21         args.addons = []
22     config['addons_path'] = ','.join(args.addons)
23     openerp.netsvc.init_logger()
24
25     if args.filesystem:
26         module_names = common.get_addons_from_paths(args.addons, [])
27         print "Modules (addons path %s):" % (', '.join(args.addons),)
28         for x in sorted(module_names):
29             print x
30     else:
31         registry = openerp.modules.registry.RegistryManager.get(
32             args.database, update_module=False)
33  
34         xs = []
35         ir_module_module = registry.get('ir.module.module')
36         with registry.cursor() as cr:
37             ids = ir_module_module.search(cr, openerp.SUPERUSER_ID, [], {})
38             xs = ir_module_module.read(cr, openerp.SUPERUSER_ID, ids, [], {})
39  
40         if xs:
41             print "Modules (database `%s`):" % (args.database,)
42             for x in xs:
43                 if args.short:
44                     print '%3d %s' % (x['id'], x['name'])
45                 else:
46                     print '%3d %s %s' % (x['id'], x['name'], {'installed': '(installed)'}.get(x['state'], ''))
47         else:
48             print "No module found (database `%s`)." % (args.database,)
49
50 def add_parser(subparsers):
51     parser = subparsers.add_parser('module',
52         description='Display modules known from a given database or on file-system.')
53     parser.add_argument('-d', '--database', metavar='DATABASE',
54         **common.required_or_default('DATABASE', 'the database to modify'))
55     common.add_addons_argument(parser)
56     parser.add_argument('-m', '--module', metavar='MODULE', required=False,
57         help='the module for which information should be shown')
58     parser.add_argument('-v', '--verbose', action='store_true',
59         help='display more information')
60     parser.add_argument('--short', action='store_true',
61         help='display less information')
62     parser.add_argument('-f', '--filesystem', action='store_true',
63         help='display module in the addons path, not in db')
64
65     parser.set_defaults(run=run)