55from quickpython .config import Config
66from quickpython .component import hooker
77from quickpython .component .scheduler import Scheduler
8+ from quickpython .component .scheduler import INSTALL_DPS as Scheduler_INSTALL_DPS
89logger = logging .getLogger (__name__ )
910
1011
@@ -30,13 +31,27 @@ def _call(argv):
3031 cmd_path = str (app_path + "/command" ).replace ("\\ " , "." ).replace (r"/" , "." )
3132 app_cmd = importlib .import_module (cmd_path )
3233 if hasattr (app_cmd , 'COMMANDS' ):
33- choice = sys .argv [1 ]
34- if choice in app_cmd .COMMANDS :
35- app_cmd .COMMANDS [choice ](sys .argv [2 :] if len (sys .argv ) > 2 else [])
36- else :
37- logging .warning ("未知命令:{}" .format (choice ))
34+ app_cmd = app_cmd .COMMANDS
3835 else :
39- logging .warning ("app/command.py脚本中未包含COMMANDS配置" )
36+ app_cmd = {}
37+
38+ # 框架自带命令
39+ qp_cmd = CommandManager .get_qp_cmd ()
40+ app_cmd = {** app_cmd , ** qp_cmd }
41+
42+ # 执行调用
43+ choice = sys .argv [1 ]
44+ if choice in app_cmd :
45+ app_cmd [choice ](sys .argv [2 :] if len (sys .argv ) > 2 else [])
46+ else :
47+ logging .error ("未知命令:{}" .format (choice ))
48+
49+ @staticmethod
50+ def get_qp_cmd ():
51+ from quickpython .database .builder .generate import GenerateDemo
52+ return {
53+ 'model_gen' : GenerateDemo .call ,
54+ }
4055
4156
4257class ComponentManager :
@@ -50,17 +65,20 @@ def init():
5065 # hooker
5166 hooker .start ()
5267 # 定时器
53- scheduler = Scheduler .instance ()
54- app_crontab = importlib .import_module ("{}.crontab" .format (app_dir ))
55- if hasattr (app_crontab , 'TASKS' ):
56- scheduler .add (app_crontab .TASKS )
68+ if Scheduler_INSTALL_DPS :
69+ scheduler = Scheduler .instance ()
70+ app_crontab = importlib .import_module ("{}.crontab" .format (app_dir ))
71+ if hasattr (app_crontab , 'TASKS' ):
72+ scheduler .add (app_crontab .TASKS )
5773
5874 @staticmethod
5975 def start ():
60- Scheduler .instance ().start ()
76+ if Scheduler_INSTALL_DPS :
77+ Scheduler .instance ().start ()
6178
6279 @staticmethod
6380 def app_stop ():
6481 hooker .send (hooker .EXIT )
6582 hooker .stop ()
66- Scheduler .instance ().stop ()
83+ if Scheduler_INSTALL_DPS :
84+ Scheduler .instance ().stop ()
0 commit comments