From e775db23b101976c4acdcdd8d011781cafb55ce1 Mon Sep 17 00:00:00 2001 From: Shuang Zheng Date: Thu, 22 Jul 2021 19:30:00 +0800 Subject: [PATCH] config_tools: add interface to save config xmls to user defined path in config editor add interface to save scenario xmls and launch xmls to user defined path in config editor; move all config xmls and generated scripts out of acrn-hypervisor. Tracked-On: #6208 Signed-off-by: Shuang Zheng Reviewed-by: Victor Sun --- misc/config_tools/config_app/configs.py | 7 +- misc/config_tools/config_app/controller.py | 2 +- misc/config_tools/config_app/static/main.js | 60 ++-- .../config_app/templates/base.html | 4 +- .../config_app/templates/launch.html | 8 +- .../config_app/templates/scenario.html | 10 +- misc/config_tools/config_app/views.py | 267 ++++++++++-------- 7 files changed, 207 insertions(+), 151 deletions(-) diff --git a/misc/config_tools/config_app/configs.py b/misc/config_tools/config_app/configs.py index e823c4b1c..0af8cf192 100644 --- a/misc/config_tools/config_app/configs.py +++ b/misc/config_tools/config_app/configs.py @@ -10,4 +10,9 @@ import os BOARD_INFO = None BOARD_TYPE = None SCENARIO = None -CONFIG_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'data') +LAUNCH = None +DEFAULT_CONFIG_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'data') +CONFIG_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..', '..', '..', 'user_config') + +if not os.path.isdir(CONFIG_PATH): + os.makedirs(CONFIG_PATH) diff --git a/misc/config_tools/config_app/controller.py b/misc/config_tools/config_app/controller.py index 6c7fbb50b..a4d5b4cb6 100644 --- a/misc/config_tools/config_app/controller.py +++ b/misc/config_tools/config_app/controller.py @@ -313,7 +313,7 @@ class XmlConfig: raise Exception('can not find node by {} from xml'.format(args)) - def save(self, xml=None, user_defined=True): + def save(self, xml=None, user_defined=False): """ save current xml to file. :param xml: the file name to save; if not specified, save current xml to default names. diff --git a/misc/config_tools/config_app/static/main.js b/misc/config_tools/config_app/static/main.js index eec8b2309..30402d2a6 100644 --- a/misc/config_tools/config_app/static/main.js +++ b/misc/config_tools/config_app/static/main.js @@ -265,7 +265,6 @@ $().ready(function(){ $('#export_scenario_xml').on('click', function() { var dataId = $(this).data('id'); $("#save_scenario").data('id', dataId); - $('#src_path_row').addClass('hidden'); }); $('#generate_config_src').on('click', function() { @@ -277,7 +276,6 @@ $().ready(function(){ $('#export_launch_xml').on('click', function() { var dataId = $(this).data('id'); $("#save_launch").data('id', dataId); - $('#src_path_row').addClass('hidden'); }); @@ -777,6 +775,7 @@ function create_setting(type, default_name, name, mode){ type: type, default_name: default_name, create_name: name, + src_path: '', mode: mode } @@ -789,10 +788,10 @@ function create_setting(type, default_name, name, mode){ exist = result.exist create_flag = true if(exist == "yes") { - overwirte_confirm_message = 'Setting name: ' + create_config['create_name'] + ' existed in ' + - 'acrn-hypervisor/misc/config_tools/data/'+board_info+'/user_defined/.\n'+ + overwrite_confirm_message = 'Setting name: ' + create_config['create_name'] + ' existed in ' + + 'acrn-hypervisor/../user_config/'+board_info+'/.\n'+ 'Do you want to overwrite it?\nClick OK to overwrite it; click Cancel to rename it.' - if(!confirm(overwirte_confirm_message)) { + if(!confirm(overwrite_confirm_message)) { create_flag = false } } @@ -870,8 +869,7 @@ function save_scenario(generator=null){ scenario_config[id] = [value]; } } else if(id!='new_scenario_name' && id!='new_scenario_name2' && id!='board_info_file' && id!='board_info_upload' - && id!='scenario_file' && id!='create_name' && id!='load_scenario_name2' && id!='load_launch_name2' - && id!='src_path') { + && id!='scenario_file' && id!='create_name' && id!='load_scenario_name2' && id!='load_launch_name2') { scenario_config[id] = value; } }) @@ -905,10 +903,10 @@ function save_scenario(generator=null){ exist = result.exist create_flag = true if(exist == "yes") { - overwirte_confirm_message = 'Setting name: ' + scenario_config['create_name'] + ' existed in ' + - 'acrn-hypervisor/misc/config_tools/data/'+board_info+'/user_defined/.\n'+ + overwrite_confirm_message = 'Setting name: ' + ' existed in current setting ' + + 'acrn-hypervisor/../user_config/'+board_info+'/.\n'+ 'Do you want to overwrite it?\nClick OK to overwrite it; click Cancel to rename it.' - if(!confirm(overwirte_confirm_message)) { + if(!confirm(overwrite_confirm_message)) { create_flag = false } } @@ -929,21 +927,26 @@ function save_scenario(generator=null){ $("#"+index+"_err").text(item); }) if(no_err == true && status == 'success') { + var src_path = $("input#src_path").val(); + if(src_path == null || src_path == '') { + xml_path = 'acrn-hypervisor/../user_config/'+board_info+'/.' + } else { + xml_path = src_path + } file_name = result.file_name; validate_message = 'Scenario setting saved successfully with name: ' - +file_name+'\ninto acrn-hypervisor/misc/config_tools/data/'+board_info+'/user_defined/.' + +file_name+'\ninto '+xml_path; if(result.rename==true) { validate_message = 'Scenario setting existed, saved successfully with a new name: ' - +file_name+'\ninto acrn-hypervisor/misc/config_tools/data/'+board_info+'/user_defined/.'; + +file_name+'\ninto acrn-hypervisor/../user_config/'+board_info+'/.'; } if(generator=="generate_config_src") { - var src_path = $("input#src_path").val(); generate_flag = true; if(src_path == null || src_path == '') { - overwirte_confirm_message = 'The Source Path for configuration files is not set.\n' + + overwrite_confirm_message = 'The Source Path for configuration files is not set.\n' + 'Do you want to generate them into the default path: acrn-hypervisor/build/hypervisor/configs/board/ and acrn-hypervisor/build/hypervisor/configs/scenarios/,\n'+ 'and overwrite the old ones?\nClick OK to overwrite them; click Cancel to edit the Source Path.' - if(!confirm(overwirte_confirm_message)) { + if(!confirm(overwrite_confirm_message)) { generate_flag = false } } @@ -1043,8 +1046,7 @@ function save_launch(generator=null) { launch_config[id] = [value]; } } else if(id!='new_launch_name' && id!='new_launch_name2' && id!='board_info_file' && id!='board_info_upload' - && id!="launch_file" && id!='create_name' && id!='load_scenario_name2' && id!='load_launch_name2' - && id!='src_path') { + && id!="launch_file" && id!='create_name' && id!='load_scenario_name2' && id!='load_launch_name2') { launch_config[id] = value; } }) @@ -1079,10 +1081,9 @@ function save_launch(generator=null) { exist = result.exist create_flag = true if(exist == "yes") { - overwirte_confirm_message = 'Setting name: ' + launch_config['create_name'] + ' existed in ' + - 'acrn-hypervisor/misc/config_tools/data/'+board_info+'/user_defined/.\n'+ + overwrite_confirm_message = 'Setting name: existed in the XML path\n'+ 'Do you want to overwrite it?\nClick OK to overwrite it; click Cancel to rename it.' - if(!confirm(overwirte_confirm_message)) { + if(!confirm(overwrite_confirm_message)) { create_flag = false } } @@ -1105,21 +1106,26 @@ function save_launch(generator=null) { $("#"+index+"_err").text(item); }) if(no_err == true && status == 'success') { + var src_path = $("input#src_path").val(); + if(src_path == null || src_path == '') { + xml_path = 'acrn-hypervisor/../user_config/'+board_info+'/.' + } else { + xml_path = src_path + } file_name = result.file_name; validate_message = 'Launch setting saved successfully with name: ' - +file_name+'\nto acrn-hypervisor/misc/config_tools/data/'+board_info+'/user_defined/.' + +file_name+'\nto '+xml_path; if(result.rename==true) { validate_message = 'Launch setting existed, saved successfully with a new name: ' - +file_name+'\nto acrn-hypervisor/misc/config_tools/data/'+board_info+'/user_defined/.'; + +file_name+'\nto '+xml_path; } if(generator == 'generate_launch_script') { - var src_path = $("input#src_path").val(); generate_flag = true; if(src_path == null || src_path == '') { - overwirte_confirm_message = 'The Source Path for launch scripts is not set.\n' + - 'Do you want to generate them into the default path: misc/config_tools/data/'+board_info+'/output/,\n'+ + overwrite_confirm_message = 'The Source Path for launch scripts is not set.\n' + + 'Do you want to generate them into the default path: acrn-hypervisor/../user_config/'+board_info+'/output/,\n'+ 'and overwrite the old ones?\nClick OK to overwrite them; click Cancel to edit the Source Path.' - if(!confirm(overwirte_confirm_message)) { + if(!confirm(overwrite_confirm_message)) { generate_flag = false } } @@ -1144,7 +1150,7 @@ function save_launch(generator=null) { if (status == 'success' && (JSON.stringify(error_list)=='{}' || JSON.stringify(error_list)=='null')) { if(src_path==null || src_path==='') { alert(generator+' successfully into '+ - 'acrn-hypervisor/misc/config_tools/data/'+board_info+'/output/.'); + 'acrn-hypervisor/../user_config'+board_info+'/output/.'); } else { alert(generator+' successfully into '+src_path); } diff --git a/misc/config_tools/config_app/templates/base.html b/misc/config_tools/config_app/templates/base.html index 69004bb9d..266336832 100644 --- a/misc/config_tools/config_app/templates/base.html +++ b/misc/config_tools/config_app/templates/base.html @@ -123,7 +123,7 @@ Scenario Setting