def genaFile_cmdArrHeadersAndValsIntoListOfDicts( cmdArrayWidth, cmdArrayHeight ):

    cmdArray = genCmdArraySample( cmdArrayWidth, cmdArrayHeight )
    ## print("Function genCmdArraySample: ", cmdArray)

    cmdArrValDotTxt = open('cmdArrVals.txt', 'w')
    print()
    for  row in range(0, 55, 1):

        for column in range(0, 4, 1):
            strOut = "cmdArray[(" + str(column) + ", " + str(row) + ")] = " + '"' + cmdArray[(column, row)] + '"'
            print( strOut )
            strOut = "    cmdArray[(" + str(row) + ", " + str(column) + ")] = " + '"' + cmdArray[(column, row)] + '"'
            print(("    To" + strOut))
            cmdArrValDotTxt.write(strOut + '\n')

        print()
        cmdArrValDotTxt.write('\n')


    cmdArrValDotTxt.close()
    print()
    return
def genaFile_cmdArrValsDotTxt( cmdArrayWidth, cmdArrayHeight ):  # Gens txt file with some reversals

    cmdArray = genCmdArraySample( cmdArrayWidth, cmdArrayHeight )
    ## print("Function genCmdArraySample: ", cmdArray)

    cmdArrValDotTxt = open('cmdArrVals.txt', 'w')
    print()
    for  row in range(0, 55, 1):

        for column in range(0, 4, 1):
            strOut = "cmdArray[(" + str(column) + ", " + str(row) + ")] = " + '"' + cmdArray[(column, row)] + '"'
            print( strOut )
            strOut = "    cmdArray[(" + str(row) + ", " + str(column) + ")] = " + '"' + cmdArray[(column, row)] + '"'
            print(("    To" + strOut))
            cmdArrValDotTxt.write(strOut + '\n')

        print()
        cmdArrValDotTxt.write('\n')


    cmdArrValDotTxt.close()
    print()
    return " "
def genCmdArray():

    cmdArray = genCmdArraySample( 5, 99 )
    ## print("Function genCmdArraySample: ", cmdArray)

    ### cmdArrValDotTxt = open('cmdArrVals.txt', 'w')
    print()
    for  row in range(0, 98, 1):

        for column in range(0, 4, 1):

            strOut = "cmdArray[(" + str(column) + ", " + str(row) + ")] = " + '"' + cmdArray[(column, row)] + '"'
            print( strOut )
            
            
            #  cmdArrValDotTxt.write(strOut + '\n')

        print()
        #  cmdArrValDotTxt.write('\n')


    #  cmdArrValDotTxt.close()
    print()
    return cmdArray 
