def pyF1GetWait(exprNd): ''' extract a wait from Expr node - adds node to model, tags ast node as valid, and returns True on match ''' if type(exprNd) is not ast.Expr: return False callNd = exprNd.value if type(callNd) is not ast.Call: return False callStr = __class__.getSourceString(callNd) pat = re.compile('time.sleep\\((\\w+)') mat = pat.match(callStr) if mat: varstr = mat.group(1) #print("....found wait, var=" + varstr) intvar = Cm.CfgNumDataType(varstr) if intvar.isValid(): # TODO allow a var here also intvar.val *= 1000 # convert time.sleep value to ms Cm.CfgWaitNode(intvar, exprNd) exprNd.__cfg_valid__ = True # tag this ast node as translated return True return False
def pyF1ToCfgData(pyNd): ''' convert a py node to appropriate config model data type - returns None on no match form match is checked in following order: int, path w/ read, path only ''' s = __class__.getSourceString(pyNd) # convert py node to a string data = Cm.CfgNumDataType(s) # try converting to int if data.isValid(): return data hstr = __class__.getHierString(s) if hstr: path = Cm.CfgPathDataType(hstr) # try converting to path if path.isValid(): if path.hasCall(): if path.call == '__get__': path.setField() return Cm.CfgReadNode(path, pyNd) if path.call == '__read__': path.setReg() return Cm.CfgReadNode(path, pyNd) print('invalid call in strToCfgDataType path.val=' + path.val + ', path.call=' + path.call) return None # invalid call found else: return path return None