首页 > 代码库 > odoo.cli.main()做了什么?

odoo.cli.main()做了什么?

先把代码贴过来

 1 def main():
 2     args = sys.argv[1:] 
 3 
 4     # The only shared option is ‘--addons-path=‘ needed to discover additional
 5     # commands from modules
 6     if len(args) > 1 and args[0].startswith(--addons-path=) and not args[1].startswith("-"): 如果有插件路径参数,则解析之
 7         # parse only the addons-path, do not setup the logger...
 8         odoo.tools.config._parse_config([args[0]])
 9         args = args[1:]
10 
11     # Default legacy command  这是要启动server吗?
12     command = "server"
13 
14     # TODO: find a way to properly discover addons subcommands without importing the world 需要一种方法确定必须导入的模块,而不是所有的模块
15     # Subcommand discovery
16     if len(args) and not args[0].startswith("-"):
17         logging.disable(logging.CRITICAL)
18         for module in get_modules():
19             if isdir(joinpath(get_module_path(module), cli)):
20                 __import__(odoo.addons. + module)
21         logging.disable(logging.NOTSET)
22         command = args[0]
23         args = args[1:]
24 
25     if command in commands:
26         o = commands[command]()
27         o.run(args)
28     else:
29         sys.exit(Unknow command %r % (command,))

at last o.run(args)

其中,command=‘server’

在python运行时探测得知

commands的内容是

{shell: <class odoo.cli.shell.Shell>, help: <class odoo.cli.command.Help>, deploy: <class odoo.cli.deploy.Deploy>, scaffold: <class odoo.cli.scaffold.Scaffold>, server: <class odoo.cli.server.Server>, star
t: <class odoo.cli.start.Start>}

也就是说server 代表的是<class odoo.cli.server.Server‘>

by the way

args is ”-w odoo -r odoo --addons-path=addons,../mymodules --db-filter=mydb$“

let‘s go!<class odoo.cli.server.Server‘>

odoo.cli.main()做了什么?