Advertisement
Guest User

Untitled

a guest
May 27th, 2016
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 60.52 KB | None | 0 0
  1. # Test Ip's below   #
  2. #
  3. #   10.45.4.141
  4. #   10.45.4.192
  5. #   10.45.4.93
  6. #####################
  7. #
  8. #   Add later
  9. #  If value is blank when it goes to display it
  10. #   point out in log that the value is empty
  11. #####################
  12.  
  13.  
  14. import errno
  15. import os
  16. import os.path
  17. import sys
  18. import cmd
  19. import paramiko
  20. import msvcrt as m
  21. import time
  22. import logging
  23. import subprocess
  24. import smtplib
  25. import sys
  26. from email.mime.multipart import MIMEMultipart
  27. from email.mime.text import MIMEText
  28. from email.mime.application import MIMEApplication
  29. from PIL import Image, ImageFilter
  30.  
  31. global username, password, port, host, SERIAL, Version_, _WorkDir_, source, destination, UtilHome
  32. password = "#############################
  33. username = ##################################
  34. port = 22
  35. host = ''#
  36. Version_ = ''
  37. Version_App = ''
  38. Version_System = ''
  39. SERIAL = ''
  40. source = 'SoftwareUpgrade'
  41. destination = '/tmp/updatesw/'
  42. UtilHome = os.getcwd()
  43.  
  44. # Generic Log file line use
  45. # logging.info('[' + time.strftime("%H:%M") + ']|> ')
  46.  
  47. #####################################
  48. #                                   #
  49. #     -Defining Functions-          #
  50. #                                   #
  51. #####################################
  52.  
  53. def PrintBox(message):
  54.    print('\n__________________________________\n')
  55.    print(' ' + message)
  56.    print('\n__________________________________\n')
  57.  
  58. def Log(message):
  59.    logging.info(' _____________[' + time.strftime("%H:%M") + ']___________')
  60.    logging.info(']|> ' + message)
  61.    logging.info(' ____________________________________________________________\n')
  62. #    logging.info('\n')
  63.  
  64. def FindType(TYPE):
  65.    Log(TYPE + ' is ' + type(TYPE))
  66.  
  67.  
  68. def CreateOSFolder(Folders):
  69.    for elem in Folders:
  70.        if not os.path.exists(elem):
  71.            logging.info('[' + time.strftime("%H:%M") + ']|> creating ' + elem)
  72.            os.mkdir(elem)
  73. def Clear():
  74.    Log('Running Clear()...')
  75.    os.system(['clear','cls'][os.name == 'nt'])
  76.  
  77. def wait():
  78.    Log('waiting...')
  79.    print('\n Press any key to continue..')
  80.    m.getch()
  81.    Clear()
  82.  
  83.  
  84. def HomeFolder():
  85.    # May go away with use of UtilHome
  86.    Log('moving to homefolder')
  87.    os.chdir(UtilHome)
  88.    Log('current Folder : ' + UtilHome)
  89.  
  90. def PrintDirs():
  91.    Log('Current OSdir - ' + os.getcwd() +
  92.        '\n Current SFTPdir ' + sftp.getcwd() + '\n Current UtilHome : ' + UtilHome)
  93.  
  94. def ClearHost():
  95.    Log('cleaning host information..')
  96.    global host, SERIAL, Version_App, Version_System
  97.    host = ''
  98.    SERIAL = ''
  99.    Version_App = ''
  100.    Version_System = ''
  101.    filepath = ''
  102.  
  103. def Reboot():
  104.    global host, SERIAL, Version_App, Version_System
  105.    Log('Rebooting..')
  106.    PrintBox('Please press any button\n   to reboot Nexgen')
  107.    m.getch()
  108.    cmd = 'reboot'
  109.    stdin, stdout, stderr = ssh.exec_command(cmd)
  110.    _reboot = stdout.read().strip().decode(encoding='utf-8')
  111.    stdin, stdout, stderr = ssh.exec_command('cmd')
  112.    ClearHost()
  113.    Clear()
  114.  
  115. def TestPing():
  116.    Log('entered test ping()....')
  117.    global host
  118.    print('contacting ' + host + ' ...')
  119.    Log('contacting ' +  host)
  120.    ping_result = subprocess.Popen(["ping.exe",host],stdout = subprocess.PIPE).communicate()[0]
  121.    if (b'unreachable' in ping_result):
  122.        Log('host unreachable')
  123.        print('\nHost unreachable, please try again')
  124.        wait()
  125.        GetHost()
  126.    elif (b'timed out.' in ping_result):
  127.        Log('host unreachable')
  128.        PrintBox('connection timed out, please try again')
  129.        wait()
  130.        Clear()
  131.        GetHost()
  132.    elif (b'failed' in ping_result):
  133.        Log('host unreachable')
  134.        PrintBox('ping failed, please try again')
  135.        wait()
  136.        Clear()
  137.        GetHost()
  138.    else:
  139.        Log('host online!')
  140.        PrintBox('host online')
  141.        ConnectSSH()
  142.  
  143. def GetHost():
  144.    HomeFolder()
  145.    global host
  146.    host = input('\nPlease Enter IP Address: ')
  147.    print('The IP Address has been changed to : ' + host + '\n')
  148.    Log('               > Entered GetHost() \n host : ' + host)
  149.    TestPing()
  150.    Clear()
  151.  
  152. def CheckSSH():
  153.    Clear()
  154.    Log('checking for host from CheckSSH')
  155.    if host == '':
  156.        logging.info('no host found, asking for host IP')
  157.        PrintBox('Need IP Address First!')
  158.        GetHost()
  159.  
  160. def KillAll():
  161.    Log('entered KillAll()...')
  162.    CheckSSH()
  163.    Clear()
  164.    PrintBox('Working on SD card....')
  165.    Log('Starting Format_SD ..')
  166.    cmd = 'tail /etc/inittab'
  167.    stdin, stdout, stderr = ssh.exec_command(cmd)
  168.    AppSearch = stdout.read().strip().decode(encoding='utf-8')
  169.  
  170.    Log('inittab info below... \n\n' + AppSearch + '\n')
  171.    if '#za' in AppSearch:
  172.        Log('#za already commented out')
  173.    else:
  174.        Log('commenting za out')
  175.        cmd = 'sed -i s/za:/#za:/ /etc/inittab'
  176.        stdin, stdout, stderr = ssh.exec_command(cmd)
  177.  
  178.    try:
  179.        time.sleep(5)
  180.    finally:
  181.        print('')
  182.  
  183.    if '#zb' in AppSearch:
  184.        Log('#zb already commented out')
  185.    else:
  186.        Log('commenting zb out')
  187.        cmd = 'sed -i s/zb:/#zb:/ /etc/inittab'
  188.        stdin, stdout, stderr = ssh.exec_command(cmd)
  189.  
  190.    time.sleep(5)
  191.  
  192.    if '#zc' in AppSearch:
  193.        Log('#zc already commented out')
  194.    else:
  195.        Log('commenting zc out')
  196.        cmd = 'sed -i s/zc:/#zc:/ /etc/inittab'
  197.        stdin, stdout, stderr = ssh.exec_command(cmd)
  198.  
  199.    try:
  200.        time.sleep(5)
  201.    finally:
  202.        print('')
  203.  
  204.    if '#zd' in AppSearch:
  205.        Log('#z already commented out')
  206.    else:
  207.        Log('commenting zd out')
  208.        cmd = 'sed -i s/zd:/#zd:/ /etc/inittab'
  209.        stdin, stdout, stderr = ssh.exec_command(cmd)
  210.  
  211.    try:
  212.        time.sleep(5)
  213.    finally:
  214.        print('')
  215.  
  216.    stdin, stdout, stderr = ssh.exec_command('init q')
  217.  
  218.    time.sleep(5)
  219.  
  220.    Log('stopping mclient ..')
  221.    stdin, stdout, stderr = ssh.exec_command('sh /etc/init.d/mclientd stop')
  222.  
  223.    try:
  224.        time.sleep(5)
  225.    finally:
  226.        print('')
  227.  
  228.    Log('stopping syslog ..')
  229.    stdin, stdout, stderr = ssh.exec_command('sh /etc/init.d/syslog stop')
  230.  
  231.    try:
  232.        time.sleep(5)
  233.    finally:
  234.        print('')
  235.  
  236.    cmd = 'mount'
  237.    stdin, stdout, stderr = ssh.exec_command(cmd)
  238.    MOUNTlog = stdout.read().strip().decode(encoding='utf-8')
  239.    Log('Mount info BEFORE unmount below... \n\n' + MOUNTlog + '\n')
  240.  
  241. def ReviveAll():
  242.    Log('running sed, then will output contents of file')
  243.    print('changing from vfat -> auto...')
  244.    cmd = 'sed -i s/vfat/auto/ /etc/fstab'
  245.    stdin, stdout, stderr = ssh.exec_command(cmd)
  246.  
  247.    time.sleep(4)
  248.  
  249.    cmd = 'cat /etc/fstab'
  250.    stdin, stdout, stderr = ssh.exec_command(cmd)
  251.    FSTABlog = stdout.read().strip().decode(encoding='utf-8')
  252.    Log('FSTAB BELOW>..\n\n: ' + FSTABlog + '\n' )
  253.  
  254.    PrintBox('restoring inittab file..')
  255.    cmd = 'tail /etc/inittab'
  256.    stdin, stdout, stderr = ssh.exec_command(cmd)
  257.    AppSearch = stdout.read().strip().decode(encoding='utf-8')
  258.  
  259.    #will make function/array in future iteration
  260.    if '#za' in AppSearch:
  261.        Log('un-commenting za out')
  262.        cmd = 'sed -i s/#za:/za:/ /etc/inittab'
  263.        stdin, stdout, stderr = ssh.exec_command(cmd)
  264.    else:
  265.        Log('za not commented out')
  266.  
  267.    time.sleep(5)
  268.  
  269.    if '#zb' in AppSearch:
  270.        Log('un-commenting zb out')
  271.        cmd = 'sed -i s/#zb:/zb:/ /etc/inittab'
  272.        stdin, stdout, stderr = ssh.exec_command(cmd)
  273.    else:
  274.        Log('zb not commented out')
  275.  
  276.    time.sleep(5)
  277.  
  278.    if '#zc' in AppSearch:
  279.        Log('un-commenting zc out')
  280.        cmd = 'sed -i s/#zc:/zc:/ /etc/inittab'
  281.        stdin, stdout, stderr = ssh.exec_command(cmd)
  282.    else:
  283.        Log('zc not commented out')
  284.  
  285.    time.sleep(5)
  286.  
  287.    if '#zd' in AppSearch:
  288.        Log('un-commenting zd out')
  289.        cmd = 'sed -i s/#zd:/zd:/ /etc/inittab'
  290.        stdin, stdout, stderr = ssh.exec_command(cmd)
  291.    else:
  292.        Log('zd not commented out')
  293.  
  294.    time.sleep(5)
  295.    cmd = 'mount'
  296.    stdin, stdout, stderr = ssh.exec_command(cmd)
  297.    MOUNTlog = stdout.read().strip().decode(encoding='utf-8')
  298.    Log('Mount info BEFORE unmount below... \n\n' + MOUNTlog + '\n')
  299.  
  300. def Fdisk():
  301.    KillAll()
  302.    Log('Starting Format_SD ..\n running fdisk ..')
  303.    cmd = '(echo d; echo n; echo p; echo 1; echo ; echo ; echo w;) | fdisk /dev/mmcblk0'
  304.    stdin, stdout, stderr = ssh.exec_command(cmd)
  305.  
  306.  
  307. def MKFS():
  308.    Clear()
  309.    Log('Starting Format_SD ..\n umounting ..')
  310.    print('making filesystem, takes about 85 seconds...')
  311.    cmd = 'mkfs.ext3 /dev/mmcblk0p1'
  312.    stdin, stdout, stderr = ssh.exec_command(cmd)
  313.    time.sleep(85)
  314.    ReviveAll()
  315.  
  316. def CheckSD():
  317.    Log('entered CheckSD().....')
  318.    cmd = "mount | grep '/dev/mmcblk0p1'"
  319.    stdin, stdout, stderr = ssh.exec_command(cmd)
  320.    SDreults = stdout.read().strip().decode(encoding='utf-8')
  321.    if 'var/permalog' in SDreults:
  322.        Log('\n SD card check successful')
  323.        PrintBox('SD card check successful!')
  324.        wait()
  325.    else:
  326.        Log('\n SD card bad')
  327.        PrintBox('App Version is... '+  Version_App + '\n press any key to continue\n')
  328.        m.getch()
  329.        if '10.0.6' in Version_App:
  330.            Log('running mkfs command..')
  331.            PrintBox('SD Card bad, fixing!\n\n Making filesystem...\n')
  332.            Fdisk()
  333.            MKFS()
  334.            PrintBox('SD card repaired,  preparing to reboot')
  335.            time.sleep(10)
  336.            Reboot()
  337.        else:
  338.            PrintBox('unit not upgraded to 10.0.6, continuing')
  339.            time.sleep(5)
  340.  
  341. def SDFix():
  342.    Log('entered SDFix()...')
  343.    KillAll()
  344.    cmd = 'umount -l /dev/mmcblk0p1'
  345.    stdin, stdout, stderr = ssh.exec_command(cmd)
  346.    time.sleep(5)
  347.  
  348.    logging.info('[' + time.strftime("%H:%M") + ']|> running mkfs...')
  349.    print('making filesystem...\n   This will take about 85 seconds.. \n')
  350.    cmd = 'mkfs.ext3 /dev/mmcblk0p1'
  351.    stdin, stdout, stderr = ssh.exec_command(cmd)
  352.    time.sleep(85)
  353.  
  354.    cmd = 'mount /dev/mmcblk0p1'
  355.    stdin, stdout, stderr = ssh.exec_command(cmd)
  356.    time.sleep(5)
  357.    ReviveAll()
  358.  
  359. def ConnectSSH():
  360.    Clear()
  361.    CheckSSH()
  362.    Log('Connecting to host...')
  363.    print('Connecting to ' + host)
  364.    global ssh, sftp
  365.    ssh = paramiko.SSHClient()
  366.    ssh.set_missing_host_key_policy(
  367.        paramiko.AutoAddPolicy())
  368.    ssh.connect( host, username = username, password = password)
  369.    print('    Connected to ' + host)
  370.    logging.info('connected to host ('+host+')')
  371.    sftp = ssh.open_sftp()
  372.    GetVersion()
  373.    GetSerial()
  374.  
  375.  
  376. def ChangeSerial():
  377.    Log('Changing Serial...')
  378.    sftp.chdir('/etc/unique/')
  379.    try:
  380.        sftp.stat('SERIAL')
  381.    except IOError as e:
  382.         print()
  383.    else:
  384.        sftp.remove('SERIAL')
  385.    HomeFolder()
  386.    os.chdir('temp/unique')
  387.    print('_______________________________________\n')
  388.    NewSerial = input('Please enter the correct/updated Serial number and press the enter key: \n\n'
  389.                          'New Serial: ')
  390.    f = open('SERIAL', 'w')
  391.    f.write(NewSerial)
  392.    f.close()
  393.    sftp.put('SERIAL','SERIAL')
  394.    LocalClean()
  395.    print('Serial Number updated, checking Serial Number on device..')
  396.    print('_______________________________________\n')
  397.    Log('serial set to '+ NewSerial)
  398.    ConnectSSH()
  399.  
  400. def SendCMD(cmd, VALUE):
  401.    Log('sending command.. ' + cmd)
  402.    print(' sending command.. ' + cmd)
  403.    stdin, stdout, stderr = ssh.exec_command(cmd)
  404.    VALUEcmd = stdout.read().strip().decode(encoding='utf-8')
  405.  
  406.  
  407.  
  408. def GetSerial():
  409.    global SERIAL
  410.    sftp.chdir('/etc/unique')
  411. #    SendCMD('head /etc/unique/SERIAL',SERIAL)
  412.    cmd = 'head /etc/unique/SERIAL'
  413.    stdin, stdout, stderr = ssh.exec_command(cmd)
  414.    SERIAL = stdout.read().strip().decode(encoding='utf-8')
  415.    Log('Current Serial: ' + SERIAL )
  416.    print('Please confirm that the serial number below \nmatches the label on the back of the device \n')
  417.    print("Serial: " + SERIAL + '\n')
  418.    _serialanswer_ =input('Is this serial correct?(Y/N) ')
  419.    if _serialanswer_ == b'N':
  420.        Log('user specified serial is incorrect')
  421.        ChangeSerial()
  422.    elif _serialanswer_ == 'n':
  423.        Log('user specified serial is incorrect')
  424.        ChangeSerial()
  425.    else:
  426.        Log('user specified serial is correct')
  427.        print()
  428.  
  429. def GetVersion():
  430.    global Version_App, Version_System
  431.    cmd = "ipkg list_installed | grep pts150-application"
  432.    stdin, stdout, stderr = ssh.exec_command(cmd)
  433.    Version = stdout.read().strip().decode(encoding='utf-8')
  434.    Version_App = Version[Version.find("pts150-application - ")+20:Version.find(" - Application")]
  435.    global Version_
  436.    cmd = "ipkg list_installed | grep pts150-system"
  437.    stdin, stdout, stderr = ssh.exec_command(cmd)
  438.    Version = stdout.read().strip().decode(encoding='utf-8')
  439.    Version_System = Version[Version.find("pts150-system - ")+16:Version.find(" - System")]
  440.    #Version_System = bytes(Version_System, encoding='utf-8')
  441.    PrintBox('Application version is :' + Version_App)
  442.    logging.info('[' + time.strftime("%H:%M") + ']|> ________________________________________')
  443.  
  444.  
  445. def GetTemp():
  446.    CheckSSH()
  447.    global Temp
  448.    cmd = "grep -Eo 'Calibration Temperature Offset C100ths</comment><value>-*[0-9]+' /etc/ptsenv/THERM.cfg"
  449.    stdin, stdout, stderr = ssh.exec_command(cmd)
  450.    Temp = stdout.read().strip().decode(encoding='utf-8')
  451.    TempValue = Temp[55:]
  452.    if TempValue == "":
  453.        print('no value found')
  454.        cmd = "head -10 /etc/ptsenv/THERM.cfg | tail -1 | grep value"
  455.        stdin, stdout, stderr = ssh.exec_command(cmd)
  456.        Temp = stdout.read().strip().decode(encoding='utf-8')
  457.        TempValue = Temp[7:]
  458.        if '</value>' in TempValue:
  459.            Log('removing </value> from TempValue')
  460.            TempValue = TempValue.replace('</value>','')
  461.        else:
  462.            print('')
  463.    else:
  464.        print ('')
  465.    PrintBox('The set point value is: ' + TempValue)
  466.    Log('Set Value is ' + TempValue)
  467.    wait()
  468.  
  469. def Remove(RMfiles,path):
  470.    CheckSSH()
  471.    logging.info('[' + time.strftime("%H:%M") + ']|> ________________________________________')
  472.    logging.info('[' + time.strftime("%H:%M") + ']|> Running Remove(): ')
  473.    for elem in RMfiles:
  474.        print('\n___________________________')
  475.        print('Looking for ' + elem + ' .....')
  476.        if elem in sftp.listdir(path):
  477.            print('Removing ' + elem  + '....')
  478.            print('___________________________\n')
  479.            logging.info('[' + time.strftime("%H:%M") + ']|> removing following files :')
  480.            logging.info('[' + time.strftime("%H:%M") + ']|> ' + elem )
  481.            sftp.remove(path+elem)
  482.    logging.info('[' + time.strftime("%H:%M") + ']|> ________________________________________')
  483.  
  484. def RemoveRemoteDir():
  485.    CheckSSH()
  486.    ConnectSSH()
  487.    PrintDirs()
  488.    Log('Running RemoveRemoteDir() ')
  489.    for filename in sftp.listdir(destination):
  490.        filepath = os.path.join(destination, filename)
  491.        print('removing ' + filename)
  492.        logging.info('[' + time.strftime("%H:%M") + ']|> removing :' + filepath)
  493.        sftp.remove(filepath)
  494.    print('\n removing ' + destination)
  495.    logging.info('[' + time.strftime("%H:%M") + ']|> removing :' + destination)
  496.    sftp.rmdir(destination)
  497.    logging.info('[' + time.strftime("%H:%M") + ']|> ________________________________________')
  498.  
  499. def RemoveFactory():
  500.    CheckSSH()
  501.    Log('Running RemoveFactory()')
  502.    RMfiles = ['FACTORY']
  503.    Remove(RMfiles,'/etc/ptsenv/')
  504.  
  505. def RemoveCONFIGsav():
  506.    CheckSSH()
  507.    Log('Running RemoveCONFIGsav()')
  508.    RMfiles = ['CONFIG.sav']
  509.    Remove(RMfiles,'/etc/ptsenv/')
  510.  
  511.  
  512. def CheckUpdateSW():
  513.    CheckSSH()
  514.    Log('Running CheckUpdateSW() ')
  515.    print(' Checking for ('+ destination +')\n')
  516.    try:
  517.        sftp.stat(destination)
  518.    except IOError as e:
  519.         if 'No such file' in str(e):
  520.             print('update folder not found..')
  521.             print('creating updatesw directory')
  522.             logging.info('[' + time.strftime("%H:%M") + ']|> creating /tmp/updatesw')
  523.             sftp.mkdir('/tmp/updatesw')
  524.             print('proceeding to upgrade..')
  525.             Upgrade()
  526.    else:
  527.        print('Folder already exists..\n')
  528.        print('removing old folder')
  529.        RemoveRemoteDir()
  530.        print('folder removed\n')
  531.        print('removing host IP from utility..')
  532.        host = ''
  533.        print('(host value should be blank)')
  534.        print('host : ' + host)
  535.        print('going back to menu...')
  536.        PrintBox('unit already had update folder \nyou are about to return to menu \n please choose upgrade again')
  537.        Clear()
  538.        CheckUpdateSW()
  539.        logging.info('[' + time.strftime("%H:%M") + ']|> ________________________________________')
  540.  
  541.  
  542. def WindsorBackup():
  543.    global SERIAL
  544.    MapLDrive()
  545.    logging.info('[' + time.strftime("%H:%M") + ']|> ________________________________________')
  546.    logging.info('[' + time.strftime("%H:%M") + ']|> Entered WindsorBackup')
  547.    os.chdir('L:\\')
  548.    PrintDirs()
  549.  
  550.    if os.path.exists(str(SERIAL)):
  551.        logging.info('[' + time.strftime("%H:%M") + ']|> ' + str(SERIAL) + ' is there!' )
  552.    else:
  553.        CreateOSFolder([str(SERIAL)])
  554.        logging.info('[' + time.strftime("%H:%M") + ']|> created ' + str(SERIAL) )
  555.  
  556.    TimeStamp = time.strftime("%m_%d_%Y")
  557.    Ldrive = 'L:\\' + str(SERIAL) + '\\' + TimeStamp
  558.  
  559.    if os.path.exists(Ldrive):
  560.        logging.info('[' + time.strftime("%H:%M") + ']|> ' + Ldrive + 'was not found, will use hour and minute')
  561.        #Ldrive = str(SERIAL)+'\\' + time.strftime("%Y-%m-%d_%H-%M")+'\Pre_Wipe'
  562.        TimeStamp = time.strftime("%m_%d_%Y[%H-%M]")
  563.        Ldrive = 'L:\\' +  str(SERIAL)+'\\' + TimeStamp
  564.        CreateOSFolder([Ldrive])
  565.        logging.info('[' + time.strftime("%H:%M") + ']|> new Ldrive .. ' + Ldrive)
  566.    else:
  567.        logging.info('[' + time.strftime("%H:%M") + ']|>' + Ldrive +  'was not found, creating it')
  568.        CreateOSFolder([Ldrive])
  569.    logging.info('[' + time.strftime("%H:%M") + ']|> creating rest of folders for backup')
  570.  
  571.    CreateOSFolder([
  572.        Ldrive+'\Windsor_Backup',
  573.        Ldrive+'\Windsor_Backup\etc', Ldrive+'\Windsor_Backup\etc\ptsenv', Ldrive+r'\Windsor_Backup\etc\unique',
  574.        Ldrive+'\Windsor_Backup\\var', Ldrive+'\Windsor_Backup\\var\permalog',
  575.        Ldrive+'\Windsor_Backup\home', Ldrive+'\Windsor_Backup\home\localdata'])
  576.  
  577.    PrintBox('Utility will now begin transferring files\n from unit to network drive...')
  578.    logging.info('[' + time.strftime("%H:%M") + ']|> ________________________________________')
  579.    logging.info('[' + time.strftime("%H:%M") + ']|> L drive set to :  ' + Ldrive)
  580.    logging.info('[' + time.strftime("%H:%M") + ']|> creating subfolders...')
  581.  
  582.    sftp.chdir('/etc/')
  583.    os.chdir(Ldrive+'\Windsor_Backup\etc')
  584.    path = 'ptsenv/'
  585.    PrintDirs()
  586.  
  587.    print('Backing up ptsenv folder...')
  588.    for filename in sftp.listdir('ptsenv'):
  589.        if filename == 'BATTERY.log':
  590.            logging.info('[' + time.strftime("%H:%M") + ']|> removing : ' + filename)
  591.            cmd = 'rm ' + filename
  592.            stdin, stdout, stderr = ssh.exec_command(cmd)
  593.        elif filename != 'wpa_supplicant.d':
  594.            if filename != 'BATTERY.log':
  595.                filepath = os.path.join(path, filename)
  596.                PrintBox('filename is ' + filename + '\n  transferring... ' + filepath)
  597.                logging.info('[' + time.strftime("%H:%M") + ']|> backing up : ' + filepath)
  598.                sftp.get(filepath, filepath)
  599.  
  600.    path ='unique/'
  601.    PrintDirs()
  602.    print('Backing up unique folder....')
  603.    for filename in sftp.listdir('unique'):
  604.        filepath = os.path.join(path, filename)
  605.        PrintBox('filename is ' + filename + '\n  transferring... ' + filepath)
  606.        logging.info('[' + time.strftime("%H:%M") + ']|> backing up : ' + filepath)
  607.        sftp.get(filepath, filepath)
  608.    os.chdir('..')
  609.  
  610.    sftp.chdir('/home/')
  611.    os.chdir('home')
  612.    PrintDirs()
  613.    path = 'localdata/'
  614.    print('Backing up localdata folder....')
  615.    for filename in sftp.listdir('localdata'):
  616.        if 'PTS' in filename:
  617.            filepath = os.path.join(path, filename)
  618.            PrintBox('filename is ' + filename + '\n  transferring... ' + filepath)
  619.            logging.info('[' + time.strftime("%H:%M") + ']|> backing up : ' + filepath)
  620.            sftp.get(filepath, filepath)
  621.    os.chdir('..')
  622.  
  623.    sftp.chdir('/var/')
  624.    os.chdir('var')
  625.    path ='permalog/'
  626.    PrintDirs()
  627.  
  628.    print('Backing up permalog folder....')
  629.    for filename in sftp.listdir('permalog'):
  630.        if filename == 'lost+found':
  631.            print('Removing lost+found')
  632.            logging.info('[' + time.strftime("%H:%M") + ']|> removing ' + path + 'lost+found')
  633.            sftp.rmdir(path + 'lost+found')
  634.        else:
  635.            if filename != 'Templates':
  636.                if filename != 'System Volume Information':
  637.                    filepath = os.path.join(path, filename)
  638.                    PrintBox('filename is ' + filename + '\n  transferring... ' + filepath)
  639.                    logging.info('[' + time.strftime("%H:%M") + ']|> backing up : ' + filepath)
  640.                    sftp.get(filepath, filepath)
  641.  
  642.    os.chdir('..')
  643.    wait()
  644.    logging.info('[' + time.strftime("%H:%M") + ']|> finished pre wipe backup...')
  645.    logging.info('[' + time.strftime("%H:%M") + ']|> removing files...')
  646.    Clear()
  647.  
  648.  
  649.  
  650. def WifiNo():
  651.    Log('Setting Wifi to False')
  652.    cmd = 'cat /etc/ptsenv/pts150gui.ini'
  653.    stdin, stdout, stderr = ssh.exec_command(cmd)
  654.    WifiSearch = stdout.read().strip().decode(encoding='utf-8')
  655.    Log('contents of pts150gui below... \n\n' + WifiSearch )
  656.    if 'UseWifi=false' in WifiSearch:
  657.        Log('WiFi already false')
  658.        PrintBox('WiFI already enabled')
  659.    elif 'UseWifi=true' in WifiSearch:
  660.        Log('changing UseWifi to true..')
  661.        cmd = "sed -i s/UseWifi=true/UseWifi=false/  /etc/ptsenv/pts150gui.ini"
  662.        stdin, stdout, stderr = ssh.exec_command(cmd)
  663.        Log('contents of pts150gui below... \n\n' + WifiSearch )
  664.    else:
  665.        Log('adding in UseWifi=false')
  666.        cmd = r"sed -i '/\[wifi\]/,/\[wired\]/{ /^[[:space:]]*$/{ s//UseWifi=false\n/ } }' /etc/ptsenv/pts150gui.ini"
  667.        stdin, stdout, stderr = ssh.exec_command(cmd)
  668.        Log('contents of pts150gui below... \n\n' + WifiSearch )
  669.  
  670. def WifiYes():
  671.    Log('Setting Wifi to True')
  672.    cmd = 'cat /etc/ptsenv/pts150gui.ini'
  673.    stdin, stdout, stderr = ssh.exec_command(cmd)
  674.    WifiSearch = stdout.read().strip().decode(encoding='utf-8')
  675.    Log('contents of pts150gui below... \n\n' + WifiSearch )
  676.    if 'UseWifi=true' in WifiSearch:
  677.        Log('WiFi already true')
  678.        PrintBox('WiFI already enabled')
  679.    elif 'UseWifi=false' in WifiSearch:
  680.        Log('changing UseWifi to true..')
  681.        cmd = "sed -i s/UseWifi=false/UseWifi=true/  /etc/ptsenv/pts150gui.ini"
  682.        stdin, stdout, stderr = ssh.exec_command(cmd)
  683.        Log('contents of pts150gui below... \n\n' + WifiSearch )
  684.    else:
  685.        Log('adding in UseWifi=true')
  686.        cmd = r"sed -i '/\[wifi\]/,/\[wired\]/{ /^[[:space:]]*$/{ s//UseWifi=true\n/ } }' /etc/ptsenv/pts150gui.ini"
  687.        stdin, stdout, stderr = ssh.exec_command(cmd)
  688.        Log('contents of pts150gui below... \n\n' + WifiSearch )
  689.  
  690. def WifiCheck():
  691.    Clear()
  692.    CheckSSH()
  693.    global _WifiAnswer_
  694.    _WifiAnswer_ =input('Is this a WiFi unit?(Y/N): ')
  695.    Log('user entered ' + _WifiAnswer_ + ' for ~is this wifi?~')
  696.    _confirm_=input('You entered ' + _WifiAnswer_ + ' are you sure? ')
  697.    if _confirm_ == 'n':
  698.        Log('user chose N on confirm, starting WiFiCheck over')
  699.        WifiCheck()
  700.    else:
  701.        if _WifiAnswer_ == 'y':
  702.            Log('going to WifiYes()')
  703.            WifiYes()
  704.        else:
  705.            WifiNo()
  706.  
  707. def Upgrade():
  708.    CheckSSH()
  709.    WindsorBackup()
  710.    LocalClean()
  711.    PrintDirs()
  712.    RemoveFactory()
  713.    HomeFolder()
  714.    EnableTest()
  715.    RemoveCONFIGsav()
  716. #    sftp.remove('/etc/ptsenv/CONFIG.sav')
  717. #    PrintBox('removed CONFIG.sav')
  718.    time.sleep(5)
  719.    DisableTest()
  720. #    ModeReplace()
  721.    EnableTest()
  722.    Log('Running Upgrade() ')
  723.    print('Checking update directory')
  724.    print(' Info on each file being worked on below..\n')
  725.    for filename in os.listdir(source):
  726.        print('____________________________\n')
  727.        print(' working on \n' +  filename + '\n')
  728.        print('  moving.. \n' +  os.path.join(source, filename)+ '\n')
  729.        print('to.. \n' + os.path.join(destination, filename) + '\n')
  730.        print('(now doing actual command)')
  731.        Log('moving update files from pc to nexgen')
  732.        sftp.put(
  733.            os.path.join(source, filename),
  734.            os.path.join(destination, filename) )
  735.    print('____________________________\n')
  736.  
  737.    print('changing dir to update folder..')
  738.    sftp.chdir('/tmp/updatesw')
  739.  
  740.             #####################################
  741.            #                                   #
  742.            #     -Installing packages-         #
  743.            #                                   #
  744.            #####################################
  745.  
  746.    PrintDirs()
  747.    for filename in sftp.listdir(destination):
  748.        filepath = os.path.join(destination, filename)
  749.        PrintBox('Installing ... ' +  filepath)
  750.        logging.info('[' + time.strftime("%H:%M") + ']|> installing packages..')
  751.        cmd = 'ipkg install -force-overwrite -force-downgrade ' + filepath
  752.        stdin, stdout, stderr = ssh.exec_command(cmd)
  753.        Install = stdout.read().strip().decode(encoding='utf-8')
  754.        print(Install)
  755.    PrintBox('software installed..\n press any key to continue')
  756.    m.getch()
  757.    logging.info('[' + time.strftime("%H:%M") + ']|> sync after install')
  758.    stdin, stdout, stderr = ssh.exec_command('sync')
  759.    Sync = stdout.read().strip().decode(encoding='utf-8')
  760.    print(Sync)
  761.    DisableTest()
  762.    SDFix()
  763.    WifiCheck()
  764.    Reboot()
  765.  
  766.  
  767. def MountCheck():
  768.    CheckSSH()
  769.    PrintDirs()
  770.    Log('Running MountCheck() ')
  771.    cmd = 'mount | grep ptsenv'
  772.    #cmd = 'mount | grep i'
  773.    stdin, stdout, stderr = ssh.exec_command(cmd)
  774.    Mount = stdout.read().strip().decode(encoding='utf-8')
  775.    if Mount == '':
  776.        PrintBox('   Nothing mounted, moving to Install')
  777.        logging.info('[' + time.strftime("%H:%M") + ']|> nothing found, moving to install')
  778.        CheckUpdateSW()
  779.    else:
  780.        PrintBox('mount WAS NOT blank, doing copymount')
  781.        logging.info('[' + time.strftime("%H:%M") + ']|> mount found, going to CopyMount()')
  782.        #wait()
  783.        CopyMount()
  784.        MountCheck()
  785.    logging.info('[' + time.strftime("%H:%M") + ']|> ________________________________________')
  786.  
  787.                    #####################################
  788.                    #                                   #
  789.                    #            _Files_                #
  790.                    #          Nexgen -> PC             #
  791.                    #                                   #
  792.                    #####################################
  793. def CopyMount():
  794.    HomeFolder()
  795.    os.chdir('temp')
  796.    sftp.chdir('/etc/')
  797.    path = 'ptsenv/'
  798.    Log('Running CopyMount()')
  799.    PrintDirs()
  800.    print('Backing up ptsenv folder...')
  801.    for filename in sftp.listdir('ptsenv'):
  802.        if 'root' not in filename:
  803.            if '~' not in filename:
  804.                if filename != 'default.cfg':
  805.                    if filename != 'wpa_supplicant.d':
  806.                        if filename != 'BATTERY.log':
  807.                            if filename != 'mode.cfg':
  808.                                print('filename is ' + filename)
  809.                                filepath = os.path.join(path, filename)
  810.                                print(' transferring... ' + filepath)
  811.                                print('_______________________________________\n')
  812.                                logging.info('[' + time.strftime("%H:%M") + ']|> backing up : ' + filepath)
  813.                                sftp.get(filepath, filepath)
  814.  
  815.    logging.info('[' + time.strftime("%H:%M") + ']|> ________________________________________')
  816.  
  817.    sftp.chdir('ptsenv')
  818.    os.chdir('ptsenv')
  819.    path = 'wpa_supplicant.d/'
  820.    PrintDirs()
  821.    print('Backing up wpa_supplicant.d folder...')
  822.    for filename in sftp.listdir('wpa_supplicant.d'):
  823.        filepath = os.path.join(path, filename)
  824.        PrintBox('filename is ' + filename + '\n transferring... ' + filepath)
  825.        logging.info('[' + time.strftime("%H:%M") + ']|> backing up : ' + filepath)
  826.        sftp.get(filepath, filepath)
  827.  
  828.    PrintDirs()
  829.    HomeFolder()
  830.    os.chdir('temp')
  831.    sftp.chdir('/etc/')
  832.    path ='unique/'
  833.    PrintDirs()
  834.    print('Backing up unique folder....')
  835.    for filename in sftp.listdir('unique'):
  836.        filepath = os.path.join(path, filename)
  837.        PrintBox('filename is ' + filename + '\n transferring... ' + filepath)
  838.        logging.info('[' + time.strftime("%H:%M") + ']|> backing up : ' + filepath)
  839.        sftp.get(filepath, filepath)
  840.  
  841.    sftp.chdir('/home/')
  842.    PrintDirs()
  843.    path = 'localdata/'
  844.    print('Backing up localdata folder....')
  845.    for filename in sftp.listdir('localdata'):
  846.        if 'PTS' in filename:
  847.            filepath = os.path.join(path, filename)
  848.            PrintBox('filename is ' + filename + '\n transferring... ' + filepath)
  849.            logging.info('[' + time.strftime("%H:%M") + ']|> backing up : ' + filepath)
  850.            sftp.get(filepath, filepath)
  851.  
  852.    print('Sync Before Unmount')
  853.    logging.info('[' + time.strftime("%H:%M") + ']|> sync before unmount')
  854.    stdin, stdout, stderr = ssh.exec_command('sync')
  855.    Sync = stdout.read().strip().decode(encoding='utf-8')
  856.    print(Sync)
  857.  
  858.  
  859.                #####################################
  860.                #                                   #
  861.                #         -unmountings-             #
  862.                #                                   #
  863.                #####################################
  864.  
  865.    PrintDirs()
  866.    logging.info('[' + time.strftime("%H:%M") + ']|> unmounting 5')
  867.    print('umounting mtdblock5\n')
  868.    cmd = 'umount /dev/mtdblock5'
  869.    stdin, stdout, stderr = ssh.exec_command(cmd)
  870.    Unmount5 = stdout.read().strip().decode(encoding='utf-8')
  871.    print(Unmount5)
  872.    print('MTDblock5 unmounted..\n')
  873.  
  874.    logging.info('[' + time.strftime("%H:%M") + ']|> unmounting 6')
  875.    print('umounting mtdblock6\n')
  876.    cmd = 'umount /dev/mtdblock6'
  877.    stdin, stdout, stderr = ssh.exec_command(cmd)
  878.    Unmount6 = stdout.read().strip().decode(encoding='utf-8')
  879.    print(Unmount6)
  880.    print('MTDblock6 unmounted...')
  881.  
  882.    logging.info('[' + time.strftime("%H:%M") + ']|> unmounting 7')
  883.    print('umounting mtdblock7\n')
  884.    cmd = 'umount /dev/mtdblock7'
  885.    stdin, stdout, stderr = ssh.exec_command(cmd)
  886.    Unmount7 = stdout.read().strip().decode(encoding='utf-8')
  887.    print(Unmount7)
  888.    print('MTDblock7 unmounted...')
  889.  
  890.    logging.info('[' + time.strftime("%H:%M") + ']|> sync after unmount')
  891.    print('Sync after Unmount...')
  892.    stdin, stdout, stderr = ssh.exec_command('sync')
  893.    Sync = stdout.read().strip().decode(encoding='utf-8')
  894.    print(Sync)
  895.  
  896.  
  897.                    #####################################
  898.                    #                                   #
  899.                    #            _Files_                #
  900.                    #            PC -> Nexgen           #
  901.                    #                                   #
  902.                    #####################################
  903.  
  904.  
  905.    sftp.chdir('/etc/')
  906.    path = 'ptsenv/'
  907.    PrintDirs()
  908.    print('deleting old ptsenv files from nexgen....')
  909.    for filename in sftp.listdir('ptsenv'):
  910.        if filename != 'wpa_supplicant.d':
  911.            filepath = os.path.join(path, filename)
  912.            PrintBox('filename is ' + filename + '\n removing... ' + filepath)
  913.            Log('Removing :' + filepath)
  914.            sftp.remove(filepath)
  915.        else:
  916.            print('no file')
  917.  
  918.    print('restoring ptsenv files ....')
  919.    for filename in os.listdir('ptsenv'):
  920.        if filename != 'wpa_supplicant.d':
  921.            filepath = os.path.join(path, filename)
  922.            PrintBox('filename is ' + filename + '\n transferring... ' + filepath)
  923.            sftp.put(filepath, filepath)
  924.        else:
  925.            print('no file')
  926.  
  927.    sftp.chdir('ptsenv')
  928.    os.chdir('ptsenv')
  929.    PrintDirs()
  930.    path = 'wpa_supplicant.d/'
  931.    try:
  932.        sftp.stat('wpa_supplicant.d')
  933.    except IOError as e:
  934.         if 'No such file' in str(e):
  935.             sftp.mkdir('wpa_supplicant.d')
  936.    else:
  937.        raise
  938.  
  939.    print('deleting old wpa_supplicant.d files to nexgen....')
  940.    for filename in sftp.listdir('wpa_supplicant.d'):
  941.        filepath = os.path.join(path, filename)
  942.        PrintBox('filename is ' + filename + '\n removing... ' + filepath)
  943.        logging.info('[' + time.strftime("%H:%M") + ']|> removing :' + filepath)
  944.        sftp.remove(filepath)
  945.    else:
  946.        print('no file')
  947.  
  948.    print('restoring wpa_supplicant.d files ....')
  949.    PrintDirs()
  950.    for filename in os.listdir('wpa_supplicant.d'):
  951.        filepath = os.path.join(path, filename)
  952.        PrintBox('filename is ' + filename + '\n transferring... ' + filepath)
  953.        logging.info('[' + time.strftime("%H:%M") + ']|> restoring :' + filepath)
  954.        sftp.put(filepath, filepath)
  955.    else:
  956.        print('no file')
  957.  
  958.    os.chdir('..')
  959.    sftp.chdir('/etc/')
  960.    path ='unique/'
  961.    PrintDirs()
  962.    print('deleting old unique files from nexgen....')
  963.    for filename in sftp.listdir('unique'):
  964.        filepath = os.path.join(path, filename)
  965.        PrintBox('filename is ' + filename + '\n removing... ' + filepath)
  966.        logging.info('[' + time.strftime("%H:%M") + ']|> removing :' + filepath)
  967.        sftp.remove(filepath)
  968.    else:
  969.        print('no file')
  970.  
  971.    print('restoring unique files ....')
  972.    for filename in os.listdir('unique'):
  973.        filepath = os.path.join(path, filename)
  974.        logging.info('[' + time.strftime("%H:%M") + ']|> restoring :' + filepath)
  975.        PrintBox('filename is ' + filename + '\n transferring... ' + filepath)
  976.        sftp.put(filepath, filepath)
  977.    else:
  978.        print('no file')
  979.  
  980.    sftp.chdir('/home/')
  981.    path = 'localdata/'
  982.    PrintDirs()
  983.    print('deleting old localdata files from nexgen....')
  984.    for filename in sftp.listdir('localdata'):
  985.        filepath = os.path.join(path, filename)
  986.        PrintBox('filename is ' + filename + '\n removing... ' + filepath)
  987.        logging.info('[' + time.strftime("%H:%M") + ']|> removing :' + filepath)
  988.        sftp.remove(filepath)
  989.    else:
  990.        print('no file')
  991.  
  992.    print('restoring localdata files ....')
  993.    for filename in os.listdir('localdata'):
  994.        if 'PTS' in filename:
  995.            filepath = os.path.join(path, filename)
  996.            PrintBox('filename is ' + filename + '\n transferring... ' + filepath)
  997.            logging.info('[' + time.strftime("%H:%M") + ']|> restoring :' + filepath)
  998.            sftp.put(filepath,filepath)
  999.        else:
  1000.            print('no file')
  1001.  
  1002.    print('Last Sync')
  1003.    logging.info('[' + time.strftime("%H:%M") + ']|> final sync')
  1004.    stdin, stdout, stderr = ssh.exec_command('sync')
  1005.    Sync = stdout.read().strip().decode(encoding='utf-8')
  1006.    print(Sync)
  1007.  
  1008.    print('finished copying files')
  1009.  
  1010.                    #####################################
  1011.                    #                                   #
  1012.                    #          _Cleanup_                #
  1013.                    #                                   #
  1014.                    #####################################
  1015.  
  1016. def LocalClean():
  1017.    Clear()
  1018.    print('cleaning local files..')
  1019.    HomeFolder()
  1020.    os.chdir('temp')
  1021.    path = 'localdata/'
  1022.    print('removing localdata files from local computer...')
  1023.    for filename in os.listdir('localdata'):
  1024.        filepath = os.path.join(path, filename)
  1025.        print('Removing local file.. ' + filepath + '\n')
  1026.        logging.info('[' + time.strftime("%H:%M") + ']|> removing :' + filepath)
  1027.        os.remove(filepath)
  1028.  
  1029.    path = 'ptsenv/'
  1030.    print('removing ptsenv files from local computer...')
  1031.    for filename in os.listdir('ptsenv'):
  1032.         if filename != 'wpa_supplicant.d':
  1033.             filepath = os.path.join(path, filename)
  1034.             print('Removing local file.. ' + filepath + '\n')
  1035.             logging.info('[' + time.strftime("%H:%M") + ']|> removing :' + filepath)
  1036.             os.remove(filepath)
  1037.  
  1038.    path ='unique/'
  1039.    print('removing unique files from local computer...')
  1040.    for filename in os.listdir('unique'):
  1041.        filepath = os.path.join(path, filename)
  1042.        print('Removing local file.. ' + filepath + '\n')
  1043.        logging.info('[' + time.strftime("%H:%M") + ']|> removing :' + filepath)
  1044.        os.remove(filepath)
  1045.  
  1046.    os.chdir('ptsenv')
  1047.    path = 'wpa_supplicant.d/'
  1048.    logging.info('removing wpa_supplicant.d files from local computer.....')
  1049.    print('removing wpa_supplicant.d files from local computer...')
  1050.    for filename in os.listdir('wpa_supplicant.d'):
  1051.        filepath = os.path.join(path, filename)
  1052.        print('Removing local file.. ' + filepath + '\n')
  1053.        print('Removing local file.. ' + filepath + '\n')
  1054.        logging.info('[' + time.strftime("%H:%M") + ']|> removing :' + filepath)
  1055.        os.remove(filepath)
  1056.    Clear()
  1057.  
  1058. def EnableTest():
  1059.    CheckSSH()
  1060.    Clear()
  1061.    HomeFolder()
  1062.    Log('enabling test mode')
  1063.    Log('checking inittab file..')
  1064.    cmd = 'tail /etc/inittab'
  1065.    stdin, stdout, stderr = ssh.exec_command(cmd)
  1066.    AppSearch = stdout.read().strip().decode(encoding='utf-8')
  1067.    if '#zd' in AppSearch:
  1068.        PrintBox('Unit already in test mode\n\n press any key to continue')
  1069.    else:
  1070.        cmd = 'sed -i s/zd:/#zd:/ /etc/inittab'
  1071.        stdin, stdout, stderr = ssh.exec_command(cmd)
  1072.        stdin, stdout, stderr = ssh.exec_command('init q')
  1073.        PrintBox('Test mode is now ON \n\n press any key to continue')
  1074.    wait()
  1075.  
  1076. def DisableTest():
  1077.    CheckSSH()
  1078.    Clear()
  1079.    HomeFolder()
  1080.    Log('disabling test mode')
  1081.    Log('checking inittab file..')
  1082.    cmd = 'tail /etc/inittab'
  1083.    stdin, stdout, stderr = ssh.exec_command(cmd)
  1084.    AppSearch = stdout.read().strip().decode(encoding='utf-8')
  1085.    if '#zd' in AppSearch:
  1086.        cmd = 'sed -i s/#zd:/zd:/ /etc/inittab'
  1087.        stdin, stdout, stderr = ssh.exec_command(cmd)
  1088.        stdin, stdout, stderr = ssh.exec_command('init q')
  1089.        PrintBox('test mode disabled.')
  1090.    else:
  1091.        PrintBox('unit was not in test mode.')
  1092.    wait()
  1093.  
  1094. def PuTTY():
  1095.    Clear()
  1096.    CheckSSH()
  1097.    Log('making sure unit is in test mode')
  1098.    cmd = 'tail /etc/inittab'
  1099.    stdin, stdout, stderr = ssh.exec_command(cmd)
  1100.    AppSearch = stdout.read().strip().decode(encoding='utf-8')
  1101.    if '#zd' in AppSearch:
  1102.        Log('unit already in test mode')
  1103.        PrintBox('Unit already in test mode')
  1104.    else:
  1105.        cmd = 'sed -i s/zd:/#zd:/ /etc/inittab'
  1106.        stdin, stdout, stderr = ssh.exec_command(cmd)
  1107.        stdin, stdout, stderr = ssh.exec_command('init q')
  1108.        Log('enabled test mode')
  1109.        PrintBox('Test mode is now ON')
  1110.    Clear()
  1111.    os.system('color 17')
  1112.    PrintBox('launching putty, utility will progress once window is closed \n\n' + \
  1113.             'Utility will disable test mode when putty is closed')
  1114.    winCMD = '.\putty.exe -ssh root@'+host+' -pw ew3_llc'
  1115.    subprocess.call(winCMD)
  1116.    DisableTest()
  1117.    os.system('color 07')
  1118.  
  1119.  
  1120. def MapLDrive():
  1121.    # initialize
  1122.    logging.info('[' + time.strftime("%H:%M") + ']|> started MapLDrive')
  1123.    driveLetter = 'L:'
  1124.    networkPath = '\\\\10.45.4.254\Data\\nexgen-PTS\\logs'
  1125.   # logging.info('[' + time.strftime("%H:%M") + ']|> drive letter is ' + driveLetter + '..')
  1126.    #logging.info('[' + time.strftime("%H:%M") + ']|> path is ' + networkPath + '..')
  1127.  
  1128.    # Disconnecting
  1129.    winCMD = 'NET USE ' + driveLetter + ' /delete /YES'
  1130.    logging.info('[' + time.strftime("%H:%M") + ']|> removing L: drive if it exists')
  1131.    #print(winCMD)
  1132.    subprocess.call(winCMD)
  1133.  
  1134.    # Mapping
  1135.    winCMD = 'NET USE ' + driveLetter + ' ' + networkPath
  1136.    logging.info('[' + time.strftime("%H:%M") + ']|> mapping L drive')
  1137.    #print(winCMD)
  1138.    subprocess.call(winCMD)
  1139.    Clear()
  1140.  
  1141.  
  1142. def ClearWireless():
  1143.    logging.info('[' + time.strftime("%H:%M") + ']|> ________________________________________')
  1144.    logging.info('[' + time.strftime("%H:%M") + ']|> clearing wireless settings')
  1145.    logging.info('[' + time.strftime("%H:%M") + ']|> ________________________________________')
  1146.    Clear()
  1147.    print('Removing wireless profiles')
  1148.    RMfiles = ['wpa_supplicant.conf']
  1149.    Remove(RMfiles,'/etc/')
  1150.    RMfiles = ['pts150gui.ini']
  1151.    Remove(RMfiles,'/etc/ptsenv/')
  1152.    logging.info('[' + time.strftime("%H:%M") + ']|> ________________________________________')
  1153.  
  1154. def ModeReplace():
  1155.    logging.info('[' + time.strftime("%H:%M") + ']|> ________________________________________')
  1156.    logging.info('[' + time.strftime("%H:%M") + ']|>  entered ModeReplace()')
  1157.    Clear()
  1158.    try:
  1159.        sftp.stat('/etc/ptsenv/MODE.cfg')
  1160.    except IOError as e:
  1161.        if 'No such file' in str(e):
  1162.            print('no find found')
  1163.            sftp.put('MODE.cfg', '/etc/ptsenv/MODE.cfg')
  1164.    else:
  1165.        print('file found')
  1166.        sftp.remove('/etc/ptsenv/MODE.cfg')
  1167.        print('adding it back')
  1168.        sftp.put(UtilHome + '\MODE.cfg', '/etc/ptsenv/MODE.cfg')
  1169.    for filename in sftp.listdir('/etc/ptsenv/'):
  1170.        if filename == 'BATTERY.log':
  1171.            logging.info('[' + time.strftime("%H:%M") + ']|> removing : ' + filename)
  1172.            cmd = 'rm /etc/ptsenv/' + filename
  1173.            stdin, stdout, stderr = ssh.exec_command(cmd)
  1174.            _reboot = stdout.read().strip().decode(encoding='utf-8')
  1175.            stdin, stdout, stderr = ssh.exec_command('cmd')
  1176.    Clear()
  1177.  
  1178. def RemoveConfig():
  1179.    Clear()
  1180.    HomeFolder()
  1181.    logging.info('[' + time.strftime("%H:%M") + ']|> ________________________________________')
  1182.    logging.info('[' + time.strftime("%H:%M") + ']|> running RemoveConfig().. ')
  1183.    RMfiles = ['SAMPLE_DB.cfg','LOT_CAL.cfg','PTSUSERS.cfg','DEFAULT.cfg']
  1184.    logging.info('[' + time.strftime("%H:%M") + ']|> RM files below... ')
  1185.    Remove(RMfiles,'/etc/ptsenv/')
  1186.  
  1187.    logging.info('[' + time.strftime("%H:%M") + ']|> cleaning user / adding default admin... ')
  1188.    cmd = 'echo "admin;427c6d6148ce09e80004096df96dfe6a224dbcf3;2;1;2016-01-01;2099-01-01" > /etc/ptsenv/PTSUSERS.cfg'
  1189.    stdin, stdout, stderr = ssh.exec_command(cmd)
  1190.    logging.info('[' + time.strftime("%H:%M") + ']|> file added... ')
  1191.    logging.info('[' + time.strftime("%H:%M") + ']|> files currently in ptsenv ')
  1192.    PrintBox('Cleaning out ptsenv files..')
  1193.    PrintDirs()
  1194.    path = '/etc/ptsenv/'
  1195.    for filename in sftp.listdir('/etc/ptsenv/'):
  1196.        if 'root' in filename:
  1197.            print(' removing ' + filename)
  1198.            sftp.remove(path+filename)
  1199.        if '~' in filename:
  1200.            print(' removing ' + filename)
  1201.            sftp.remove(path+filename)
  1202.        if filename == 'default.cfg':
  1203.            print(' removing ' + filename)
  1204.            sftp.remove(path+filename)
  1205.        if filename == 'DEFAULT.cfg':
  1206.            print(' removing ' + filename)
  1207.            sftp.remove(path+filename)
  1208.    #    if filename == 'wpa_supplicant.d':
  1209.    #        os.remove(filename)
  1210.        if filename == 'BATTERY.log':
  1211.            print(' removing ' + filename)
  1212.            sftp.remove(path+filename)
  1213. #        if filename == 'mode.cfg':
  1214. #            print(' removing ' + filename)
  1215. #            sftp.remove(path+filename)
  1216. # do not need to replace MODE.cfg
  1217. #    ModeReplace()
  1218.    ClearWireless()
  1219.    Clear()
  1220.  
  1221. def Copy2Remote():
  1222.    global SERIAL
  1223.    MapLDrive()
  1224.    logging.info('[' + time.strftime("%H:%M") + ']|> ________________________________________')
  1225.    logging.info('[' + time.strftime("%H:%M") + ']|> Entered Copy2Remote')
  1226.    os.chdir('L:\\')
  1227.    PrintDirs()
  1228.  
  1229.    if os.path.exists(str(SERIAL)):
  1230.        logging.info('[' + time.strftime("%H:%M") + ']|> ' + str(SERIAL) + ' is there!' )
  1231.    else:
  1232.        CreateOSFolder([str(SERIAL)])
  1233.        logging.info('[' + time.strftime("%H:%M") + ']|> created ' + str(SERIAL) )
  1234.  
  1235.    TimeStamp = time.strftime("%m_%d_%Y")
  1236.    Ldrive = 'L:\\' + str(SERIAL) + '\\' + TimeStamp
  1237.  
  1238.    if os.path.exists(Ldrive):
  1239.        logging.info('[' + time.strftime("%H:%M") + ']|> ' + Ldrive + 'was not found, will use hour and minute')
  1240.        #Ldrive = str(SERIAL)+'\\' + time.strftime("%Y-%m-%d_%H-%M")+'\Pre_Wipe'
  1241.        TimeStamp = time.strftime("%m_%d_%Y[%H-%M]")
  1242.        Ldrive = 'L:\\' +  str(SERIAL)+'\\' + TimeStamp
  1243.        CreateOSFolder([Ldrive])
  1244.        logging.info('[' + time.strftime("%H:%M") + ']|> new Ldrive .. ' + Ldrive)
  1245.    else:
  1246.        logging.info('[' + time.strftime("%H:%M") + ']|>' + Ldrive +  'was not found, creating it')
  1247.        CreateOSFolder([Ldrive])
  1248.    logging.info('[' + time.strftime("%H:%M") + ']|> creating rest of folders for backup')
  1249.  
  1250.    CreateOSFolder([
  1251.        Ldrive+'\Pre_Wipe',
  1252.        Ldrive+'\Pre_Wipe\etc', Ldrive+'\Pre_Wipe\etc\ptsenv', Ldrive+r'\Pre_Wipe\etc\unique',
  1253.        Ldrive+'\Pre_Wipe\\var', Ldrive+'\Pre_Wipe\\var\permalog',
  1254.        Ldrive+'\Pre_Wipe\home', Ldrive+'\Pre_Wipe\home\localdata'])
  1255.  
  1256.    PrintBox('Utility will now begin transferring files\n from unit to network drive...')
  1257.    logging.info('[' + time.strftime("%H:%M") + ']|> ________________________________________')
  1258.    logging.info('[' + time.strftime("%H:%M") + ']|> L drive set to :  ' + Ldrive)
  1259.    logging.info('[' + time.strftime("%H:%M") + ']|> creating subfolders...')
  1260.  
  1261.    sftp.chdir('/etc/')
  1262.    os.chdir(Ldrive+'\Pre_Wipe\etc')
  1263.    path = 'ptsenv/'
  1264.    PrintDirs()
  1265.  
  1266.    print('Backing up ptsenv folder...')
  1267.    for filename in sftp.listdir('ptsenv'):
  1268.        if filename == 'BATTERY.log':
  1269.            logging.info('[' + time.strftime("%H:%M") + ']|> removing : ' + filename)
  1270.            cmd = 'rm ' + filename
  1271.            stdin, stdout, stderr = ssh.exec_command(cmd)
  1272.            _reboot = stdout.read().strip().decode(encoding='utf-8')
  1273.            stdin, stdout, stderr = ssh.exec_command('cmd')
  1274.        elif filename != 'wpa_supplicant.d':
  1275.            if filename != 'BATTERY.log':
  1276.                filepath = os.path.join(path, filename)
  1277.                PrintBox('filename is ' + filename + '\n  transferring... ' + filepath)
  1278.                logging.info('[' + time.strftime("%H:%M") + ']|> backing up : ' + filepath)
  1279.                sftp.get(filepath, filepath)
  1280.  
  1281.    path ='unique/'
  1282.    PrintDirs()
  1283.    print('Backing up unique folder....')
  1284.    for filename in sftp.listdir('unique'):
  1285.        filepath = os.path.join(path, filename)
  1286.        PrintBox('filename is ' + filename + '\n  transferring... ' + filepath)
  1287.        logging.info('[' + time.strftime("%H:%M") + ']|> backing up : ' + filepath)
  1288.        sftp.get(filepath, filepath)
  1289.    os.chdir('..')
  1290.  
  1291.    sftp.chdir('/home/')
  1292.    os.chdir('home')
  1293.    PrintDirs()
  1294.    path = 'localdata/'
  1295.    print('Backing up localdata folder....')
  1296.    for filename in sftp.listdir('localdata'):
  1297.        if 'PTS' in filename:
  1298.            filepath = os.path.join(path, filename)
  1299.            PrintBox('filename is ' + filename + '\n  transferring... ' + filepath)
  1300.            logging.info('[' + time.strftime("%H:%M") + ']|> backing up : ' + filepath)
  1301.            sftp.get(filepath, filepath)
  1302.    os.chdir('..')
  1303.  
  1304.    sftp.chdir('/var/')
  1305.    os.chdir('var')
  1306.    path ='permalog/'
  1307.    PrintDirs()
  1308.  
  1309.    print('Backing up permalog folder....')
  1310.    for filename in sftp.listdir('permalog'):
  1311.        if filename == 'lost+found':
  1312.            print('Removing lost+found')
  1313.            logging.info('[' + time.strftime("%H:%M") + ']|> removing ' + path + 'lost+found')
  1314.            sftp.rmdir(path + 'lost+found')
  1315.        else:
  1316.            if filename != 'Templates':
  1317.                if filename != 'System Volume Information':
  1318.                    filepath = os.path.join(path, filename)
  1319.                    PrintBox('filename is ' + filename + '\n  transferring... ' + filepath)
  1320.                    logging.info('[' + time.strftime("%H:%M") + ']|> backing up : ' + filepath)
  1321.                    sftp.get(filepath, filepath)
  1322.  
  1323.    os.chdir('..')
  1324.    PrintBox('Please clear reports from Nexgen device')
  1325.    wait()
  1326.    logging.info('[' + time.strftime("%H:%M") + ']|> finished pre wipe backup...')
  1327.    logging.info('[' + time.strftime("%H:%M") + ']|> removing files...')
  1328.  
  1329.    RemoveConfig()
  1330.    for elem in sftp.listdir('/var/permalog/'):
  1331.        sftp.remove('/var/permalog/'+elem)
  1332.  
  1333.    os.chdir('L:\\')
  1334.    logging.info('[' + time.strftime("%H:%M") + ']|> L drive set to :  ' + Ldrive)
  1335.    logging.info('[' + time.strftime("%H:%M") + ']|> creating subfolders...')
  1336.    CreateOSFolder([
  1337.        Ldrive+'\Post_Wipe',
  1338.        Ldrive+'\Post_Wipe\etc', Ldrive+'\Post_Wipe\etc\ptsenv', Ldrive+r'\Post_Wipe\etc\unique',
  1339.        Ldrive+'\Post_Wipe\\var', Ldrive+'\Post_Wipe\\var\permalog',
  1340.        Ldrive+'\Post_Wipe\home', Ldrive+'\Post_Wipe\home\localdata'
  1341.        ])
  1342.  
  1343.    sftp.chdir('/etc/')
  1344.    os.chdir(Ldrive+'\Post_Wipe\etc')
  1345.    path = 'ptsenv/'
  1346.    PrintDirs()
  1347.    print('Backing up ptsenv folder...')
  1348.    for filename in sftp.listdir('ptsenv'):
  1349.        if filename == 'BATTERY.log':
  1350.            sftp.remove('BATTERY.log')
  1351.        elif filename != 'wpa_supplicant.d':
  1352.            filepath = os.path.join(path, filename)
  1353.            PrintBox('filename is ' + filename + '\n  transferring... ' + filepath)
  1354.            logging.info('[' + time.strftime("%H:%M") + ']|> backing up : ' + filepath)
  1355.            sftp.get(filepath, filepath)
  1356.  
  1357.    path ='unique/'
  1358.    PrintDirs()
  1359.    print('Backing up unique folder....')
  1360.    for filename in sftp.listdir('unique'):
  1361.        filepath = os.path.join(path, filename)
  1362.        PrintBox('filename is ' + filename + '\n  transferring... ' + filepath)
  1363.        logging.info('[' + time.strftime("%H:%M") + ']|> backing up : ' + filepath)
  1364.        sftp.get(filepath, filepath)
  1365.    os.chdir('..')
  1366.  
  1367.    sftp.chdir('/home/')
  1368.    os.chdir('home')
  1369.    PrintDirs()
  1370.    path = 'localdata/'
  1371.    print('Backing up localdata folder....')
  1372.    for filename in sftp.listdir('localdata'):
  1373.        if 'PTS' in filename:
  1374.            filepath = os.path.join(path, filename)
  1375.            PrintBox('filename is ' + filename + '\n  transferring... ' + filepath)
  1376.            logging.info('[' + time.strftime("%H:%M") + ']|> backing up : ' + filepath)
  1377.            sftp.get(filepath, filepath)
  1378.    os.chdir('..')
  1379.  
  1380.    sftp.chdir('/var/')
  1381.    os.chdir('var')
  1382.    path ='permalog/'
  1383.    PrintDirs()
  1384.  
  1385.    print('Backing up permalog folder....')
  1386.    for filename in sftp.listdir('permalog'):
  1387.        if filename != 'Templates':
  1388.            if filename != 'System Volume Information':
  1389.                filepath = os.path.join(path, filename)
  1390.                PrintBox('filename is ' + filename + '\n  transferring... ' + filepath)
  1391.                logging.info('[' + time.strftime("%H:%M") + ']|> backing up : ' + filepath)
  1392.                sftp.get(filepath, filepath)
  1393.  
  1394.    os.chdir('..')
  1395.    Clear()
  1396.    PrintBox('PTSenv & Permalog files backed up')
  1397.    HomeFolder()
  1398.    Reboot()
  1399.    Clear()
  1400.  
  1401.  
  1402. def ImageCapture():
  1403.    CheckSSH()
  1404.    HomeFolder()
  1405.    sftp.chdir('/usr/local/bin')
  1406.    Log('Running ImageCapture() ')
  1407.    PrintBox('Capturing screenshot, please wait..')
  1408.    try:
  1409.        sftp.stat('fbimage')
  1410.    except IOError as e:
  1411.        Log('file not found, transferring now')
  1412.        sftp.put('fbimage','/usr/local/bin/fbimage')
  1413.    else:
  1414.        print('')
  1415.    time.sleep(5)
  1416.    Log('setting permissions')
  1417.    cmd = "chmod 777 /usr/local/bin/fbimage"
  1418.    stdin, stdout, stderr = ssh.exec_command(cmd)
  1419.    setImage = stdout.read().strip().decode(encoding='utf-8')
  1420.    print(setImage)
  1421.    time.sleep(10)
  1422.    Log('taking screenshot')
  1423.    cmd = "/usr/local/bin/fbimage -d /dev/fb0 /usr/local/bin/image.png"
  1424.    stdin, stdout, stderr = ssh.exec_command(cmd)
  1425.    screenShot = stdout.read().strip().decode(encoding='utf-8')
  1426.    print(screenShot)
  1427.    PrintBox('Screenshot captured')
  1428.    Clear()
  1429.    HomeFolder()
  1430.    PrintBox('Transferring to computer..')
  1431.    screenCapture = './screenCaptures/'+ SERIAL + '[' + time.strftime("%m_%d_%Y__%H-%M") + '].png'
  1432.    sftp.get('/usr/local/bin/image.png',screenCapture)
  1433.    time.sleep(5)
  1434.    im = Image.open(screenCapture)
  1435.    im.transpose(Image.ROTATE_90).save(screenCapture)
  1436.    sftp.remove('/usr/local/bin/image.png')
  1437.  
  1438. def SendMail():
  1439. #    FROM = "Nexgen-Utility@crl.com"
  1440. #    TO = "Brandon.Dangerfield@crl.com"
  1441.    # Create message container - the correct MIME type is multipart/alternative.
  1442.  
  1443.    Log('Sending Mail....')
  1444.    s = smtplib.SMTP('smtp.cr.local')
  1445.  
  1446.    msg = MIMEMultipart('alternative')
  1447.  
  1448.    #email list
  1449.  
  1450.  
  1451.    msg['Subject'] = "Nexgen-PTS ERROR [SERIAL - %s]"%(SERIAL)
  1452.    msg['From'] = 'Nexgen-Utility@crl.com'
  1453.    msg['To'] = "brandon.dangerfield@crl.com, jason.tremblay@crl.com"
  1454.  
  1455.    # Create the body of the message (a plain-text and an HTML version).
  1456.    text = """
  1457.             The system below has encountered an error
  1458.             The log file attached may not be up to date, please use ctrl+f to find the IP or SERIAL to find information on this unit.
  1459.  
  1460.                     System Information1
  1461.                     Serial :        %s
  1462.                     IP Address :    %s
  1463.                     System Version: %s
  1464.                     App Version:    %s
  1465.         """ %(SERIAL,host,Version_System,Version_App)
  1466.    html = """\
  1467.     <html>
  1468.       <head></head>
  1469.       <body>
  1470.         The system below has encountered an error<br>
  1471.         The log file attached may not be up to date! <br><br>
  1472.             <table>
  1473.               <tr>
  1474.                 <th colspan="2"><b><u><h1>System Information</h1></u></b></th>
  1475.               </tr>
  1476.               <tr>
  1477.                 <td><b>Serial</b></td>
  1478.                 <td>%s</td>
  1479.               </tr>
  1480.               <tr>
  1481.                 <td><b>IP Address</b></td>
  1482.                 <td>%s</td>
  1483.               </tr>
  1484.               <tr>
  1485.                 <td><b>System Version</b></td>
  1486.                 <td>%s</td>
  1487.               </tr>
  1488.               <tr>
  1489.                 <td><b>App Version</b></td>
  1490.                 <td>%s</td>
  1491.               </tr>
  1492.             </table>
  1493.       </body>
  1494.     </html>
  1495.     """%(SERIAL,host,Version_System,Version_App)
  1496.    # Record the MIME types of both parts - text/plain and text/html.
  1497.    part1 = MIMEText(text, 'plain')
  1498.    part2 = MIMEText(html, 'html')
  1499.    part3 = MIMEApplication(open(Logname,"rb").read())
  1500.    part3.add_header('Content-Disposition', 'attachment', filename=Logname)
  1501.    # Attach parts into message container.
  1502.    # According to RFC 2046, the last part of a multipart message, in this case
  1503.    # the HTML message, is best and preferred.
  1504.    msg.attach(part1)
  1505.    msg.attach(part2)
  1506.    msg.attach(part3)
  1507.  
  1508.    # sendmail function takes 3 arguments: sender's address, recipient's address
  1509.    # and message to send - here it is sent as one string.
  1510.    s.sendmail(msg['From'],["brandon.dangerfield@crl.com", "jason.tremblay@crl.com"], msg.as_string())
  1511.    s.quit()
  1512.  
  1513. def ResizeWindow():
  1514.    os.system('mode con: cols=90 lines=75')
  1515.  
  1516. #s = smtplib.SMTP('smtp.uk.xensource.com')
  1517. #s.set_debuglevel(1)
  1518. #msg = MIMEText("""body""")
  1519. ##sender = 'me@example.com'
  1520. #recipients = ['john.doe@example.com', 'john.smith@example.co.uk']
  1521. #msg['Subject'] = "subject line"
  1522. #msg['From'] = sender
  1523. ##msg['To'] = ", ".join(recipients)
  1524. #s.sendmail(sender, recipients, msg.as_string())
  1525.  
  1526.  
  1527. #################################
  1528. #                               #
  1529. #    Options / ETC below        #
  1530. #                               #
  1531. #################################
  1532. CreateOSFolder(['screenCaptures','logs','temp','temp/unique','temp/ptsenv','temp/ptsenv/wpa_supplicant.d','temp/localdata'])
  1533.  
  1534. #Logging
  1535. Logname='./logs/Nexgen_Utility_Log_'+(time.strftime("%Y-%m-%d_%H-%M")+'.log')
  1536. logging.basicConfig(filename=Logname,level=logging.INFO)
  1537. logging = logging.getLogger(__name__)
  1538.  
  1539. def main():
  1540.    Options()
  1541.  
  1542. def Options():
  1543.    Clear()
  1544. #    ResizeWindow()
  1545.    Log('Loading main...' + '\n' +
  1546.        '                  ' + '\n' +
  1547.        '                  Host          : ' + host + '\n'+
  1548.        '                  App Version   :' + Version_App + '\n'+
  1549.        '                  Serial Number : ' + SERIAL + '\n')
  1550.    print("""
  1551. ______________________________________
  1552. |                                     |
  1553. |       Nexgen Update Utility         |
  1554. |             v 1.3.3                 |
  1555. |_____________________________________|
  1556.  
  1557.  
  1558.  
  1559. Validated to install/upgrade version 10.1!
  1560.  
  1561.     """)
  1562.  
  1563.    print('    The current working directory...')
  1564.    print('  ' + os.getcwd())
  1565.  
  1566.    PrintBox('        IP Address :  ' + host + \
  1567.             '\nApplication version : ' + Version_App + \
  1568. #             '\n     System Version :  '+ Version_System + \
  1569.             '\n      Serial Number :  ' + SERIAL)
  1570.    menu = {}
  1571.    print('Please choose one of the options below...\n')
  1572.    menu['[1]']="Set or Change IP Address"
  1573.    menu['[2]']="Get Set Point Value"
  1574.    menu['[3]']="Upgrade"
  1575.    menu['[4]']="Enable Test mode"
  1576.    menu['[5]']="Disable Test Mode"
  1577.    menu['[6]']="Backup files & Clean Unit \n______________________\n"
  1578.    menu['[7]']="Fix Config.sav"
  1579.    menu['[8]']="Take Screenshot \n______________________\n"
  1580.    menu['[9]']="Launch PuTTY \n______________________\n"
  1581.    menu['[w]']="Set Wifi Model"
  1582.    menu['[x]']="Exit"
  1583.    while True:
  1584.        main=list(menu.keys())
  1585.        main.sort()
  1586.        for entry in main:
  1587.            print(entry, menu[entry])
  1588.        selection=input("\nPlease Select: ")
  1589.        if selection =="1":
  1590.            logging.info('[' + time.strftime("%H:%M") + ']|> User selected [1]...')
  1591.            Clear()
  1592.            GetHost()
  1593.            Options()
  1594.        elif selection == '2':
  1595.            logging.info('[' + time.strftime("%H:%M") + ']|> User selected [2]...')
  1596.            Clear()
  1597.            GetTemp()
  1598.            Options()
  1599.        elif selection == '3':
  1600.            logging.info('[' + time.strftime("%H:%M") + ']|> User selected [3]...')
  1601.            Clear()
  1602.            #CheckUpdateSW()
  1603.            MountCheck()
  1604.            #Reboot()
  1605.            Options()
  1606.        elif selection == '4':
  1607.            logging.info('[' + time.strftime("%H:%M") + ']|> User selected [4]...')
  1608.            Clear()
  1609.            EnableTest()
  1610.            CheckSD()
  1611.            Options()
  1612.        elif selection == '5':
  1613.            logging.info('[' + time.strftime("%H:%M") + ']|> User selected [5]...')
  1614.            Clear()
  1615.            DisableTest()
  1616.            Options()
  1617.        elif selection == '6':
  1618.            logging.info('[' + time.strftime("%H:%M") + ']|> User selected [6]...')
  1619.            CheckSSH()
  1620.            CheckSD()
  1621.            Copy2Remote()
  1622.            Options()
  1623.        elif selection == '7':
  1624.            Log('User selected [7]')
  1625.            Clear()
  1626.            EnableTest()
  1627.            sftp.remove('/etc/ptsenv/CONFIG.sav')
  1628.            Clear()
  1629.            DisableTest()
  1630.            Options()
  1631.        elif selection == '8':
  1632.            Log('User selected [8]')
  1633.            Clear()
  1634.            ImageCapture()
  1635.            Clear()
  1636.            Options()
  1637.        elif selection == '9':
  1638.            Log('User selected [9]')
  1639.            Clear()
  1640.            PuTTY()
  1641.            Options()
  1642.        elif selection == '77':
  1643.            Log('User selected [77]')
  1644.            SendMail()
  1645.            Options()
  1646.        elif selection == 'w':
  1647.            Log('User selected [w]')
  1648.            WifiCheck()
  1649.            Options()
  1650.        elif selection == 'x':
  1651.            logging.info('[' + time.strftime("%H:%M") + ']|> ________________________________________')
  1652.            logging.info('[' + time.strftime("%H:%M") + ']|> User selected [99]...')
  1653.            logging.info('[' + time.strftime("%H:%M") + ']|> CLOSING...')
  1654.            logging.info('[' + time.strftime("%H:%M") + ']|> ________________________________________')
  1655.            exit()
  1656.  
  1657.        elif selection == 't':
  1658.            RemoveConfig()
  1659.            Options()
  1660.  
  1661.        else:
  1662.            print("\nUnknown Option Selected!\n")
  1663.            logging.info('[' + time.strftime("%H:%M") + ']|> ________________________________________')
  1664.            logging.info('[' + time.strftime("%H:%M") + ']|> User  input invalid selection...')
  1665.            logging.info('[' + time.strftime("%H:%M") + ']|> ________________________________________')
  1666.            wait()
  1667.            Clear()
  1668.            Options()
  1669.  
  1670. #####################################
  1671. #                                   #
  1672. #     -Calling Functions-           #
  1673. #                                   #
  1674. #####################################
  1675. Clear()
  1676. if __name__ == Options():
  1677.    Options()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement