*********************************** pkg_py.txt (text) *********************************** #pkg_py.py stored in . . /Desktop/ix # by D@CC on 2023KNov04 #2024CMar07 was ix_pkg.py #tested with Script_Test_preParse_v00.py #tested with Test_readCD2.py #uses: getSub() # getSub_v0(parm1,q1,q2) These modules use Uses: GPIO.setmode() GPIO.setup() GPIO.output() sys.path.append() "/home/pi/Desktop/IX_assets/ix" getSub(parm1,q1,q2) replSub() def getSub(s1,s2,s3): #def end etSub(s1,s2,s3) #/getSub.py #::::::::::textpak=>getSub_v00.py #getSub_v00.py def getSub_v00(parm1,q1,q2): #By: D@CC #On: 2023LDec01 #Purpose: get subString BETWEEN columns q1 & q2 #status: works # get sub string from q1 to q2 sub=parm1[q1+1:q2] #def end #/getSub_v00.py #::::::::::textpak=>initCD2.py def initCD2(PPin): #def end initCD2(PPin) #::::::::::textpak=>ixTestB.py def ixTestB(s): #def end ixTestB.py #::::::::::textpak=>ixTestC.py def ixTestC(s): #def end ixTestC.py #::::::::::textpak=>preParse.py #preParse.py #def end #/preparse.py #::::::::::textpak=>preParse_v00.py #preParse_v00.py import sys sys.path.append("/home/pi/Desktop/IX_assets/ix") from ix_pkg import getSub from ix_pkg import replSub def preParse_v00(parm): #By D@CC #On 2023LDec01 #Purpose: to find pairs of ' or " # and replace each space (or spaces) in # each pair with &20 #parm1: cli str to preParse #Eg: any"any any"any"any any"any #Returns:any"any&20any"any"any&20any"any #Status: no fails by Test_preParse() #TestFile: Test_preParse_File.txt #print("at 35 parm1:"+parm1) parm1=parm #so we can change parm1 result=parm1 isAnyDQ=True if parm1.find('"')<0: isAnyDQ=False isAnySQ=True if parm1.find("'")<0: isAnySQ=False if isAnyDQ and isAnySQ: return parm1 if (not isAnyDQ) and (not isAnySQ): return parm1 if isAnyDQ or isAnySQ: for qStr in ('"',"'"): # search for both DQ and SQ q=qStr qCol= 0 cntQ =-1 #print("at 49 parm1:"+parm1) while qCol>-1 : #find next col containing q qCol =parm1.find(q,qCol+1) #count it (them) cntQ+=1 #print("55 qCol:",qCol) #while end #print("cntQ:",cntQ) modQ=cntQ%2 #print("modQ:",modQ) # if oldSub needs spaces replaced if oldSub.find(" ")>-1: #print("p 88 replacing spaces between pair") newSub=oldSub.replace(" ","&20") parm1=replSub(parm1,q1,q2,newSub) #print("p 91 new parm1:"+parm1) return result #def end #/preParse_v00.py #::::::::::textpak=>readCD2.py def readCD2(PPin): import RPi.GPIO as GPIO #By D@CC on 2023KNov01 #Purpose: to return True if both CDs are covered #HW: my device "CD2_Dongle(c)" #Tested with PPin=40 reading=GPIO.input(PPin) # reading is True if the CD photoCells are Dark # Make them dark by covering them with a finger if reading: state=False else: state=True #if end return state #def end readCD2(PPin) #::::::::::textpak=>replSub.py #replSub.py import sys sys.path.append("/home/pi/Desktop/IX_assets/ix") from ix_pkg import replSub_v00 def replSub(s1,s2,s3,s4): #By: D@CC #On: 2023LDec01 #print("calling replSub_v00()") return replSub_v00(s1,s2,s3,s4) #def end #replSub.py #::::::::::textpak=>replSub_v00.py #replSub_v00.py def replSub_v00(parm1,q1,q2,newSub): #By: D@CC #On: 2023LDec01 #Purpose: # sister func to getSub() # insert newSub BETWEEN cols q1 & q2 #q1,q2 are col numbers of a pair of '"' # replace sub string between q1 to q2 #pre = before sub pre=parm1[0:q1+1] #print("11 pre:"+pre) #post = after sub lenParm1=len(parm1) #print("lenParm1:",lenParm1) post=parm1[q2:lenParm1] #print("14 post:"+post) sub=parm1[q1+1:q2] #print("18 sub:"+sub) newSub=pre+newSub+post return newSub #def end #/replSub_v00.py #::::::::::textpak=>requires.py def requires(inStr,v=""): #by D@CC on 2023KNov04 # IX Software Family component #Purpose: tells prepIX how to deal with # required functions #Parm 1 "func(s,'v=1')" #Parm 2 tells prepIX what to do # v="" create a function pair # from pkg_py.py import func # from pkg_py.py import func_v01 # v="import" just import normally # from func import func # v="?" returns version # of requires # v=0,1,2 future #def end requires.py ******************************************************* #/pkg end pkg_py.txt stored in . . /Desktop/IX_assets/ix