def configDict(config_file): """ read in a configuration file and populate a dict structure of pin groups, pins, and ports :param config_file: :return: config_dict """ pin_expr = "\((?P<pin>\w+)\)" chan_expr = "(?P<chan>\w+|\([\,\d]+\))" id_expr = "\"?(?P<id>\w+)?\"?" operation_mode_expr = "(?P<op_mode>DFP[NS])" searchStr = "^\s*{op_mode}\s+{chan}\s*,\s*{id}\s*,\s*{pin}".format( op_mode=operation_mode_expr, chan=chan_expr, id=id_expr, pin=pin_expr) f = util.FileUtils(config_file, True) # read in config file. populate dict structure of pin groups, pins, and ports g = util.m_re(f.contents) g.grep("^DFP[NS]\s+(?:\w+|\([\,\d]+\)),\s*\"?\w*\"?,\(\w+\)") pin_list_dict = [re.search(searchStr, a_row) for a_row in g.lines] pin_list = [] pin_map_dict = {} for i, m in enumerate(pin_list_dict): try: a_dict = m.groupdict() map_keys = list(set(a_dict.iterkeys()) - {"pin"}) if a_dict["op_mode"] == "DFPN": pin_list.append(a_dict["pin"]) pin_map_dict[a_dict["pin"]] = dict([(k, a_dict[k]) for k in map_keys]) except AttributeError, e: print "Uh Oh, Error in building pin_list_dict, bailing out....\n{0}".format( e) raise
def parseMFH(mfh_file, reg_exp="", ref_keys=None): """ ref_keys :param mfh_file: is the file reference all the external files used to create the object in questions, such as levels :param reg_exp: is a search string regular expression with two keys: ref_type and ref_name :param ref_keys: are the reference types for the files referenced int the mfh file, i.e, EQNSET :return: ref_dict """ if ref_keys is None: ref_keys = [] base_path = os.path.dirname(mfh_file) f = util.FileUtils(mfh_file, True) ref_dict = {} chk_list = util.keep_in_list(f.contents, reg_exp) for a_line in chk_list: m = re.search(reg_exp, a_line) if m: m_dict = m.groupdict() if len(m_dict) > 0: ref_type, ref_name = m_dict["ref_type"], m_dict["ref_name"] if not ref_dict.has_key(ref_type): ref_dict[ref_type] = {} ref_dict[ref_type][ref_name] = os.path.join( base_path, re.sub("\s*#.*$", "", a_line.split(":")[-1]).strip()) return ref_dict
def determineSetups(testflow_file): """ get levels and timing file reference(s) from setups in testflow file :param testflow_file""" # testflow section fields tfSectionFields = [ "information", "declarations", "implicit_declarations", "flags", "testmethodparameters", "testmethodlimits", "testmethods", "test_suites", "bin_disconnect", "test_flow", "binning", "context", "hardware_bin_descriptions" ] contextDirDict = { "context_config_file": "configuration", "context_levels_file": "levels", "context_timing_file": "timing", "context_vector_file": "vectors", "context_analog_control_file": "analog_control", "context_routing_file": "routing", "context_testtable_file": "testtable", "context_channel_attrib_file": "ch_attributes" } testflowPath = os.path.dirname(testflow_file) devicePath = testflowPath.rpartition(os.path.sep)[0] f = util.FileUtils(testflow_file, True) setupIndex = util.find_index(f.contents, "^\s*setup\s*:\s*[\.\\/\w]+") setupsDict = {} if setupIndex > -1: setupFn = os.path.join(testflowPath, f.contents[setupIndex].split(":")[-1].strip()) f = util.FileUtils(setupFn, True) startPt = util.find_index(f.contents, "^\s*context\\b") stopPt = startPt + util.find_index(f.contents[startPt:], "^\s*end\\b") chkList = [ ",".join([aWord.strip() for aWord in aRow.strip().split("=") ]).replace(";", "").replace('"', '') for aRow in f.contents[startPt:stopPt] if util.in_string(aRow, "=") ] setupsDict = dict([tuple(aRow.split(",")) for aRow in chkList]) for k, v in setupsDict.iteritems(): setupsDict[k] = os.path.join(devicePath, contextDirDict[k], v) return setupsDict
import util import re import os dirPath = "/HDD1TB/qcom/jacob/q55xx/trunk/Q55xx" configFile = os.path.join(dirPath,"configuration", "Q55XX.cfg") f = util.FileUtils(configFile, True) # read in config file. populate dict structure of pin groups, pins, and ports g = util.m_re(f.contents) g.grep("^DFPN\s+\w+,\s*\"\w+\",\(\w+\)") pinListDict = [re.search("^DFPN\s+(?P<chan>\w+),\s*\"(?P<id>\w+)\",\s*\((?P<pin>\w+)\)", a_row) for a_row in g.lines] pinList = [m.groupdict()["pin"] for m in pinListDict if m] g.clear_cache() g.grep("^DFGP") chkList = [re.search("DFGP\s+\w+,\((?P<pins>[\w\,]+)\),\((?P<pin_group>\w+)\)", a_row) for a_row in g.lines] pinGroupDict = {} for m in chkList: if m: pinGroup, pins = m.groupdict()["pin_group"], m.groupdict()["pins"].split(",") if not pinGroupDict.has_key(pinGroup): pinGroupDict[pinGroup] = [] pinGroupDict[pinGroup] = list(set(pinGroupDict[pinGroup] + pins)) g.clear_cache() g.grep("^DFPT") chkList = [re.search("DFPT\s+\((?P<pins>[\w\,]+)\),\((?P<port>\w+)\)", a_row) for a_row in g.lines] portDict = {} for m in chkList: if m:
def getTiming(timing_file, spec_timing_groups, full_pin_list, pin_group_dict, ref_eqn_dict): """ ref_eqn_dict is a running copy of the ref_dict["EQN"] dictionary, and is treated as "read-only", with the sole purpose as a reference for the SPEC parameters that get determined in the ref_dict["SPS"] dictionary. """ ref_dict = {"EQN": {}, "SPS": {}, "WVT": {}} f = util.FileUtils(timing_file, True) g = util.m_re(f.contents) g.grep(spec_timing_groups["topLevel"]) # with timing, the eqnset is broken down into two sets: Equation(EQN) and Spec(SPS) start_pts, stop_pts = util.find_blocks(g.m_groups, spec_timing_groups["startClause"], spec_timing_groups["stopClause"]) for start, stop in zip(start_pts, stop_pts): contents = g.allLines[int(float(g.coordinates[start]) - 1):int(float(g.coordinates[stop]) - 1)] if util.in_string(g.lines[start], "EQN"): timing_key = "EQN" elif util.in_string(g.lines[start], "WVT"): timing_key = "WVT" break else: timing_key = "SPS" b = util.m_re(contents) b.grep(spec_timing_groups["SPS"]["SPECIFICATION"]) #----------------------------------------------------------------------------------------------------------- # rlogan .. 26apr2016 wrapped in try/catch to display offending code for OMAP5 FPC try: specName = re.sub("^\s*SPECIFICATION\s+\"|\"", "", b.m_groups[0]).strip() except KeyError: import sys sys.exit(contents) #----------------------------------------------------------------------------------------------------------- ref_dict["SPS"] = {specName: {"GLOBALS": {}}} timing_dict = spec_timing_groups[timing_key] b = util.m_re(contents) for remove_expr in timing_dict["remove"]: b.sub(remove_expr, "") contents = util.remove_from_list(contents, "^\s*$") b = util.m_re(contents) b.grep(timing_dict["topLevel"]) i_list = [int(float(a_num) - 1) for a_num in b.coordinates] if len(i_list) > 1: eqn_set_indices = [ (a, b) for a, b in zip(i_list, i_list[1:] + [len(contents)]) ] else: eqn_set_indices = [(i_list[0], len(contents))] if timing_key == "SPS": # let's check for globals _getTimingGlobalSpecVars( ref_dict[timing_key][specName]["GLOBALS"], contents[util.find_index(contents, "{") + 1:i_list[0]]) for (eq_start, eq_stop) in eqn_set_indices: eq_m = re.search( "^\s*EQNSET\s+(?P<eq_num>\d+)\s*\"?(?P<eq_name>[\w\s\-\.]+)?\"?", contents[eq_start]) eq_num, eq_name = -99, "" try: eq_dict = eq_m.groupdict() eq_num, eq_name = int(eq_dict["eq_num"]), eq_dict["eq_name"] except KeyError, e: if eq_num == -99: print "Uh Oh, we should always have an EQNSET number\n{0}".format( e) print "\n{0}".format(contents[eq_start]) raise else: pass # may not always have an equation set name if timing_key == "EQN": ref_dict[timing_key][eq_num] = { "eq_name": eq_name, "sub_sections": [] } _getTimingEqnSet(ref_dict[timing_key][eq_num], contents, eq_start, eq_stop, timing_dict, full_pin_list, pin_group_dict) elif timing_key == "SPS": ref_dict[timing_key][specName][eq_num] = {"name": eq_name} _getTimingSpsSet(ref_dict[timing_key][specName][eq_num], contents[eq_start:eq_stop], timing_dict, ref_eqn_dict[eq_num]["SPECS"].keys())
def getLevels(levels_file, spec_levels_groups, full_pin_list, pin_group_dict): """ Parse out levels objects, split into EQN and SPS sections for a dictionary :param levels_file: :param spec_levels_groups: :return: big levels dict, containing all info pertaining to equation sets, level sets, pins, etc.... """ f = util.FileUtils(levels_file, True) g = util.m_re(f.contents) g.grep(spec_levels_groups["topLevel"]) # with levels, the eqnset is broken down into two sets: Equation(EQN) and Spec(SPS) start_pts, stop_pts = util.find_blocks(g.m_groups, spec_levels_groups["startClause"], spec_levels_groups["stopClause"]) ref_dict = {"EQN": {}, "SPS": {}} for start, stop in zip(start_pts, stop_pts): contents = g.allLines[int(float(g.coordinates[start]) - 1):int(float(g.coordinates[stop]) - 1)] if util.in_string(g.lines[start], "EQN"): level_key = "EQN" else: level_key = "SPS" level_dict = spec_levels_groups[level_key] b = util.m_re(contents) for remove_expr in level_dict["remove"]: b.sub(remove_expr, "") contents = util.remove_from_list(contents, "^\s*$") b = util.m_re(contents) b.grep(level_dict["topLevel"]) i_list = [int(float(a_num) - 1) for a_num in b.coordinates] if len(i_list) > 1: eqn_set_indices = [ (a, b) for a, b in zip(i_list, i_list[1:] + [len(contents)]) ] else: eqn_set_indices = [(i_list[0], len(contents))] for (eq_start, eq_stop) in eqn_set_indices: eq_m = re.search( "^\s*EQNSET\s+(?P<eq_num>\d+)\s*\"?(?P<eq_name>[\w\s\-\.]+)?\"?", contents[eq_start]) eq_num, eq_name = -99, "" try: eq_dict = eq_m.groupdict() eq_num, eq_name = int(eq_dict["eq_num"]), eq_dict["eq_name"] except KeyError, e: if eq_num == -99: print "Uh Oh, we should always have an EQNSET number\n{0}".format( e) print "\n{0}".format(contents[eq_start]) raise else: pass # may not always have an equation set name ref_dict[level_key][eq_num] = { "eq_name": eq_name, "sub_sections": [] } if level_key == "EQN": _getLevelEqnSet(ref_dict[level_key][eq_num], contents, eq_start, eq_stop, level_dict, full_pin_list, pin_group_dict) elif level_key == "SPS": _getLevelSpsSet(ref_dict[level_key][eq_num], contents, eq_start, eq_stop, level_dict)