odoo以开发者模式运行的话,能自动检测所有的addons目录的代码变动情况自动进行reload
这个机制对于python代码来说是够用的,但是对csv安全规则、xml数据及视图模版来说还需要更新模块才能使其生效
今天由于逐个测试安全规则条目,不断的手工更新模块不胜其烦,只好深入研究一下
odoo9开始已经将开发者模式依赖的pyinotify替换为watchdog,可能是后者的应用范围更广把,不仅提供python库,还附带shell工具
那就学习下这个叫watchmedo的命令行工具吧
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | (python)[srj@x1c odoo9]$ watchmedo --help usage: watchmedo [-h] [--version]                  {tricks-from,tricks-generate-yaml,log,shell-command,auto-restart}                  ... positional arguments:   {tricks-from,tricks-generate-yaml,log,shell-command,auto-restart}     tricks-from         Subcommand to execute tricks from a tricks                         configuration file. :param args: Command line argument                         options.     tricks-generate-yaml                         Subcommand to generate Yaml configuration for tricks                         named on the command line. :param args: Command line                         argument options.     log                 Subcommand to log file system events to the console.                         :param args: Command line argument options.     shell-command       Subcommand to execute shell commands in response to                         file system events. :param args: Command line argument                         options.     auto-restart        Subcommand to start a long-running subprocess and                         restart it on matched events. :param args: Command                         line argument options. optional arguments:   -h, --help            show this help message and exit   --version             show program's version number and exit | 
看到auto-restart参数后真是让人眼前一亮,根据提示继续学习二级参数
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | (python)[srj@x1c odoo9]$ watchmedo auto-restart -h usage: watchmedo auto-restart [-h] [-d directory] [-p PATTERNS]                               [-i IGNORE_PATTERNS] [-D] [-R]                               [--interval TIMEOUT] [--signal SIGNAL]                               [--kill-after KILL_AFTER]                               command [arg [arg ...]]     Subcommand to start a long-running subprocess and restart it     on matched events.     :param args:         Command line argument options. positional arguments:   command               Long-running command to run in a subprocess.   arg                   Command arguments. Note: Use -- before the command                         arguments, otherwise watchmedo will try to interpret                         them. (default: -) optional arguments:   -h, --help            show this help message and exit   -d directory, --directory directory                         Directory to watch. Use another -d or --directory                         option for each directory. (default: -)   -p PATTERNS, --pattern PATTERNS, --patterns PATTERNS                         matches event paths with these patterns (separated by                         ;). (default: '*')   -i IGNORE_PATTERNS, --ignore-pattern IGNORE_PATTERNS, --ignore-patterns IGNORE_PATTERNS                         ignores event paths with these patterns (separated by                         ;). (default: '')   -D, --ignore-directories                         ignores events for directories (default: False)   -R, --recursive       monitors the directories recursively (default: False)   --interval TIMEOUT, --timeout TIMEOUT                         use this as the polling interval/blocking timeout                         (default: 1.0)   --signal SIGNAL       stop the subprocess with this signal (default SIGINT)                         (default: 'SIGINT')   --kill-after KILL_AFTER                         when stopping, kill the subprocess after the specified                         timeout (default 10) (default: 10.0) | 
真是太强大了,本以为还要写点小代码什么的,没想到几个选项就可以灵活组合出一个小型的监控工具
| 1 | watchmedo auto-restart -R -p="*.py;*.xml;*.csv" -d /home/srj/Git/Odoo/custom_addons/account_simple/ -- ./odoo.py -c c.conf -d test9 -u account_simple | 
-R是目录递归监控
-p是文件模式匹配,主要是排除前端资源和pyc
-d是指定监控目录
–是watchmedo与odoo各自的命令行参数分割线
至此odoo的模块开发效率又提高了一个层次:)