def get_generic_scenario_config(scenario_config, add_vm_type=None): if add_vm_type is not None: config_path = os.path.join(current_app.config.get('CONFIG_PATH'), 'template') generic_scenario_config = XmlConfig(config_path) if os.path.isfile(os.path.join(config_path, add_vm_type + '.xml')): generic_scenario_config.set_curr(add_vm_type) return generic_scenario_config else: return None config_path = os.path.join(current_app.config.get('CONFIG_PATH'), 'generic') generic_scenario_config = XmlConfig(config_path) for file in os.listdir(config_path): if os.path.isfile(os.path.join(config_path, file)) and \ os.path.splitext(file)[1] == '.xml': generic_scenario_config.set_curr(os.path.splitext(file)[0]) generic_scenario_config_root = generic_scenario_config.get_curr_root( ) if 'scenario' in generic_scenario_config_root.attrib \ and 'uos_launcher' not in generic_scenario_config_root.attrib \ and generic_scenario_config_root.attrib['scenario'] == \ scenario_config.get_curr_root().attrib['scenario']: return generic_scenario_config return None
def get_board_config(board_info): """ get board config :param board_info: the board info file :return: the board type """ board_config = None if board_info is not None: board_config = XmlConfig(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'res')) board_config.set_curr(board_info) return board_config
def get_board_info_type(board_info): """ get board info type :param board_info: the board info file :return: the board type """ board_type = None if board_info is not None: board_info_config = XmlConfig(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'res')) board_info_config.set_curr(board_info) board_info_root = board_info_config.get_curr_root() if board_info_root and 'board' in board_info_root.attrib: board_type = board_info_root.attrib['board'] return board_type
def upload_launch(): """ upload scenario setting xml file :return: the upload status """ if request.method == 'POST': if 'file' not in request.files: return {'status': 'no file uploaded'} file = request.files['file'] if file and '.' in file.filename and file.filename.rsplit('.', 1)[1] in ['xml']: filename = secure_filename(file.filename) print(filename) launch_file_name = os.path.splitext(file.filename)[0] board_type = current_app.config.get('BOARD_TYPE') tmp_launch_name = 'tmp_' + launch_file_name + '.xml' tmp_launch_file = os.path.join(current_app.config.get('CONFIG_PATH'), board_type, 'user_defined', tmp_launch_name) if os.path.isfile(tmp_launch_file): os.remove(tmp_launch_file) file.save(tmp_launch_file) tmp_xml_config = XmlConfig(os.path.join(current_app.config.get('CONFIG_PATH'), board_type, 'user_defined')) tmp_xml_config.set_curr(tmp_launch_name[:-4]) status = None if tmp_xml_config.get_curr_root() is None: status = 'Error on parsing the scenario xml file, \n' \ 'check the xml syntax and config items.' else: tmp_root = tmp_xml_config.get_curr_root() if 'board' not in tmp_root.attrib or 'scenario' not in tmp_root.attrib \ or 'uos_launcher' not in tmp_root.attrib: status = 'Invalid launch xml file, \nboard, scenario,' \ 'and uos_launcher need to be configured.' elif tmp_root.attrib['board'] != current_app.config.get('BOARD_TYPE'): status = 'Current board: {} mismatched with the board in the launch file,' \ '\nplease reselect or upload the board info: {}' \ .format(current_app.config.get('BOARD_TYPE'), tmp_root.attrib['board']) if status is not None: if os.path.isfile(tmp_launch_file): os.remove(tmp_launch_file) return {'status': status} error_list = {} new_launch_name = launch_file_name rename = False if not error_list: new_launch_path = os.path.join(current_app.config.get('CONFIG_PATH'), board_type, 'user_defined', launch_file_name + '.xml') if os.path.isfile(new_launch_path): new_launch_name = new_launch_name + '_' + \ datetime.now().strftime('%Y%m%d%H%M%S') rename = True os.rename(tmp_launch_file, os.path.join(current_app.config.get('CONFIG_PATH'), board_type, 'user_defined', new_launch_name + '.xml')) return {'status': 'success', 'file_name': new_launch_name, 'rename': rename, 'error_list': error_list} return {'status': 'unsupported method'}
def upload_board_info(): """ upload board info xml file :return: the upload status """ if request.method == 'POST': if 'file' not in request.files: return {'status': 'Error: no file uploaded'} file = request.files['file'] if file and '.' in file.filename and file.filename.rsplit('.', 1)[1] in ['xml']: filename = secure_filename(file.filename) tmp_filename = 'tmp_' + filename save_tmp_board_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'res', tmp_filename) file.save(save_tmp_board_path) board_type_list = [] config_path = current_app.config.get('CONFIG_PATH') for config_name in os.listdir(config_path): if os.path.isdir(os.path.join(config_path, config_name)) \ and config_name != 'generic': board_type_list.append(config_name) res_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'res') if not os.path.isdir(res_path): os.makedirs(res_path) board_info_config = XmlConfig(res_path) board_info_config.set_curr(tmp_filename.rsplit('.', 1)[0]) board_info_root = board_info_config.get_curr_root() board_type = None if board_info_root and 'board' in board_info_root.attrib \ and 'scenario' not in board_info_root.attrib \ and 'uos_launcher' not in board_info_root.attrib: board_type = board_info_root.attrib['board'] if not board_type: os.remove(save_tmp_board_path) return {'status': 'Error on parsing Board info\n' 'check the xml syntax and whether there is only the board ' 'attribute in the board info file'} os.rename(save_tmp_board_path, os.path.join(os.path.dirname(os.path.abspath(__file__)), 'res', filename)) info = 'updated' if board_type not in board_type_list: info = board_type os.makedirs(os.path.join(config_path, board_type)) for generic_name in os.listdir(os.path.join(config_path, 'generic')): generic_file = os.path.join(config_path, 'generic', generic_name) if os.path.isfile(generic_file): new_file = os.path.join(config_path, board_type, generic_name) copyfile(generic_file, new_file) xml_config = XmlConfig(os.path.join(current_app.config.get('CONFIG_PATH'), board_type)) xml_config.set_curr(generic_name[:-4]) xml_config.set_curr_attr('board', board_type) xml_config.save(generic_name[:-4], user_defined=False) board_info = os.path.splitext(file.filename)[0] current_app.config.update(BOARD_INFO=board_info) current_app.config.update(BOARD_TYPE=board_type) return {'status': 'success', 'info': info} return {'status': 'Error: upload failed'}
def upload_board_info(): """ upload board info xml file :return: the upload status """ if request.method == 'POST': if 'file' not in request.files: return {'status': 'Error: no file uploaded'} file = request.files['file'] if file and '.' in file.filename and file.filename.rsplit('.', 1)[1] in ['xml']: filename = secure_filename(file.filename) tmp_filename = 'tmp_' + filename save_tmp_board_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'res', tmp_filename) file.save(save_tmp_board_path) board_type_list = [] config_path = current_app.config.get('CONFIG_PATH') for config_name in os.listdir(config_path): if os.path.isdir(os.path.join(config_path, config_name)) \ and config_name != 'generic': board_type_list.append(config_name) res_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'res') if not os.path.isdir(res_path): os.makedirs(res_path) board_info_config = XmlConfig(res_path) board_info_config.set_curr(tmp_filename.rsplit('.', 1)[0]) board_info_root = board_info_config.get_curr_root() board_type = None if board_info_root and 'board' in board_info_root.attrib \ and 'scenario' not in board_info_root.attrib \ and 'uos_launcher' not in board_info_root.attrib: board_type = board_info_root.attrib['board'] if not board_type: os.remove(save_tmp_board_path) return {'status': 'Error on parsing Board info\n' 'check the xml syntax and whether there is only the board ' 'attribute in the board info file'} os.rename(save_tmp_board_path, os.path.join(os.path.dirname(os.path.abspath(__file__)), 'res', filename)) info = 'updated' if board_type not in board_type_list: info = board_type os.makedirs(os.path.join(config_path, board_type)) for generic_name in os.listdir(os.path.join(config_path, 'generic')): generic_file = os.path.join(config_path, 'generic', generic_name) if os.path.isfile(generic_file): new_file = os.path.join(config_path, board_type, generic_name) copyfile(generic_file, new_file) xml_config = XmlConfig(os.path.join(current_app.config.get('CONFIG_PATH'), board_type)) xml_config.set_curr(generic_name.rsplit('.', 1)[0]) xml_config.set_curr_attr('board', board_type) # update RDT->CLOS_MASK according to board xml xml_config_root = xml_config.get_curr_root() if 'board' in xml_config_root.attrib and 'scenario' in xml_config_root.attrib \ and 'uos_launcher' not in xml_config_root.attrib: cdp_enabled = xml_config.get_curr_value('hv', 'FEATURES', 'RDT', 'CDP_ENABLED') (num_clos_mask, num_mba_delay) = \ get_num_of_rdt_res(filename.rsplit('.', 1)[0], cdp_enabled) elem_clos_max = xml_config.get_curr_elem('hv', 'FEATURES', 'RDT', 'CLOS_MASK') elem_mba_delay = xml_config.get_curr_elem('hv', 'FEATURES', 'RDT', 'MBA_DELAY') xml_config.delete_curr_elem('hv', 'FEATURES', 'RDT', 'CLOS_MASK') xml_config.delete_curr_elem('hv', 'FEATURES', 'RDT', 'MBA_DELAY') for i in range(num_clos_mask): xml_config.clone_curr_elem(elem_clos_max, 'hv', 'FEATURES', 'RDT') for i in range(num_mba_delay): xml_config.clone_curr_elem(elem_mba_delay, 'hv', 'FEATURES', 'RDT') xml_config.save(generic_name.rsplit('.', 1)[0], user_defined=False) board_info = os.path.splitext(file.filename)[0] current_app.config.update(BOARD_INFO=board_info) current_app.config.update(BOARD_TYPE=board_type) return {'status': 'success', 'info': info} return {'status': 'Error: upload failed'}