[FIX] use unique localstorage path when running phantomjs tests
[odoo/odoo.git] / openerp / cli / __init__.py
1 import logging
2 import sys
3
4 import openerp
5 from openerp import tools
6 from openerp.modules import module
7
8 _logger = logging.getLogger(__name__)
9
10 commands = {}
11
12 class CommandType(type):
13     def __init__(cls, name, bases, attrs):
14         super(CommandType, cls).__init__(name, bases, attrs)
15         name = getattr(cls, name, cls.__name__.lower())
16         cls.name = name
17         if name != 'command':
18             commands[name] = cls
19
20 class Command(object):
21     """Subclass this class to define new openerp subcommands """
22     __metaclass__ = CommandType
23
24     def run(self, args):
25         pass
26
27 class Help(Command):
28     def run(self, args):
29         print "Available commands:\n"
30         for k, v in commands.items():
31             print "    %s" % k
32
33 import server
34
35 def main():
36     args = sys.argv[1:]
37
38     # The only shared option is '--addons-path=' needed to discover additional
39     # commands from modules
40     if len(args) > 1 and args[0].startswith('--addons-path=') and not args[1].startswith("-"):
41         # parse only the addons-path, do not setup the logger...
42         tools.config._parse_config([args[0]])
43         args = args[1:]
44
45     # Default legacy command
46     command = "server"
47
48     # Subcommand discovery
49     if len(args) and not args[0].startswith("-"):
50         for m in module.get_modules():
51             m = 'openerp.addons.' + m
52             __import__(m)
53             #try:
54             #except Exception, e:
55             #    raise
56             #    print e
57         command = args[0]
58         args = args[1:]
59
60     if command in commands:
61         o = commands[command]()
62         o.run(args)
63
64 # vim:et:ts=4:sw=4: