diff --git a/src/epics/util/post_build_script.py b/src/epics/util/post_build_script.py index ec0fd547cc72c5b1f625dc93cf38d2f72ea7e464..ba5235ac5abd20eb87c88f72a3a73abbc5e06492 100755 --- a/src/epics/util/post_build_script.py +++ b/src/epics/util/post_build_script.py @@ -22,6 +22,7 @@ else: ifo_initial = model_name[0:2] site_initial = model_name[0] +sysname = model_name[2:] global top_names top_names = None global model_params @@ -115,7 +116,7 @@ class Block: self.subblocks = [] #Parses a "block" of an .mdl file and returns the corresponding Block structure along with the last line number parsed -def parse_block(data_lines,line_number,reference_name): +def parse_block(data_lines,line_number,reference_name,system_name): new_block = Block() ###Normal, non-reference parsing if reference_name == None: @@ -125,14 +126,14 @@ def parse_block(data_lines,line_number,reference_name): current_line = data_lines[line_number] #We encounter a new block definition so start a new node if current_line.split()[-1].strip() == '{': - temp_block, line_number = parse_block(data_lines,line_number,None) + temp_block, line_number = parse_block(data_lines,line_number,None, system_name) #Check to see if we've found a reference block try: if (temp_block.data['BlockType'] == 'Reference') & (not (simulink_reference[0] in temp_block.data['SourceBlock'])) & (not (simulink_reference[1] in temp_block.data['SourceBlock'])): #If we did find a reference block, get the reference data current_name = temp_block.data['Name'] - library_lines = find_library(temp_block.data['SourceBlock']) - scratch_block, scratch = parse_block(library_lines,0,temp_block.data['SourceBlock']) + library_lines = find_library(temp_block.data['SourceBlock'], system_name) + scratch_block, scratch = parse_block(library_lines,0,temp_block.data['SourceBlock'], system_name) #Keep the farthest back reference description for screen generation as well - allows changes to just the library part if ('Description' in list(scratch_block.data.keys())): if not ('Reference_Descrip' in list(scratch_block.data.keys())): @@ -215,7 +216,7 @@ def parse_block(data_lines,line_number,reference_name): sys.stderr.write("Exiting\n") sys.exit(1) - new_block,scratch = parse_block(data_lines,current_line_count,None) + new_block,scratch = parse_block(data_lines,current_line_count,None, system_name) if description_present: new_block.data['Description'] = temp_description return new_block, scratch @@ -223,8 +224,10 @@ def parse_block(data_lines,line_number,reference_name): #This function goes and finds the location of part's corresponding library .mdl #It then returns all lines from the library .mdl file. -def find_library(library_name): +def find_library(library_name, system_name): reference_file_name = re.search('([^\/]*)',library_name).group(1).strip('"').strip('/') + if reference_file_name == '$bdroot': + reference_file_name = system_name #reference_file_name = re.search('(.*/(?!/))(.*)',library_name).group(1).strip('"').strip('/') for path in rcg_lib_path.split(':'): full_reference_path = path + '/' + reference_file_name + '.mdl' @@ -243,12 +246,12 @@ def find_library(library_name): sys.exit(1) #This function is the top level function which recursively goes through the mdl file -def parse_simulink_file(data_lines): +def parse_simulink_file(data_lines, system_name): line_number = 0 root = Block() root.data['MyBlockType'] = 'File' while (line_number < len(data_lines)-1): - temporary_block, line_number = parse_block(data_lines, line_number,None) + temporary_block, line_number = parse_block(data_lines, line_number,None, system_name) root.subblocks.append(temporary_block) return root @@ -442,7 +445,7 @@ mdl_data = mdl_file.readlines() mdl_file.close() #Begin parsing the model -root_block = parse_simulink_file(mdl_data) +root_block = parse_simulink_file(mdl_data,sysname) #Figure out DCU_ID #Find the cdsParameter block