#buildMain_WioT_v01o01_2023EMay15_i.py def buildMain_WioT_v01o01_2023EMay15_i(): #By: D@CC #Date: 2023EMay15 #Purpose: To build (and copy) each main.py WioT program #Parms In: # parm1 str progName #Parms Out: # parm1 bool isSuccess True # #Issues: 1. the only name allowed by WioT is main.py # so use improvised programs ending in "_i.py" # 2. to save space on the WioT # this program will run in the RPi # this program will remove all comments # the function definitions will reside on the RPi # 3. When the uSD card works on the WioT, buildMain will run on the WioT # 4. Searches current folder and Desktop/ix/ for functions # #Version 01o01 tested OK # includes all functions requested by the statement: # request("strFunc(. . . )") # which is a function call [instead of "include"] #Eg # s="";T=True;i=0;v="0" # request("show(s,s,T,v="")" ) #syntax of v="" ????? # # (Initially the functions won't process the "v" correctly ) # Until they do . . . # Note 1 the definition of the function "show" will prepend the module built # Note 2 buildMain can include improvised functions programs (in future) # Note 3 a future version of buildMain will write out "request(show(s,s,T,v))" # by not copying the two '"' (before and after "show"). # Note 4 that v is the minimum version needed by this program eg "00" (future) # Note 5 each function will verify the version # if v is passed to it (future) # Note 6 each function will immediately return if v is passed to it (future) # Note 7 The author created a program that can list the functions it calls. #Abstract of buildMain program # Name of program to build is passed to buildMain # open the program to build # Open (for writing) the program to be built # for each record: # if a comment: ignore # else: # if it says "request(": # grep the name of the function # if not found: # strMsg = "not included" # insert strMsg in the request line # else # open the function file # for all records: # read record # if a comment: ignore # else: write out the record # write out the request line # else: # write out the record # close both # copy main.py to WioT # done #Calls # from pathlib import Path import datetime print("buildMain begins") strFolder="/home/pi/Desktop/ix/" isSuccess= True # two examples buildName="main" fName="show" # build in proto file must be in current folder In1=open(buildName+".pb","r") # allow 1 function in "home/pi/Desktop/request/" # build this file Build3=open(buildName+".py","w") # # for each rec in In1: for rec in In1: #rec=In1.readline() # first rec of proto file strRec=rec.strip() print("strRec:",strRec) str8=strRec[0:8] #print("str8:",str8) if str8=="request(": lenRec=len(strRec) #print("lenRec:",lenRec) strEnd=strRec[8:] #print("strEnd:",strEnd) posOpen=strEnd.find("(") print("posOpen:",posOpen) fName=strEnd[1:posOpen] print("fNam:",fName) pathedName=strFolder+fName+".py" pathTest=Path(pathedName) if pathTest.is_file(): #Build3.write("#"+rec) # print request rec as comment if fName=="request": Build3.write("#"+rec) # print request rec else: Build3.write(rec) # print request rec # insert the requested file F2=open(pathedName,"r") print("success open of F2") for recF in F2: testRecF=recF.strip() if not testRecF[0:1]=="#": Build3.write(recF) #for end Build3.write("\n") #insert LF if missing at end of function Build3.write("#def end "+fName+"\n") Build3.write("############################################\n") else: lenRecM2=len(rec)-2 errRec=rec[0:lenRecM2]+',"does NOT exist.")\n' print("errRec:",errRec) Build3.write(errRec) # print request rec Build3.write("############################################\n") #if end else: if not rec[0:1]=="#": #suppress comments (to save space) Build3.write(rec) #if end #rec=F2.readline() # first rec of func file #Build3.write(rec) Build3.write("\n") Build3.write("#"+buildName+".py (created by buildMain.py)\n") now=datetime.datetime.now() prettyDTime=now.strftime("%Y-%m-%d T %H:%M:%S") Build3.write("# on "+prettyDTime) In1.close() F2.close() Build3.close() #request("show(s,s,T,v)") #request("showX(s,s,T,v)","does not exist") return isSuccess #def end buildMain_WioT_v01o01_2023EMay15_i # main program starts here Doh=buildMain_WioT_v01o01_2023EMay15_i() print("end of program") #/buildMain_WioT_v01o01_2023EMay15.py #def end