def line_by_line_term_interface(cmdArray):

    import getpass
    import subprocess

    out_bytes = subprocess.check_output(['ls'])
    print(out_bytes)

    stringPiecesDict = genStrVariables()   # stringPiecesDict

    line_choice = 1
    print("")
    print("0. Choose 0 to return to previous menu.")
    print("1. Choose 1 for use of upgrade commands from original default array.")
    print("2. Choose 2 for .")
    print("3. Choose 3 for .")
    print("4. Choose 4 for outputting default cmdArray list to csv file.")
    print("5. Choose 5 for gen a file cmdArrVals.txt.")
    print("6. Choose 6 for return to previous menu. ")
    print("7. Choose 7 for cmdArray screen print check. ")
    print("8. Choose 8 to write a sample record to a sample dB.")
    print("9. Choose 9 to READ a sample record FROM a sample dB.")
    print("10. Choose 10 to WRITE a sample record TO a sample dB.")

    line_choice = inputIntegerOnly("Which number do you want? ")
        # line_choice = int(line_choice)  
 
    cmdArrayWidth = 4 ; cmdArrayHeight = 100 ; 

    if line_choice <= 0:
        # out_bytes = "Return to previous menu is chosen. sys.exit() "
        # print(); print( out_bytes )
        # sys.exit()
        out_bytes = "User chose to return to previous menu. "
        print(); print( out_bytes )
        return cmdArray  ## menuInit(cmdArray)  ## 
    elif line_choice <= 1:
        # if line_choice <= 1:
        cmdArray = genCmdArraySample( cmdArrayWidth, cmdArrayHeight )
        # cmdArray = genCmdArraySample( 4, 100 )
        print(("Function genCmdArraySample: ", cmdArray))
        line_by_line_term_interface( cmdArray )
    elif line_choice <= 2:
        cmdArray = genCmdArraySample( cmdArrayWidth, cmdArrayHeight )
        print(("Function genCmdArraySample: ", cmdArray))
        line_by_line_term_interface( cmdArray )
    elif line_choice <= 3:
        cmdArray = genCmdArraySample( 4, 100 )
        print(("Function genCmdArraySample: ", cmdArray))
        line_by_line_term_interface( cmdArray )
    elif line_choice <= 4:
        out_bytes = genaFile_cmdArrValsDotTxt( cmdArrayWidth, cmdArrayHeight )
        print( out_bytes )
        line_by_line_term_interface( cmdArray )
    elif line_choice <= 5:
        out_bytes = genaFile_cmdArrValsDotTxt( cmdArrayWidth, cmdArrayHeight )
        print( out_bytes )
        line_by_line_term_interface( cmdArray )
    elif line_choice <= 6:
        out_bytes = "User chose to return to previous menu. "
        print(); print( out_bytes )
        return cmdArray  ## menuInit(cmdArray)  ## 
    elif line_choice <= 7:
        out_bytes = "User chose to run cmdArray screen printout. "
        print(); print( out_bytes )
        # sys.exit(main())
        out_bytes = screenPrintCmdArray(cmdArray)
        line_by_line_term_interface(cmdArray)
    elif line_choice <= 8:
        out_bytes = "User chose to write a sample record to a sample dB. "
        print(); print( out_bytes )
        # sys.exit(main())
        out_bytes = writeSmplRecordToPostgresDbTable()
        line_by_line_term_interface(cmdArray)
    elif line_choice <= 9:
        out_bytes = "User chose to READ a sample record FROm the sample dB. "
        print(); print( out_bytes )
        # sys.exit(main())
        out_bytes = readSmplRecordFromPostgresDbTable()
        line_by_line_term_interface(cmdArray)
    elif line_choice <= 10:
        out_bytes = "User chose to WRITE a sample record TO the sample dB. "
        print(); print( out_bytes )
        # sys.exit(main())
        out_bytes = writeRecordToPostgresDbTable(" ", " ", " ")
        line_by_line_term_interface(cmdArray)
    elif line_choice > 98:
        out_bytes = "User chose to exit this menu. "
        print(); print( out_bytes )
        return  # sys.exit(main())
    else:
        ### cmdArray = genCmdArraySample()
        ### print("Function genCmdArraySample: ", cmdArray)
        out_bytes = "Entry is out of range." # line_by_line_term_interface()
        print(); print( out_bytes )
        line_by_line_term_interface(cmdArray) ## sys.exit(main())

    return out_bytes

    print("")
    print("Need sudo password to install software.")

    user = getpass.getuser()
    userPassWd = getpass.getpass()

    print(user)
    # print(userPassWd)

    # out_bytes = subprocess.check_output(['apt-get ', 'update', shell=True])
    # cmdLine = ['echo ' + userPassWd + ' | sudo -S apt-get update']
    # cmdLine = "sudo apt-get update"
    # out_bytes = subprocess.Popen(cmdLine, shell=True, stdin=None, stdout=None, stderr=None, executable="/bin/bash")
    # out_bytes = subprocess.Popen(cmdLine , shell=True, stdin=None, stdout=open("/dev/null", "w"), stderr=None, executable="/bin/bash")
    # echo "yourpassword" | sudo -S apt-get autoremove
    # proc = subprocess.Popen('apt-get install -y filetoinstall', shell=True, stdin=None, stdout=open("/dev/null", "w"), stderr=None, executable="/bin/bash")
    # out_bytes = aptGetShellBash(cmdLine)
    out_bytes = repeatAptGetShellBash(userPassWd, cmdArray)

    return out_bytes