a48d20e448377f8dd48528349ae1772ba7c705ad
[odoo/odoo.git] / openerp / cli / __init__.py
1 import logging
2 import sys
3
4 import openerp
5
6 _logger = logging.getLogger(__name__)
7
8 commands = {}
9
10 class CommandType(type):
11     def __init__(cls, name, bases, attrs):
12         super(CommandType, cls).__init__(name, bases, attrs)
13         name = getattr(cls, name, cls.__name__.lower())
14         cls.name = name
15         if name != 'command':
16             commands[name] = cls
17
18 class Command(object):
19     """Subclass this class to define new openerp subcommands """
20     __metaclass__ = CommandType
21
22     def run(self, args):
23         pass
24
25 class Help(Command):
26     def run(self, args):
27         print "Available commands:\n"
28         for k, v in commands.items():
29             print "    %s" % k
30
31 import server
32
33 def main():
34     args = sys.argv[1:]
35     command = "server"
36     if len(args) and not args[0].startswith("-"):
37         command = args[0]
38         args = args[1:]
39
40     if command in commands:
41         o = commands[command]()
42         o.run(args)
43
44 # vim:et:ts=4:sw=4: