def FRUM(pkgIn,moduleIn,name2In): #by D@CC #on 2024DApr06 #Name: FRUM_py.py #Usage: Main function in IXf #Purpose: FRUM returns Python statements as a Python list # appended to parm0 #parm0: source can be # "" current folder # "=" statements in string in module # "s" sPkg_py.py in stub in Desktop/IX_assets/ix/ #parm1: module name from source # or module str itself if parm0 is "=" #parm2: usually "" (in future will be name2") #uses: commandOS #imports os #v0 only Test "=" meaning literal statement #Eg call v=FRUM(v,"=","###","") #Eg call v=FRUM(v,"buIX","grep","") #any entity is the target in buIX #Eg call v=FRUM(v,"grep","eDict","") #any entity is the target in eDict # #process "=" which is a literal Python statement import os module=moduleIn typeM=type(moduleIn) print(typeM) vList="### de IXf" if pkgIn=="=": if isinstance(module,str): vList=module+"\n" else: pass #if end L.append(vList) #cannot return L.append(vList) typeL=type(L) #print("@40 returning typeL:",typeL) #print("L:",L,":") resultList=L if isinstance(resultList,str): # force resultList to be a List resultList=[resultList] #if end L=L + resultList # result must be a list return L #if end #print("@57 vList:",vList) isGrep=False #process "bu" "grep" if pkgIn=="bu" and moduleIn=="grep": isGrep=True if isGrep: cmd="grep "; file=" /home/pi/buIX/*.*" if pkgIn=="grep" and moduleIn!="": # should grep the file (in moduleIn) searching for "=" isGrep=True # grep strTarget="=" cmd="grep "; file=" /home/pi/Desktop/a/sandBox/"+moduleIn #if end if isGrep: #print("@72") #grep an entity name (defined by the regular expression below) # followed by "=" strTarget = '"[y]*"' strTarget = '"[[:alnum:]]*"' strTarget = '"[&]"' strTarget = '"[&][[:alnum:]]*"' strTarget = '"[&][[:alnum:]]*[|]"' strTarget = '"[&][a-z][[:alnum:]]*[|]"' strTarget = '"[&][a-z][[:alnum:]]*[|][=]"' strTarget = '"[&][a-z][[:alnum:]]*[|][ ][=]"' strTarget = '"[&][a-z][[:alnum:]]*[|][ ]*[=]"' strTarget = '"[&][a-z][[:alnum:]]*[|][ ]*[=]"' #strTarget = '"[&][a-z][[:alnum:]]* [|][ ]*[=]"' strTarget = '"[&][a-z][[:alnum:]]*\|[_]*[|][ ]*[=]"' # 1 11 112 21 1 1 1 11 1 1 1 #strTarget is & + lower-case + chars + | + spaces + = # where alnum are any alphanumeric characters: a-zA-Z0-9 # where chars is any number of alphanumeric or "_" even 0 # where spaces is any number of spaces even 0 # note the first | is escaped to be the "or" operator # the second | is the "|" character # examples are # "&b|=" "&c23B_4def|=" "&d| =" #strTarget = ' "=" ' if True: #print("@101") #if strTarget is the end of an entity name followed by "|=" # grep the file in ix_eDict #result=commandOS(cmd+strTarget+file) #file=" /home/pi/Desktop/IX_assets/ix/ix_eDict.txt" resultName="/home/pi/Desktop/IX_assets/ix/result.py" file=" /home/pi/buIX/*.* >"+resultName #file=" /home/pi/Desktop/IX_assets/ix/mPkg_py.pyix >"+resultName #file=" /home/pi/Desktop/IX_assets/ix/ePkg_py.pyix" #print("@109 system:"+cmd+strTarget+file) os.system(cmd+strTarget+file) #get result from file named resultName resultF=open(resultName,"r") result=resultF.readlines() #result="nope" #print("@115 result:",result) #strTarget="home/pi/Desktop/IX_assets/ix_eDict" #result=result+commandOS(cmd+strTarget) #if end #print("@119") #print("@120 result:",result) #print("@121 L:",L) resultList=result if isinstance(resultList,str): # force resultList to be a List resultList=[resultList] #if end L=resultList #print("@127 L:",L) return L #if end #return L #def end FRUM def FRUM_testA(): progName="FRUM_testA" print("@134 progName:"+progName) while True: print() print('@137 eg: wo double quotes "="',"print('b')",'""') pkgIn=input("pkg:?") moduleIn=input("module:?") field3=input("field3:?") #print("field3:"+field3+":") v=[] #Note FRUM must return a Python list not a str v=v+FRUM(pkgIn,moduleIn,field3) #v=FRUM(v,pkgIn,moduleIn,field3) #v=FRUM(v,"grep","ePkg_py.pyix","=") print("@147 v:",v) #while end return def FRUM_testB(): progName="FRUM_testA" print("@155 progName:"+progName) print('testing FRUM with "="') v=[] # create empty list in v # FRUM will append the module to the list "v" v= v+FRUM("=",'print("first pgm using FRUM()")\n',"") v= v+FRUM("=",'print("line 1")\n',"" ) str='print("line2\n'+ \ 'line 3 end\n'+ \ '")' v= v+FRUM("=",str,"") v= v+FRUM("=","#end of vList in FRUM_testA\n","") print("@168 v:",v) #next, output v to a file #then, send it through python #then, python will automatically run it #end of FRUM_testA #def end FRUM_testA() if __name__ == "__main__" : FRUM_testA() #/FRUM.py