Skip to content

Commit 4f5dfbd

Browse files
committed
add command_file & fix bug: exec(): syntax error when inject python_code
1 parent c683c46 commit 4f5dfbd

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

hooks/__init__.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ def execute_task(self, server: PluginServerInterface, hook: str, var_dict: dict
122122
var_value = var_dict.get(key)
123123

124124
if (not utils.is_int_var(var_value)) and (not utils.is_list_var(var_value)) and (not utils.is_dict_var(var_value)):
125-
var_value = '"' + str(var_value) + '"'
125+
if str(var_value).__contains__('"'):
126+
var_value = "'" + str(var_value) + "'"
127+
else:
128+
var_value = '"' + str(var_value) + '"'
126129

127130
command_input.write(str(var_value))
128131
command_input.write(';')
@@ -363,10 +366,19 @@ def parse_and_apply_scripts(script: str, server: PluginServerInterface):
363366
content: dict[str, Union[str, Union[list, dict]]] = yaml.load(f.read(), Loader=yaml.Loader)
364367

365368
for task in content.get('tasks').values():
366-
# 创建task
367-
create_task(task.get('task_type'), task.get('command'), task.get('name'),
368-
server.get_plugin_command_source(),
369-
server)
369+
if (task.get('command_file') is not None) and (len(task.get('command_file')) > 0) and (os.path.isfile(task.get('command_file'))):
370+
with open(task.get('command_file'), 'r') as command_file:
371+
command_file_content = command_file.read()
372+
# 创建task
373+
create_task(task.get('task_type'), command_file_content, task.get('name'),
374+
server.get_plugin_command_source(),
375+
server)
376+
else:
377+
# 创建task
378+
create_task(task.get('task_type'), task.get('command'), task.get('name'),
379+
server.get_plugin_command_source(),
380+
server)
381+
370382
for hook in task.get('hooks'):
371383
# 挂载
372384
mount_task(hook, task.get('name'), server.get_plugin_command_source(), server)

0 commit comments

Comments
 (0)