@@ -107,26 +107,21 @@ def module_run(module_name,def_name,args):
107
107
panel_path = public .get_panel_path ()
108
108
109
109
module_file = None
110
- if model_index :
110
+ if ' model_index' in args :
111
111
# 新模块目录
112
112
if model_index in ['mod' ]:
113
- _name = "{}Mod" .format (module_name .split ('/' )[1 ])
114
113
module_file = os .path .join (panel_path ,'mod' ,'project' ,module_name + 'Mod.py' )
115
114
elif model_index :
116
115
# 旧模块目录
117
- _name = "{}Model" .format (module_name )
118
116
module_file = os .path .join (class_path ,model_index + "Model" ,module_name + 'Model.py' )
119
117
else :
120
- _name = "{}Model" .format (module_name )
121
118
module_file = os .path .join (class_path ,"projectModel" ,module_name + 'Model.py' )
122
119
else :
123
120
# 如果没指定模块名称,则遍历所有模块目录
124
121
module_list = get_module_list ()
125
122
for name in module_list :
126
123
module_file = os .path .join (class_path ,name ,module_name + 'Model.py' )
127
- if os .path .exists (module_file ):
128
- _name = "{}Model" .format (module_name )
129
- break
124
+ if os .path .exists (module_file ): break
130
125
131
126
# 判断模块入口文件是否存在
132
127
if not os .path .exists (module_file ):
@@ -136,26 +131,22 @@ def module_run(module_name,def_name,args):
136
131
if not public .path_safe_check (module_file ):
137
132
return public .returnMsg (False ,'模块路径不合法' )
138
133
139
- public .sys_path_append (os .path .dirname (module_file ))
140
- # 引用模块入口文件
141
- module_main = __import__ (_name )
134
+ def_object = public .get_script_object (module_file )
135
+ if not def_object : return public .returnMsg (False ,'模块[%s]不存在' % module_file )
142
136
143
- # 检查模块是否符合规范
144
- if not hasattr ( module_main , 'main' ) :
145
- return public . returnMsg ( False , '指定模块入口文件不符合规范' )
146
-
147
- # 实例化模块类
148
- module_obj = getattr ( module_main , 'main' )( )
137
+ # 模块实例化并返回方法对象
138
+ try :
139
+ run_object = getattr ( def_object . main (), def_name , None )
140
+ except :
141
+ return public . returnMsg ( False , '模块[%s]入口实例化失败' % module_file )
142
+ if not run_object : return public . returnMsg ( False , '在[%s]模块中找不到[%s]方法' % ( module_file , def_name ) )
149
143
150
- # 检查方法是否存在
151
- if not hasattr (module_obj ,def_name ):
152
- return public .returnMsg (False ,'在[%s]模块中找不到[%s]方法' % (module_name ,def_name ))
153
-
154
144
if 'module_get_object' in args and args .module_get_object == 1 :
155
- return getattr ( module_obj , def_name )
156
-
145
+ return run_object
146
+
157
147
# 执行方法
158
- return getattr (module_obj ,def_name )(args )
148
+ result = run_object (args )
149
+ return result
159
150
160
151
161
152
def get_plugin_list (upgrade_force = False ):
0 commit comments