Skip to content

Commit 1321908

Browse files
author
qlopc-msi
committed
增加框架自带命令
1 parent b0e0c5a commit 1321908

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

database/builder/generate.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
class GenerateDemo:
1313

14-
def call(self):
15-
""""""
16-
self.base()
14+
@staticmethod
15+
def call(argv):
16+
GenerateDemo().base()
1717

1818
def base(self):
1919
"""

database/connector/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __find_engine(config) -> Connector.__class__:
4444
return Connection.ENGINES.get(name)
4545

4646
@staticmethod
47-
def connect(name, config=None, re_connect=False) -> Connector:
47+
def connect(name=None, config=None, re_connect=False) -> Connector:
4848
"""获取连接,已连接直接返回"""
4949
if name is None and config is not None and 'name' in config:
5050
name = config['name']

server/command.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from quickpython.config import Config
66
from quickpython.component import hooker
77
from quickpython.component.scheduler import Scheduler
8+
from quickpython.component.scheduler import INSTALL_DPS as Scheduler_INSTALL_DPS
89
logger = 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

4257
class 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

Comments
 (0)