#::::::::::textpak=>IX_textunpack.py #!/usr/local/bin/python # IX_textunpack_py.txt renamed to textunpack.py ################################################################## # place the IX_textunpack.py and the package into Desktop # # Usage: $> cd Desktop/IX # # $> python ../IX_textunpack.py <../IX_package_py_py.txt # # NB In terminal, the above should unpack the items from # # package into Desktop/IX # ################################################################## import sys # from textpack import marker # use common seperator key marker = '#' + ':'*10 + 'textpak=>' # IX Marker is different mlen = len(marker) # file names after markers for line in sys.stdin.readlines( ): # for all input lines markIn=line[0:20] if(line[:mlen]!= marker): lineLen=len(line) # doh! end="" doesn't suppress LF lineLess1=line[0:lineLen-1] print(lineLess1 ) # write real lines else: fileName=line[mlen:-1] sys.stdout = open(line[mlen:-1], 'w') # or make new output file #if end #for end #end IX_textunpack_py.txt # #::::::::::textpak=>IX_textselect.py #!/usr/local/bin/python # IX_textselect_py.txt renamed to IX_textselect.py # by D@CC on 2022CMar13 #################################################################### # place the IX_textselect.py and the package into Desktop # # Usage: $> cd Desktop/IX # # $> python ../IX_textselect.py f.py < ../IX_package_py.py # # NB In terminal, the above should unpack the item f.py from # # the package into Desktop/IX # #################################################################### import sys # from textpack import marker # use common seperator key but marker = '#' + ':'*10 + 'textpak=>' # the IX Marker is different mlen = len(marker) # file names appear after markers for name in sys.argv[1:]: # e.g. f.py # command arg should contain selected fileName filename=name # file name to select and get #for end bigMarker = marker + filename # marker to look for blen = len(bigMarker) # including filename if blen==mlen: # empty arg. print("ERROR021: empty selected filename arg.") exit() # give up on this request #if end isFileExists=False # remember if the file is found isInSelectedFile=False # ignore lines before/after the selected file isOpen=False for line in sys.stdin.readlines( ): # for all input lines markIn=line[0:blen] if(line[:mlen]!= marker): # is it a marker line #no it's NOT a marker line if isInSelectedFile : # not a marker, but the selected file was already found # this IS NOT a marker line isFileExists=True # the selected file had at least 1 record #write out this line of the selected file lineLen=len(line) # doh! end="" doesn't suppress LF lineLess1=line[0:lineLen-1] # workaround for python2 discard LF print(lineLess1 ) # write real lines #if end # ignore lines if the selected file has not been found else: # yes this IS a marker line if(line[:blen]== bigMarker): # does this mark the selected file isInSelectedFile=True # yes, remember its in the selected file #fileName=line[mlen:-1] # only get the requested file sys.stdout = open(filename, 'w') # open the new output file isOpen=True else: # its a marker but not the selected file marker # before or after the requested (selected) file # so ignore these next lines i.e. stop printing the lines isInSelectedFile=False # ignore lines before and after #if end #if end #for end if isFileExists==False: if isOpen==False: sys.stdout = open(filename, 'w') # open the new output file #if end print("ERROR022: Pkg did not yield:"+filename) #if end #end IX_textselect.py # #::::::::::textpak=>IX_textpack.py #!/usr/local/bin/python import sys # load the system module marker = '#' + ':'*10 + 'textpak=>' # hopefully unique separator def pack( ): for name in sys.argv[1:]: # for all command-line arguments input = open(name, 'r') # open the next input file print( marker + name) # write a separator line lineIn=input.read( ) # read the file's contents lineLen=len(lineIn) # doh!! end="" doesn't suppress the LF lineOut=lineIn[0:lineLen-1] print(lineOut) # and write the file's contents #for end if __name__ == '__main__': pack( ) # pack files listed on cmdline #def end textpack.py # this routine needs to be renamed to IX_package_py.py # end IX_txtpack.py # #::::::::::textpak=>IX_textnames.py #!/usr/local/bin/python # IX_textnames_py.txt renamed to IX_textnames.py # by D@CC on 2022CMar16 #################################################################### # place the IX_textnames.py and the package into Desktop # # Usage: $> cd Desktop/IX # # $> python3 ../IX_textnames.py < ../IX_package_py.py # # NB In terminal, the above should list the names of the # # files that exist in the package named in stdin. # #################################################################### import sys # from textpack import marker # use common separator key but marker = '#' + ':'*10 + 'textpak=>' # the IX Marker is different mlen = len(marker) # file names appear after markers print('#::: Be sure to precede the Pkg name with a "<".') if True: for line in sys.stdin.readlines( ): # for all input lines #print("before first line") #if line=="": break #if line==None: break markIn=line[0:mlen] if(line[:mlen]== marker): # is it a marker line llen=len(line) filename=line[mlen:llen-1] # get filename without LF print(filename) #if end #for end #if end print("#::: end of list of IX_textnames.py") #end IX_textnames.py # #::::::::::textpak=>IX_textadd.py # IX_textadd.py print('NB To add; use IX_textpack.py >> to "cat" to a Pkg') # end of IX_textadd.py # #::::::::::textpak=>IX_textnamesShowDefs.py #! /usr/bin/python3 # # !/usr/local/bin/python deprecated for Raspberry Pi # IX_textnamesShowDefs_py.txt renamed to IX_textnamesShowDefs.py # by D@CC on 2022CMar19 ##################################################################### # first line (shebang) must be #! /usr/bin/python3 # # place IX_textnamesShowDefs.py and the package adcRead_pkg.py # # into the Desktop folder # # # # Usage: >$ cd Desktop/IX # # >sudo chmod +x IX_textnamesShowDefs.py # # >$ python3 ../IX_textnamesShowDefs.py < ../adcRead_pkg.py # # or: >$ cd Desktop # # >$ ./IX_textnamesShowDefs.py < adcRead_pkg.py # # NB In terminal, the above should list the names of the # # files that exist in the package named in stdin. # # and the lines that contain "def " # # # # but due to the Unix trick line 1 "#!/usr... # # and the last line if __name__ ... # # the command line below works (afer chmod ...): # # >$ ./IX_textnamesShowDefs.py < adcRead_pkg.py # ##################################################################### import sys # from textpack import marker # use common separator key but marker = '#' + ':'*10 + 'textpak=>' # the IX Marker is different mlen = len(marker) # file names appear after markers def names(): print('#::: Be sure to precede the Pkg name with a "<".') print("#::: also reporting the def s") if True: for line in sys.stdin.readlines( ): # for all input lines #print("before first line") #if line=="": break #if line==None: break markIn=line[0:mlen] if(line[:mlen]== marker): # is it a marker line llen=len(line) filename=line[mlen:llen-1] # get filename without LF print(filename) else: #DC special if (line[0:1]=="#") : #DC ignore comment lines continueDoh=True #DC else: #DC if line.find("def ")==-1 : #DC special #not found #DC continueDoh=True #DC else: #DC #found def #DC if line.find("#def ")==-1 : #DC #not found #DC llen=len(line) #DC pline=" "+line[:llen-1] #DC #pline=line #DC print(pline) #DC special #if end #DC #if end #DC special #if end #for end print("#::: end of list by IX_textnamesShowDefs.py") #end def names() if __name__ == '__main__' : names( ) #end of IX_textnamesShowDefs.py