Advertisement
eudemonics

opotoolkit.py v1.3.3.7 BETA - toolkit for android/oneplusone

Feb 9th, 2015
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 74.36 KB | None | 0 0
  1. #!/usr/bin/env python
  2. ### HALF-ASSED ONE + ONE TOOLKIT
  3. ##### VERSION: 1.3.3.7 BETA
  4. ##### RELEASE DATE: FEBRUARY 06, 2015
  5. ##### AUTHOR: vvn [eudemonics on xda-developers]
  6. ##### DESCRIPTION: a spontaneously created but hopefully comprehensive Android toolkit,
  7. ##### built originally for the OnePlus One but can be used with most Android devices
  8. ##### (DO NOT FLASH INCLUDED ONEPLUS ONE DEVICE FILES ON OTHER DEVICES!), that will or
  9. ##### will not be irregularly maintained at the developer's whim.
  10. ##### REQUIREMENTS: Python 2.7, Android SDK tools, USB drivers, pyadb.py library, opointro.py
  11. ##### also required, obviously, is a computer that runs an OS that supports python 2.7.
  12. ##### HOLY SHIT GITHUB IS FINALLY WORKING!
  13. ##### INSTALL INSTRUCTIONS USING GIT:
  14. ##### enter command into terminal:
  15. ##### git clone https://github.com/eudemonics/1plus1toolkit.git 1plus1toolkit
  16. ##### to run after using git clone (without $ sign):
  17. #####   $ cd 1plus1toolkit
  18. #####   $ python opotoolkit.py
  19. #####
  20. ##### VIEW IN BROWSER:
  21. ##### https://github.com/eudemonics/1plus1toolkit
  22. #####
  23. ##### UPDATE VIA GIT:
  24. ##### cd 1plus1toolkit
  25. ##### git pull https://github.com/eudemonics/1plus1toolkit.git
  26. ##################################################
  27. ##################################################
  28. ##### USER LICENSE AGREEMENT & DISCLAIMER
  29. ##### copyright (C) 2014  vvn <vvn @ notworth.it>
  30. #####
  31. ##### This program is FREE software: you can use it, redistribute it and/or modify
  32. ##### it as you wish. Copying and distribution of this file, with or without modification,
  33. ##### are permitted in any medium without royalty provided the copyright
  34. ##### notice and this notice are preserved. This program is offered AS-IS,
  35. ##### WITHOUT ANY WARRANTY; without even the implied warranty of
  36. ##### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  37. ##### GNU General Public License for more details.
  38. #####
  39. ##### For more information, please refer to the "LICENSE AND NOTICE" file that should
  40. ##### accompany all official download releases of this program.
  41. ##################################################
  42. ##################################################
  43. ##### don't ask about the arbitrary versioning. i am totally making this shit up.
  44. ##### getting credited for my work is nice. so are donations.
  45. ##### BTC: 1M511j1CHR8x7RYgakNdw1iF3ike2KehXh
  46. ##### https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=26PWMPCNKN28L
  47. ##### but to really show your appreciation, you should buy my EP instead!
  48. ##### you can stream and purchase it at: dreamcorp.bandcamp.com
  49. ##### (you might even enjoy listening to it)
  50. ##### questions, comments, feedback, bugs, complaints, death threats, marriage proposals?
  51. ##### contact me at:
  52. ##### vvn (at) notworth (dot) it
  53. ##### latest version will always be available HERE:
  54. ##### https://github.com/eudemonics/1plus1toolkit
  55.  
  56. import subprocess, sys, re, os, os.path, hashlib, time, datetime, urllib
  57. from opointro import *
  58. from pyadb import *
  59. global usecolor
  60. if os.name == 'nt' or sys.platform == 'win32':
  61.    try:
  62.       import colorama
  63.       colorama.init()
  64.       s = opointro()
  65.       s.colorlogo()
  66.       startmenu = s.colormenu
  67.       usecolor = 'color'
  68.    except:
  69.       try:
  70.          import tendo.ansiterm
  71.          s = opointro()
  72.          s.colorlogo()
  73.          startmenu = s.colormenu
  74.          usecolor = 'color'
  75.       except:
  76.          s = opointro()
  77.          s.cleanlogo()
  78.          startmenu = s.cleanmenu
  79.          usecolor = 'clean'
  80.          pass
  81. else:
  82.    s = opointro()
  83.    s.colorlogo()
  84.    startmenu = s.colormenu
  85.    usecolor = 'color'
  86.  
  87. def mainmenu():
  88.    print(startmenu)
  89.  
  90. def main():
  91.    os.system('cls' if os.name == 'nt' else 'clear')
  92.    mainmenu()
  93.  
  94.    global option
  95.    option = raw_input('Select an option 0-14 --> ')
  96.    
  97.    while not re.search(r'^[0-9]$', option) and not re.search(r'^1[0-4]$', option):
  98.       option = raw_input('Invalid selection. Please select an option 0-14 --> ')
  99.  
  100.    if option:
  101.  
  102.       obj = pyADB()
  103.  
  104.       if option == '1': #reboot      
  105.          rboption = raw_input("please enter 1 to reboot into android. enter 2 to reboot to bootloader. enter 3 to reboot to recovery. --> ")
  106.          while not re.search(r'^[123]$', rboption):
  107.             rboption = raw_input("invalid selection. please enter 1 to reboot into android, 2 for bootloader, and 3 for recovery. --> ")
  108.          rbtype = "android"
  109.          if rboption == '1':
  110.             rbtype = "android"
  111.          elif rboption == '2':
  112.             rbtype = "bootloader"
  113.          elif rboption == '3':
  114.             rbtype ="recovery"
  115.          checkdev = obj.get_state()
  116.          listdev = obj.attached_devices()
  117.          fastdev = obj.fastboot_devices()
  118.          if "device" in str(checkdev) and listdev is not None and "fastboot" not in str(fastdev):
  119.             print("rebooting via ADB..\n")
  120.             obj.reboot(rbtype)
  121.             time.sleep(0.9)
  122.             main()
  123.          elif "unknown" in str(checkdev) and "fastboot" in str(fastdev):
  124.             print("rebooting via fastboot..\n")
  125.             if rboption == '3':
  126.                rbtype = "bootloader"
  127.             obj.fastreboot(rbtype)
  128.             time.sleep(0.9)
  129.             main()
  130.          elif "unknown" in str(checkdev) and listdev is not None and "device" in str(fastdev):
  131.             print("rebooting via ADB..\n")
  132.             obj.reboot(rbtype)
  133.             time.sleep(0.9)
  134.             main()
  135.          elif "recovery" in [str(fastdev), str(listdev)] and checkdev is not None:
  136.             print("rebooting via ADB...\n")
  137.             obj.reboot(rbtype)
  138.             time.sleep(0.9)
  139.             main()
  140.          elif "unknown" in str(checkdev) and fastdev is not None and listdev is None:
  141.             print("rebooting via fastboot...\n")
  142.             if rboption == '3':
  143.                rbtype = "bootloader"
  144.             obj.fastreboot(rbtype)
  145.             time.sleep(0.9)
  146.             main()
  147.          elif "unknown" in str(checkdev) and "unauthorized" in str(listdev):
  148.             raw_input("verify that DEVICE IS UNLOCKED and COMPUTER IS AUTHORIZED FOR ADB ACCESS, then press ENTER.")
  149.             print("rebooting via ADB...\n")
  150.             obj.reboot(rbtype)
  151.             time.sleep(0.9)
  152.             main()
  153.          elif "unknown" in str(checkdev) and listdev is not None and fastdev is None:
  154.             raw_input("device appears to be in recovery mode. reboot from recovery menu, then press ENTER.")
  155.             checkstate = obj.get_state()
  156.             if "device" in str(checkstate):
  157.                obj.reboot(rbtype)
  158.             time.sleep(0.9)
  159.             main()
  160.          else:
  161.             print("rebooting via fastboot....\n")
  162.             if rboption == '3':
  163.                rbtype = "bootloader"
  164.             fastreboot = obj.fastreboot(rbtype)
  165.             if not fastreboot:
  166.                print("rebooting via ADB after fastboot... \n")
  167.                obj.reboot(rbtype)
  168.                if "error" in str(fastreboot):
  169.                   print("rebooting via fastboot second time...\n")
  170.                   obj.fastreboot(rbtype)
  171.             time.sleep(0.9)
  172.             main()
  173.  
  174.       elif option == '2': #wipe
  175.          print("\033[35m***WIPING SOME PARTITIONS WILL ERASE YOUR DATA.***\n please make sure to back up any important data before proceeding!\n\n")
  176.          print('''\033[36mCHOOSE AN OPTION 1-8:\033[32m\n
  177.   [1]\033[37m perform a full system wipe [system, data, and cache partitions]\033[32m
  178.   [2]\033[37m wipe only the system partition\033[32m
  179.   [3]\033[37m wipe only the data partition\033[32m
  180.   [4]\033[37m wipe only the cache partition\033[32m
  181.   [5]\033[37m wipe only the boot partition\033[32m
  182.   [6]\033[37m wipe only the recovery partition\033[32m
  183.   [7]\033[37m flash device to factory images [flash system, boot, and recovery]\033[32m
  184.   [8]\033[37m return to main menu\n\n\033[0m''')
  185.          confirmwipe = raw_input("please enter an option 1-8 --> ")
  186.          while not re.search(r'^[1-8]$', confirmwipe):
  187.             confirmwipe = raw_input('not a valid option. please enter a selection between 1-8 from above choices -->')        
  188.          if confirmwipe == '1':
  189.             obj.wipe('all')
  190.             raw_input("press ENTER to continue.")
  191.             time.sleep(0.9)
  192.             main()
  193.          elif confirmwipe == '2':
  194.             obj.wipe('system')
  195.             raw_input("press ENTER to continue.")
  196.             time.sleep(0.9)
  197.             main()
  198.          elif confirmwipe == '3':
  199.             obj.wipe('data')
  200.             raw_input("press ENTER to continue.")
  201.             time.sleep(0.9)
  202.             main()
  203.          elif confirmwipe == '4':
  204.             obj.wipe('cache')
  205.             raw_input("press ENTER to continue.")
  206.             time.sleep(0.9)
  207.             main()
  208.          elif confirmwipe == '5':
  209.             obj.wipe('boot')
  210.             raw_input("press ENTER to continue.")
  211.             time.sleep(0.9)
  212.             main()
  213.          elif confirmwipe == '6':
  214.             obj.wipe('recovery')
  215.             raw_input("press ENTER to continue.")
  216.             time.sleep(0.9)
  217.             main()
  218.          elif confirmwipe == '7':
  219.             obj.wipe('flashall')
  220.             raw_input("press ENTER to continue.")
  221.             time.sleep(0.9)
  222.             main()
  223.          elif confirmwipe == '8':
  224.             time.sleep(0.9)
  225.             main()
  226.          else:
  227.             print("there was a problem connecting to the device. returning to menu..\n")
  228.             time.sleep(0.9)
  229.             main()
  230.            
  231.                          
  232.       elif option == '3': #boot custom recovery
  233.          recovery = raw_input("enter 1 for TWRP, 2 for ClockworkMod, or 3 for Philz recovery --> ")
  234.          while not re.search(r'^[1-3]$', recovery):
  235.             recovery = raw_input("invalid selection. please choose 1 for TWRP, 2 for CWM, or 3 for Philz --> ")
  236.          def dlrecov(recovfile):
  237.             dlfile = "http://notworth.it/opo/" + recovfile
  238.             dl = urllib.URLopener()
  239.             dl.retrieve(dlfile, recovfile)
  240.             site = urllib.urlopen(dlfile)
  241.             meta = site.info()
  242.             dlsize = meta.getheaders("Content-Length")[0]
  243.             fsize = os.path.getsize(recovfile)
  244.             print("file size: \033[33m")
  245.             print(dlsize)
  246.             print("\n\033[0mbytes downloaded: \033[33m")
  247.             print(fsize)
  248.             print("\033[0m\n")
  249.          obj.reboot("bootloader")
  250.          if recovery == '1':
  251.             recovfile = "twrp.img"
  252.             while not os.path.isfile(recovfile):
  253.                print("file \033[32mtwrp.img \033[0mnot found. attempting download...\n")
  254.                dlrecov(recovfile)
  255.             print("file \033[32mtwrp.img \033[0mfound!\n")
  256.             raw_input("press ENTER to continue booting into TWRP..")
  257.             obj.bootimg("twrp.img")
  258.          elif recovery == '2':
  259.             recovfile = "cwm.img"
  260.             while not os.path.isfile(recovfile):
  261.                print("file \033[32mcwm.img \033[0mnot found. attempting download...\n")
  262.                dlrecov(recovfile)
  263.             print("file \033[32mcwm.img \033[0mfound!\n")
  264.             raw_input("press ENTER to continue booting into ClockworkMod Recovery..")
  265.             obj.bootimg("cwm.img")
  266.          elif recovery == '3':
  267.             recovfile = "philz.img"
  268.             while not os.path.isfile(recovfile):
  269.                print("file \033[32mphilz.img \033[0mnot found. attempting download...\n")
  270.                dlrecov(recovfile)
  271.             print("file \033[32mphilz.img \033[0mfound!\n")
  272.             raw_input("press ENTER to continue booting into Philz Recovery..")
  273.             obj.bootimg("philz.img")
  274.          else:
  275.             print("unable to connect to device.\n")    
  276.            
  277.          raw_input("press ENTER to return to main menu..")
  278.          time.sleep(0.9)
  279.          main()
  280.  
  281.       elif option == '4': #install or uninstall APK
  282.          whichinstall = raw_input("please enter 1 to install, 2 to uninstall, or 3 to return to main menu. --> ")
  283.          while not re.search(r'^[1-3]$', whichinstall):
  284.             whichinstall = raw_input("invalid selection. please enter 1 to install, 2 to uninstall, or 3 to return to main menu. --> ")
  285.          if not os.path.exists('apps'):
  286.             os.makedirs('apps')
  287.          if whichinstall == '1':
  288.             getapk = raw_input("place the APK file to install in the \"apps\" subdirectory, then type the filename --> ")
  289.             apkfile = os.path.join('apps', getapk)
  290.             while not os.path.isfile(apkfile):
  291.                print("\033[37mfile does not exist. please make sure the APK file is in the \"apps\" subdirectory.\033[0m\n")
  292.                getapk = raw_input("enter valid filename for the APK you want to install -->")
  293.                apkfile = os.path.join('apps', getapk)
  294.             print("installing \033[36m" + getapk + "\033[0m...")
  295.             obj.install(apkfile)
  296.             raw_input("press ENTER to continue...")
  297.             time.sleep(0.9)
  298.             main()
  299.            
  300.          if whichinstall == '2':
  301.             getunapk = raw_input("please enter the complete path for the app you wish to uninstall --> ")
  302.             keepcheck = raw_input("would you like to keep your app data? Y or N --> ")
  303.             while not re.search(r'^[nyNY]$', keepcheck):
  304.                keepcheck = raw_input("invalid selection. please enter Y to keep app data or N to erase --> ")
  305.             keepargs = "erase"
  306.             uninstcmd = "pm uninstall " + getunapk
  307.             if re.match(r'(?i)Y', keepcheck):
  308.                keepargs = "keep"
  309.                uninstcmd = "pm uninstall -k " + getunapk
  310.             print("uninstalling \033[36m" + getunapk + "\033[0m...\n")
  311.             obj.uninstall(getunapk, keepargs)
  312.             obj.shell(uninstcmd)
  313.             raw_input("press ENTER to continue...")
  314.             time.sleep(0.9)
  315.             main()
  316.            
  317.          if whichinstall == '3':
  318.             main()
  319.            
  320.          else:
  321.             print("could not connect to device.\n")
  322.             time.sleep(0.9)
  323.             main()
  324.  
  325. ############################################################
  326. ############################################################
  327. # OPTION 5: COPY/SYNC FILES BETWEEN DEVICE & COMPUTER #
  328. ############################################################
  329. ############################################################
  330.  
  331.       elif option == '5': #copy and/or sync between computer and device
  332.          copytype = raw_input("to push file from computer to device, enter T. to pull file from device to computer, enter F. to sync, enter S --> ")
  333.          matchT = re.search(r'(?i)T', copytype)
  334.          matchF = re.search(r'(?i)F', copytype)
  335.          matchS = re.search(r'(?i)S', copytype)
  336.          while not re.search(r'^[FfSsTt]$', copytype):
  337.             copytype = raw_input("invalid option. please enter T to push file, F to pull file, or S to sync --> ")
  338.            
  339.          if matchT:
  340.             getpushfile = raw_input("please enter the file or directory you wish to copy as the RELATIVE path from the script location --> ")
  341.             while not os.path.exists(getpushfile):
  342.                getpushfile = raw_input("file does not exist. please enter valid path --> ")
  343.             getpushremote = raw_input("please enter destination path for copied file(s) on the device --> ")
  344.             obj.push(getpushfile, getpushremote)
  345.             raw_input("file transfer complete. press ENTER to continue...")
  346.            
  347.          elif matchF:
  348.             getpullfile = raw_input("please enter path for the file or directory on your device to copy --> ")
  349.             getpulllocal = raw_input("please enter the copy destination folder as a RELATIVE path from the script location --> ")
  350.             if not os.path.exists(getpulllocal):
  351.                print("copy destination \033[35m" + getpulllocal + " \033[0mdoes not exist! creating new directory...")
  352.                os.makedirs(getpulllocal)
  353.             obj.pull(getpullfile, getpulllocal)
  354.             print("\033[32mtransferred file(s) in destination directory:\n")
  355.             for fn in next(os.walk(getpulllocal))[2]:
  356.                fullpath = os.path.join(getpulllocal, fn)
  357.                if os.path.getmtime(fullpath) >= os.path.getctime(getpulllocal):
  358.                   print(fullpath)
  359.             print("\033[0m\n")
  360.             raw_input("file transfer complete. press ENTER to continue...")
  361.            
  362.          elif matchS:
  363.             syncargs = raw_input("enter 1 to set sync directory, or 2 to sync the default system and data directories. --> ")
  364.             while not re.search(r'^[12]$', syncargs):
  365.                syncargs = raw_input("invalid selection. please enter 1 to set sync directory, or 2 to use default. --> ")
  366.             if syncargs == '1':
  367.                syncdir = raw_input("please enter sync directory --> ")
  368.                localargs = raw_input("enter 1 to set local sync directory, or 2 to use default ANDROID_PRODUCT_OUT --> ")
  369.                while not re.search(r'^[12]$',localargs):
  370.                   localargs = raw_input("invalid selection. enter 1 to set local sync directory or 2 to use default ANDROID_PRODUCT_OUT --> ")
  371.                if localargs == '1':
  372.                   localdir = raw_input("please enter relative path for local directory to sync device --> ")
  373.                   while not os.path.exists(localdir):
  374.                      print("the path you entered does not exist. would you like to create " + localdir + " as a new directory?\n")
  375.                      crlocaldir = raw_input("enter 1 to create new directory or 2 to enter another location. --> ")
  376.                      while not re.search(r'^[12]$', crlocaldir):
  377.                         crlocaldir = raw_input("invalid selection. please enter 1 to create directory, or 2 to enter another location. --> ")
  378.                      if crlocaldir == '1':
  379.                         os.makedirs(localdir, 0755)
  380.                      else:
  381.                         localdir = raw_input("please enter relative path for local directory to sync device with --> ")
  382.                   localsyncdir = os.path.join(localdir, syncdir)
  383.                   while not os.path.exists(localsyncdir):
  384.                      os.makedirs(localsyncdir, 0755)
  385.                      print(localsyncdir + " created\n")
  386.                else:
  387.                   localdir = "none"
  388.                obj.sync(localdir, syncdir)
  389.                if "none" not in localdir:
  390.                   print("\033[32mfile(s) in sync directory:\n")
  391.                   for fn in next(os.walk(localdir))[2]:
  392.                      fullpath = os.path.join(localdir, fn)
  393.                      if os.path.getmtime(fullpath) >= os.path.getctime(localdir):
  394.                         print(fullpath)
  395.                   print("\033[0m\n")
  396.                raw_input("press ENTER to continue...")
  397.             elif syncargs == '2':
  398.                # obj.sync()
  399.                localargs = raw_input("enter 1 to set local sync directory, or 2 to use default ANDROID_PRODUCT_OUT --> ")
  400.                while not re.search(r'^[12]$',localargs):
  401.                   localargs = raw_input("invalid selection. enter 1 to set local sync directory or 2 to use default ANDROID_PRODUCT_OUT --> ")
  402.                if localargs == '1':
  403.                   localdir = raw_input("please enter relative path for local directory to sync device --> ")
  404.                   while not os.path.exists(localdir):
  405.                      print("the path you entered does not exist. would you like to create " + localdir + " as a new directory?\n")
  406.                      crlocaldir = raw_input("enter 1 to create new directory or 2 to enter another location. --> ")
  407.                      while not re.search(r'^[12]$', crlocaldir):
  408.                         crlocaldir = raw_input("invalid selection. please enter 1 to create directory, or 2 to enter another location. --> ")
  409.                      if crlocaldir == '1':
  410.                         os.makedirs(localdir, 0755)
  411.                      else:
  412.                         localdir = raw_input("please enter relative path for local directory to sync device with --> ")
  413.                else:
  414.                   localdir = "none"
  415.                obj.sync(localdir, "none")
  416.                raw_input("press ENTER to continue...")
  417.             else:
  418.                print("could not connect to device.\n")
  419.          
  420.          else:
  421.             print("could not connect to device.\n")
  422.            
  423.          time.sleep(0.9)
  424.          main()
  425.  
  426. ############################################################
  427. ############################################################
  428. # OPTION 6 - BACKUP OR RESTORE #
  429. ############################################################
  430. ############################################################
  431.  
  432.       elif option == '6': #backup
  433.          whichbackup = raw_input("to backup, enter 1. to restore, enter 2 --> ")
  434.          while not re.search(r'^[12]$', whichbackup):
  435.             whichbackup = raw_input("invalid selection. please enter 1 to backup or 2 to restore. --> ")
  436.          if whichbackup == '1':
  437.             fullbackup = raw_input("would you like to do a full backup, including system apps and sdcard contents? enter Y or N --> ")
  438.             while not re.search(r'^[yYnN]$', fullbackup):
  439.                fullbackup = raw_input("invalid selection. please enter Y for full backup or N for other options --> ")
  440.             if fullbackup.lower() == 'y':
  441.                backapk = "apk"
  442.                backobb = "obb"
  443.                backshared = "shared"
  444.                backall = "full"
  445.                backsys = "sys"
  446.             else:
  447.                checkapk = raw_input("enter 1 to include APK files, or 2 to exclude --> ")
  448.                while not re.search(r'^[12]$', checkapk):
  449.                   checkapk = raw_input("invalid selection. enter 1 to include APK files, or 2 to exclude --> ")
  450.                if checkapk == '1':
  451.                   backapk = "apk"
  452.                   checkobb = raw_input("enter 1 to include APK expansion files, or 2 to exclude --> ")
  453.                   while not re.search(r'^[12]$', checkobb):
  454.                      checkobb = raw_input("invalid selection. enter 1 to include APK expansion files, or 2 to exclude --> ")
  455.                   if checkobb == '1':
  456.                      backobb = "obb"
  457.                   else:
  458.                      backobb = "no"
  459.                else:
  460.                   backapk = "no"
  461.                checkshared = raw_input("enter 1 to backup sdcard [userdata] contents, or 2 to exclude --> ")
  462.                while not re.search(r'^[12]$', checkshared):
  463.                   checkshared = raw_input("invalid selection. enter 1 to backup sdcard contents, or 2 to exclude --> ")
  464.                if checkshared == '1':
  465.                   backshared = "shared"
  466.                   checkall = raw_input("enter 1 to backup all installed applications, or 2 to exclude --> ")
  467.                   while not re.search(r'^[12]$', checkall):
  468.                      checkall = raw_input("invalid selection. enter 1 to backup all installed applications, or 2 to exclude --> ")
  469.                   if checkall == '1':
  470.                      backall = "all"
  471.                   else:
  472.                      backall = "no"
  473.                else:
  474.                   backshared = "no"
  475.                   backall = "all"
  476.                checksys = raw_input("enter 1 to backup system apps, or 2 to exclude --> ")
  477.                while not re.search(r'^[12]$',checksys):
  478.                   checksys = raw_input("invalid selection. enter 1 to backup system apps, or 2 to exclude --> ")
  479.                if checksys == '1':
  480.                   backsys = "sys"
  481.                else:
  482.                   backsys = "no"
  483.             backupfile = 'backup-' + str(datetime.date.today()) + '.ab'
  484.             raw_input("to continue with backup, press ENTER. then check device and follow prompts to continue. the backup process may take awhile.")
  485.             obj.backup(backupfile, backapk, backobb, backshared, backall, backsys)
  486.             raw_input("backup complete! backup file saved as: \033[35m" + backupfile + "\033[0m. press ENTER to return to main menu.")
  487.          elif whichbackup == '2':
  488.             restorefile = raw_input("please enter path to backup file on your computer [ex. \'backup-yyyy-mm-dd.ab\'] --> ")
  489.             while not os.path.isfile(restorefile):
  490.                restorefile = raw_input("file does not exist. please enter valid path --> ")
  491.             obj.restore(restorefile)
  492.             raw_input("restore complete! press ENTER to reboot and continue..")
  493.             obj.reboot("android")
  494.          else:
  495.             print("unable to connect to device. returning to main menu..")
  496.          time.sleep(0.9)
  497.          main()
  498.  
  499. ############################################################
  500. ############################################################
  501. # OPTION 7 - ROOT DEVICE #
  502. ############################################################
  503. ############################################################
  504.  
  505.       elif option == '7': #root
  506.      
  507.          def twrpdl(): # DOWNLOAD TWRP CUSTOM RECOVERY
  508.             TWRPurl = "http://notworth.it/opo/twrp.img"
  509.             TWRPmd5 = "77ba4381b13a03cc6dcff90f95e59a24"
  510.             dl = urllib.URLopener()
  511.             dl.retrieve(TWRPurl, "twrp.img")
  512.             site = urllib.urlopen(TWRPurl)
  513.             meta = site.info()
  514.             dlsize = meta.getheaders("Content-Length")[0]
  515.             fsize = os.path.getsize("twrp.img")
  516.             if usecolor == 'color':
  517.                print("file size: \033[33m")
  518.                print(dlsize)
  519.                print("\n\033[0mbytes downloaded: \033[33m")
  520.                print(fsize)
  521.                print("\033[0m\n")
  522.                print("\033[34mchecking md5 signature...\033[0m\n")
  523.             else:
  524.                print("file size: ")
  525.                print(dlsize)
  526.                print("bytes downloaded: ")
  527.                print(fsize)
  528.                print("checking md5 signature...")
  529.             md5_read = ''
  530.             integrity = ''
  531.             with open("twrp.img", "r+b") as sf:
  532.                sfdata = sf.read()
  533.                md5_read = hashlib.md5(sfdata).hexdigest()
  534.             if TWRPmd5 == md5_read:
  535.                print("MD5 verified!")
  536.                integrity = 'passed'
  537.             else:
  538.                print("MD5 file integrity check failed!")
  539.                integrity = 'failed'
  540.             if integrity == 'failed':
  541.                if dlsize != fsize:
  542.                   with open("twrp.img", "r+b") as f:
  543.                      # read contents of downloaded file
  544.                      fdata = f.read()
  545.                      f.write(site.read())
  546.                      f.flush()
  547.                      os.fsync(f.fileno())
  548.                      f.close()
  549.          
  550.          def recovdl(recovimg): # DOWNLOAD IMAGE FROM SITE
  551.             recovurl = "http://notworth.it/opo/" + recovimg
  552.             if recovimg == 'philz.img':
  553.                recovmd5 = "b2f8fb888e1377f00187ad0bd35a6584"
  554.             elif recovimg == 'cwm.img':
  555.                recovmd5 = "b60bd10f3f7cc254a4354cdc9c69b3bd"
  556.             else: # twrp.img MD5
  557.                recovmd5 = "77ba4381b13a03cc6dcff90f95e59a24"
  558.             dl = urllib.URLopener()
  559.             dl.retrieve(recovurl, recovimg)
  560.             site = urllib.urlopen(recovurl)
  561.             meta = site.info()
  562.             dlsize = meta.getheaders("Content-Length")[0]
  563.             fsize = os.path.getsize(recovimg)
  564.             if usecolor == 'color':
  565.                print("file size: \033[33m")
  566.                print(dlsize)
  567.                print("\n\033[0mbytes downloaded: \033[33m")
  568.                print(fsize)
  569.                print("\033[0m\n")
  570.                print("\033[34mchecking md5 signature...\033[0m\n")
  571.             else:
  572.                print("file size: ")
  573.                print(dlsize)
  574.                print("bytes downloaded: ")
  575.                print(fsize)
  576.                print("checking md5 signature...")
  577.             md5_read = ''
  578.             integrity = ''
  579.             with open(recovimg, "r+b") as sf:
  580.                sfdata = sf.read()
  581.                md5_read = hashlib.md5(sfdata).hexdigest()
  582.             if recovmd5 == md5_read:
  583.                print("MD5 verified!")
  584.                integrity = 'passed'
  585.             else:
  586.                print("MD5 file integrity check failed!")
  587.                integrity = 'failed'
  588.             if integrity == 'failed':
  589.                if dlsize != fsize:
  590.                   with open(recovimg, "r+b") as f:
  591.                      # read contents of downloaded recovery file
  592.                      fdata = f.read()
  593.                      f.write(site.read())
  594.                      f.flush()
  595.                      os.fsync(f.fileno())
  596.                      f.close()
  597.          
  598.          def chooserec(): # CHOOSE WHICH CUSTOM RECOVERY TO BOOT INTO ONCE
  599.             recovimg = "twrp.img"
  600.             pickrecov = raw_input("press 1 to flash superSU in TWRP Recovery, 2 to use Philz Recovery, or 3 to use CWM. --> ")
  601.             while not re.search(r'^[123]$', pickrecov):
  602.                pickrecov = raw_input("invalid selection. press 1 to flash superSU in TWRP Recovery, 2 for Philz, or 3 for CWM. --> ")
  603.             if pickrecov == '1': # SUPERSU TWRP
  604.                recovimg = "twrp.img"
  605.             elif pickrecov == '2': # SUPERSU PHILZ
  606.                recovimg = "philz.img"
  607.             elif pickrecov == '3': # SUPERSU CWM
  608.                recovimg = "cwm.img"
  609.             else:
  610.                print("unable to connect to device. returning to main menu..\n")
  611.             return recovimg
  612.            
  613.          superSU = 'UPDATE-SuperSU-v2.45.zip'
  614.          def sudl(): # DOWNLOAD SUPERSU ZIP
  615.             URLsuperSU = "http://download.chainfire.eu/695/SuperSU/UPDATE-SuperSU-v2.45.zip?retrieve_file=1"
  616.             MD5superSU = "9dbd5253b8f10a8064273dbec3bc78c8"
  617.            
  618.             dl = urllib.URLopener()
  619.             dl.retrieve(URLsuperSU, superSU)
  620.            
  621.             site = urllib.urlopen(URLsuperSU)
  622.             meta = site.info()
  623.             dlsize = meta.getheaders("Content-Length")[0]
  624.             fsize = os.path.getsize(superSU)
  625.             if usecolor == "color":
  626.                print("file size: \033[33m")
  627.                print(dlsize)
  628.                print("\n\033[0mbytes downloaded: \033[33m")
  629.                print(fsize)
  630.                print("\033[0m\n")
  631.                print("\033[34mchecking md5 signature...\033[0m\n")
  632.             else:
  633.                print("file size: ")
  634.                print(dlsize)
  635.                print("bytes downloaded: ")
  636.                print(fsize)
  637.                print("checking md5 signature...")
  638.             md5_read = ''
  639.             integrity = ''
  640.             with open(superSU, "r+b") as sf:
  641.                sfdata = sf.read()
  642.                md5_read = hashlib.md5(sfdata).hexdigest()
  643.             if MD5superSU == md5_read:
  644.                print("MD5 verified!")
  645.                integrity = 'passed'
  646.             else:
  647.                print("MD5 file integrity check failed!")
  648.                integrity = 'failed'
  649.             if integrity == 'failed':
  650.                if dlsize != fsize:
  651.                   with open(superSU, "r+b") as f:
  652.                      # read contents of downloaded SuperSU file
  653.                      fdata = f.read()
  654.                      f.write(site.read())
  655.                      f.flush()
  656.                      os.fsync(f.fileno())
  657.                      f.close()
  658.            
  659.          def suroot(recovimg):
  660.             while not os.path.isfile(superSU):
  661.                if usecolor == 'color':
  662.                   print("file \033[32m" + superSU + " \033[0mnot found.\n \033[40m\033[34;1mattempting download...\033[0m\n")
  663.                else:
  664.                   print("file " + superSU + " not found. \n attempting download... \n")
  665.                sudl()
  666.             if usecolor == 'color':  
  667.                print("file \033[32m" + superSU + " \033[0mfound!\n")
  668.             else:
  669.                print("file " + superSU + " found!\n")
  670.             while not os.path.isfile(recovimg):
  671.                if usecolor == 'color':
  672.                   print("file \033[32m" + recovimg + " \033[0mnot found. attempting download...\n")
  673.                else:
  674.                   print("file " + recovimg + " not found. attempting download...\n")
  675.                recovdl(recovimg)
  676.             if usecolor == 'color':
  677.                print("file \033[32m" + recovimg + " \033[0mfound!\n")
  678.             else:
  679.                print("file " + recovimg + " found!\n")
  680.             raw_input("press ENTER to copy file to device, then reboot into bootloader.")
  681.             remotesuperSU = '/sdcard/UPDATE-SuperSU-v2.45.zip'
  682.             obj.push(superSU, remotesuperSU)
  683.             obj.reboot("bootloader")
  684.             raw_input("press ENTER to boot into custom recovery.")
  685.             obj.bootimg(recovimg)
  686.             print("check that device is connected and booted into custom recovery. on device, choose the ADB SIDELOAD option [sometimes under ADVANCED].\n")
  687.             raw_input("press ENTER to continue with flashing superSU file via ADB sideload.")
  688.             obj.sideload(superSU)
  689.             sidefail = raw_input("if install failed, press 1 to attempt install from device. else, reboot into system from device recovery menu and press ENTER. --> ")
  690.             if sidefail == '1':
  691.                print("on device recovery menu, choose INSTALL, then select file \033[36m" + superSU + "\033[0m from the \033[36m/SDCARD\033[0m root directory.\n")
  692.                raw_input("swipe to install - this may take a moment. if install is successful, select REBOOT from recovery menu. press ENTER to continue.")
  693.             obj.reboot("android")
  694.          
  695.          superusr = 'Superuser-3.1.3-arm-signed.zip'
  696.          def susrdl():  # DOWNLOAD SUPERUSER ZIP
  697.             URLsuperusr = "http://notworth.it/opo/Superuser-3.1.3-arm-signed.zip"
  698.             MD5superusr = "b3c89f46f014c9df7d23b94d37386b8a"
  699.             dl = urllib.URLopener()
  700.             dl.retrieve(URLsuperusr, superusr)
  701.             site = urllib.urlopen(URLsuperusr)
  702.             meta = site.info()
  703.             dlsize = meta.getheaders("Content-Length")[0]
  704.             if usecolor == "color":
  705.                print("file size: \033[33m")
  706.                print(dlsize)
  707.                print("\n\033[0mbytes downloaded: \033[33m")
  708.                print(fsize)
  709.                print("\033[0m\n")
  710.                print("\033[34mchecking md5 signature...\033[0m\n")
  711.             else:
  712.                print("file size: ")
  713.                print(dlsize)
  714.                print("bytes downloaded: ")
  715.                print(fsize)
  716.                print("checking md5 signature...")
  717.             md5_read = ''
  718.             integrity = ''
  719.             with open(superusr, "r+b") as sf:
  720.                sfdata = sf.read()
  721.                md5_read = hashlib.md5(sfdata).hexdigest()
  722.             if MD5superusr == md5_read:
  723.                print("MD5 verified!")
  724.                integrity = 'passed'
  725.             else:
  726.                print("MD5 file integrity check failed!")
  727.                integrity = 'failed'
  728.             if integrity == 'failed':
  729.                if dlsize != fsize:
  730.                   with open(superusr, "r+b") as f:
  731.                      # read contents of downloaded Superuser file
  732.                      fdata = f.read()
  733.                      f.write(site.read())
  734.                      f.flush()
  735.                      os.fsync(f.fileno())
  736.                      f.close()
  737.            
  738.          def susrroot(recovimg): # FLASH SUPERUSER ZIP IN CUSTOM RECOVERY
  739.             while not os.path.isfile(superusr):
  740.                if usecolor == 'color':
  741.                   print("file \033[32m" + superusr + " \033[0mnot found. attempting download...\n")
  742.                else:
  743.                   print("file " + superusr + " not found. attempting download... \n")
  744.                susrdl()
  745.             if usecolor == 'color':
  746.                print("file \033[32m" + superusr + " \033[0mfound!\n")
  747.             else:
  748.                print("file " + superusr + " found!\n")
  749.             while not os.path.isfile(recovimg):
  750.                if usecolor == 'color':
  751.                   print("file \033[32m" + recovimg + " \033[0mnot found. attempting download...\n")
  752.                else:
  753.                   print("file " + recovimg + " not found. attempting download...")
  754.                recovdl(recovimg)
  755.             if usecolor == 'color':
  756.                print("file \033[32m" + recovimg + " \033[0mfound!\n")
  757.             else:
  758.                print("file " + recovimg + " found!")
  759.             raw_input("press ENTER to copy file to device and reboot into bootloader.")
  760.             remotesuperusr = '/sdcard/Superuser-3.1.3-arm-signed.zip'
  761.             obj.push(superusr, remotesuperusr)
  762.             obj.reboot("bootloader")
  763.             raw_input("press ENTER to boot into custom recovery.")
  764.             obj.bootimg(recovimg)
  765.             if usecolor == 'color':
  766.                print("on device, choose INSTALL from recovery menu, then select file \033[36m" + superusr + "\033[0m in the \033[36m/sdcard\033[0m directory.\n")
  767.             else:
  768.                print("on device, choose INSTALL from recovery menu, then select file " + superusr + " in the /sdcard directory.\n")
  769.             raw_input("if install is successful, select REBOOT from recovery menu on device. press ENTER to continue.")
  770.          
  771.          trfile = 'apps/tr.apk'
  772.          def trdl(): # DOWNLOAD TOWELROOT APK
  773.             dl = urllib.URLopener()
  774.             URLtr = "https://towelroot.com/tr.apk"
  775.             MD5tr = "e287e785d0e3e043fb0cfbfe69309d8e"
  776.             dl.retrieve(URLtr, trfile)
  777.             site = urllib.urlopen(URLtr)
  778.             meta = site.info()
  779.             dlsize = meta.getheaders("Content-Length")[0]
  780.             fsize = os.path.getsize(trfile)
  781.             if usecolor == "color":
  782.                print("file size: \033[33m")
  783.                print(dlsize)
  784.                print("\n\033[0mbytes downloaded: \033[33m")
  785.                print(fsize)
  786.                print("\033[0m\n")
  787.                print("\033[34mchecking md5 signature...\033[0m\n")
  788.             else:
  789.                print("file size: ")
  790.                print(dlsize)
  791.                print("bytes downloaded: ")
  792.                print(fsize)
  793.                print("checking md5 signature...")
  794.             md5_read = ''
  795.             integrity = ''
  796.             with open(trfile, "r+b") as sf:
  797.                sfdata = sf.read()
  798.                md5_read = hashlib.md5(sfdata).hexdigest()
  799.             if MD5tr == md5_read:
  800.                print("MD5 verified!")
  801.                integrity = 'passed'
  802.             else:
  803.                print("MD5 file integrity check failed!")
  804.                integrity = 'failed'
  805.             if integrity == 'failed':
  806.                if dlsize != fsize:
  807.                   with open(trfile, "r+b") as f:
  808.                      # read contents of downloaded TowelRoot file
  809.                      fdata = f.read()
  810.                      f.write(site.read())
  811.                      f.flush()
  812.                      os.fsync(f.fileno())
  813.                      f.close()
  814.            
  815.          def towroot(): # INSTALL TOWELROOT APK
  816.             if not os.path.exists('apps'):
  817.                os.makedirs('apps', 0755)
  818.             while not os.path.isfile(trfile):
  819.                print("file \033[32m" + trfile + " \033[0mnot found. attempting download...\n")
  820.                trdl()
  821.             print("file \033[32m" + trfile + " \033[0mfound!\n")
  822.             raw_input("press ENTER to install..")
  823.             obj.install(trfile)
  824.             obj.shell('am start -n com.geohot.towelroot/com.geohot.towelroot.TowelRoot')
  825.             print("if APK installed successfully, it should automatically launch on your device.")
  826.             raw_input("tap on MAKE IT RAIN. the results should appear shortly. follow instructions on device, then press ENTER to continue..")
  827.            
  828.          print("\033[36mif the firmware release date for your device is before june 2014, there is a chance the towelroot exploit may work.")
  829.          print("\033[35mhowever, superSU is a safer and more widely confirmed root method for the ONEPLUS ONE. ATTEMPT AT YOUR OWN RISK!\033[0m\n")
  830.          rootcheck = raw_input("which root method would you like to try? enter 1 for superSU [recommended for oneplus one], 2 for towelroot, 3 for Superuser, or 4 to install custom ZIP file. --> ")
  831.          while not re.search(r'^[1-4]$', rootcheck):
  832.             rootcheck = raw_input("invalid selection. enter 1 to install superSU package, 2 to install towelroot exploit, 3 to install Superuser, or 4 to install custom ZIP file. --> ")
  833.                
  834.          if rootcheck == '1': # SUPERSU
  835.             bootcustom = raw_input("press 1 to install superSU in custom recovery, 2 to install in your installed recovery, or 3 to install in fastboot [lower success rate]. --> ")
  836.             while not re.search(r'^[1-3]$', bootcustom):
  837.                bootcustom = raw_input("invalid choice. please enter 1 to load custom recovery, 2 to use installed recovery, or 3 for fastboot. --> ")
  838.             if bootcustom == '1': # SUPERSU TWRP
  839.                recovimg = chooserec()
  840.                suroot(recovimg) # SUPERSU CUSTOM RECOVERY
  841.                time.sleep(0.9)
  842.                main()
  843.             elif bootcustom == '2': # INSTALLED RECOVERY
  844.                while not os.path.isfile(superSU):
  845.                   if usecolor == 'color':
  846.                      print("file \033[32m" + superSU + " \033[0mnot found. attempting download...\n")
  847.                   else:
  848.                      print("file " + superSU + " not found. attempting download...")
  849.                   sudl()
  850.                if usecolor == 'color':
  851.                   print("file \033[32m" + superSU + " \033[0mfound!\n")
  852.                else:
  853.                   print("file " + superSU + " found!\n")
  854.                raw_input("press ENTER to copy file to device, then reboot into recovery.")
  855.                remotesuperSU = '/sdcard/UPDATE-SuperSU-v2.45.zip'
  856.                obj.push(superSU, remotesuperSU)
  857.                raw_input("file copied to device. press ENTER to continue to recovery..")
  858.                obj.reboot("recovery")
  859.                raw_input("in recovery menu on device, please select APPLY UPDATE, then APPLY FROM ADB. press ENTER when ready.")
  860.                obj.sideload("UPDATE-SuperSU-v2.45.zip")
  861.                superfail = raw_input("choose REBOOT SYSTEM from device menu. if update successful, press ENTER. else, press 1 to install superSU from TWRP, or 2 to install superSU from Philz --> " )
  862.                obj.reboot("android")
  863.                if superfail == '1': # SUPERSU TWRP
  864.                   suroot("twrp.img")
  865.                elif superfail == '2': # SUPERSU PHILZ
  866.                   suroot("philz.img")
  867.                else:
  868.                   obj.get_state()
  869.                time.sleep(0.9)
  870.                main()
  871.                
  872.             elif bootcustom == '3': # SUPERSU FASTBOOT
  873.                updatewhich = raw_input("to try installing superSU in fastboot, press 1. else, enter name of ZIP file to install --> ")
  874.                if updatewhich == '1': # SUPERSU FASTBOOT
  875.                   while not os.path.isfile(superSU):
  876.                      if usecolor == 'color':
  877.                         print("file \033[32m" + superSU + " \033[0mnot found. attempting download...\n\n")
  878.                      else:
  879.                         print("file " + superSU + " not found. attempting download...\n\n")
  880.                      sudl()
  881.                   raw_input("press ENTER to reboot into bootloader.")
  882.                   obj.reboot("bootloader")
  883.                   if usecolor == 'color':
  884.                      print("\033[35mattempting to install superSU via fastboot...\n\033[0m")
  885.                   else:
  886.                      print("attempting to install superSU via fastboot...\n")
  887.                   obj.update(superSU)
  888.                   failsu = raw_input("if installation failed, press 1 to try sideload method. otherwise, press ENTER to continue...")
  889.                   if failsu == '1': # SUPERSU SIDELOAD
  890.                      obj.fastreboot("android")
  891.                      time.sleep(0.9)
  892.                      print("\033[32mmake sure your computer is authorized to access your device over ADB.\033[0m\n")
  893.                      raw_input("press ENTER to continue rebooting to recovery..")
  894.                      obj.reboot("recovery")
  895.                      raw_input("in recovery menu on device, please select APPLY UPDATE, then APPLY FROM ADB. press ENTER when ready.")
  896.                      obj.sideload("UPDATE-SuperSU-v2.45.zip")
  897.                      superfail = raw_input("choose REBOOT SYSTEM from device menu. if update successful, press ENTER. else, press 1 to install superSU from TWRP, or 2 to install superSU from Philz --> " )
  898.                      obj.reboot("android")
  899.                      if superfail == '1': # SUPERSU TWRP
  900.                         suroot("twrp.img")
  901.                      elif superfail == '2': # SUPERSU PHILZ
  902.                         suroot("philz.img")
  903.                      else:
  904.                         obj.get_state()
  905.                   time.sleep(0.9)
  906.                   main()
  907.                else:
  908.                   print("attempting to install " + updatewhich + "...\n\n")
  909.                   while not os.path.isfile(updatewhich):
  910.                      updatewhich = raw_input("invalid file path. please enter correct path of ZIP file to install --> ")
  911.                   obj.update(updatewhich) # CUSTOM FASTBOOT UPDATE
  912.                   failupd = raw_input("if installation failed, press 1 to try sideload method. otherwise, press ENTER to continue...")
  913.                   if failupd == '1':
  914.                      obj.fastreboot("android")
  915.                      time.sleep(0.9)
  916.                      print("\033[32mmake sure your computer is authorized to access your device over ADB.\033[0m\n")
  917.                      raw_input("press ENTER to continue..")
  918.                      obj.reboot("recovery")
  919.                      raw_input("in recovery menu on device, please select APPLY UPDATE, then APPLY FROM ADB. press ENTER when ready.")
  920.                      obj.sideload(updatewhich) # CUSTOM SIDELOAD
  921.                      raw_input("please follow reboot prompts on device recovery menu, then press ENTER to continue...")
  922.                   else:
  923.                      obj.fastreboot("android")
  924.                   time.sleep(0.9)
  925.                   main()
  926.             else:
  927.                print("failed to connect to device. returning to main menu.. \n\n")
  928.                
  929.  
  930.          elif rootcheck == '2': # TOWELROOT
  931.             towroot()
  932.             trysuroot = raw_input("if towelroot failed, press 1 to launch superSU method. otherwise, press ENTER to return to main menu. --> ")
  933.             if trysuroot == '1': # SUPERSU
  934.                recovimg = chooserec()
  935.                suroot(recovimg) # SUPERSU CUSTOM RECOVERY
  936.                time.sleep(0.9)
  937.                main()
  938.             else:
  939.                time.sleep(0.9)
  940.                main()
  941.          
  942.          elif rootcheck == '3': # SUPERUSER or CUSTOM ZIP FILE
  943.             bootcustom = raw_input("press 1 to install Superuser in TWRP recovery, 2 to install in Philz recovery, or 3 to install in fastboot [lowest success rate]. --> ")
  944.             while not re.search(r'^[123]$', bootcustom):
  945.                bootcustom = raw_input("invalid choice. please enter 1 to load TWRP, 2 for Philz, or 3 for fastboot. --> ")
  946.             if bootcustom == '1':
  947.                susrroot("twrp.img")
  948.             elif bootcustom == '2':
  949.                susrroot("philz.img")
  950.             elif bootcustom == '3':
  951.                while not os.path.isfile(superusr):
  952.                   print("file \033[32m" + superusr + " \033[0mnot found. attempting download...\n\n")
  953.                   sudl()
  954.                raw_input("press ENTER to reboot into bootloader.")
  955.                obj.reboot("bootloader")
  956.                print("\033[35mattempting to install Superuser via fastboot...\n\033[0m")
  957.                obj.update(superusr)
  958.                failsu = raw_input("if installation failed, press 1 to try sideload method. otherwise, press ENTER to continue...")
  959.                if failsu == '1':
  960.                   obj.fastreboot("android")
  961.                   time.sleep(0.9)
  962.                   print("\033[32mmake sure your computer is authorized to access your device over ADB.\033[0m\n")
  963.                   raw_input("press ENTER to continue..")
  964.                   obj.reboot("recovery")
  965.                   raw_input("in recovery menu on device, please select APPLY UPDATE, then APPLY FROM ADB. press ENTER when ready.")
  966.                   obj.sideload(superusr)
  967.                   superfail = raw_input("choose REBOOT SYSTEM from device menu. if update successful, press ENTER. else, press 1 to install Superuser via TWRP or 2 to install Superuser via Philz. --> " )
  968.                   if superfail == '1':
  969.                      susrroot("twrp.img")
  970.                   elif superfail == '2':
  971.                      susrroot("philz.img")
  972.                   else:
  973.                      obj.get_state()
  974.                time.sleep(0.9)
  975.                main()
  976.                  
  977.             elif rootcheck == '4':
  978.                updatefile = raw_input("please enter path of ZIP file to install --> ")
  979.                while not os.path.isfile(updatefile):
  980.                   updatefile = raw_input("invalid file path. please enter correct path of ZIP file to install --> ")
  981.                raw_input("press ENTER to reboot into bootloader.")
  982.                obj.reboot("bootloader")
  983.                print("attempting to install " + updatefile + "...\n")
  984.                obj.update(updatefile)
  985.                raw_input("press ENTER to continue...")
  986.                obj.fastreboot("android")
  987.                time.sleep(0.9)
  988.                main()
  989.            
  990.             else:
  991.                print("failed to connect to device. returning to main menu.. \n\n")
  992.                
  993.          else:
  994.             print("failed to connect to device. returning to main menu.. \n\n")
  995.                  
  996.          time.sleep(0.9)
  997.          main()
  998.  
  999. ############################################################
  1000. ############################################################
  1001. # OPTION 8 - FLASH STOCK IMAGES/PARTITIONS #
  1002. ############################################################
  1003. ############################################################
  1004.          
  1005.       elif option == '8': #flash stock images/partitions
  1006.      
  1007.          def dlimg(imgfile):
  1008.             dlfile = "http://notworth.it/opo/" + imgfile
  1009.             dl = urllib.URLopener()
  1010.             dl.retrieve(dlfile, imgfile)
  1011.             site = urllib.urlopen(dlfile)
  1012.             meta = site.info()
  1013.             dlsize = meta.getheaders("Content-Length")[0]
  1014.             fsize = os.path.getsize(imgfile)
  1015.             print("file size: \033[33m")
  1016.             print(dlsize)
  1017.             print("\n\033[0mbytes downloaded: \033[33m")
  1018.             print(fsize)
  1019.             print("\033[0m\n")
  1020.      
  1021.          def flashmenu():
  1022.             if usecolor == 'color':
  1023.                menuflash = colorflashmenu
  1024.             else:
  1025.                menuflash = cleanflashmenu
  1026.             print(menuflash)
  1027.             flashsel = raw_input("select an option from 1 through 9 from menu --> ")
  1028.             while not re.search(r'^[1-9]$', flashsel):
  1029.                flashsel = raw_input("invalid selection. please choose an option between 1 and 9 --> ")
  1030.             if usecolor == 'color':
  1031.                print(colorversionmenu)
  1032.             else:
  1033.                print(cleanversionmenu)
  1034.                  
  1035.             verssel = raw_input("choose target version 1-5 from menu, or 6 to exit --> ")
  1036.             while not re.search(r'^[1-6]$', verssel):
  1037.                verssel = raw_input("invalid selection. please choose an option between 1-6 --> ")
  1038.             #vers = ''
  1039.    
  1040.             if verssel == '1':
  1041.                vers = 'XNPH25R'
  1042.    
  1043.             elif verssel == '2':
  1044.                vers = 'XNPH30O'
  1045.    
  1046.             elif verssel == '3':
  1047.                vers = 'XNPH33R'
  1048.      
  1049.             elif verssel == '4':
  1050.                vers = 'XNPH38R'
  1051.      
  1052.             elif verssel == '5':
  1053.                vers = 'XNPH44S'
  1054.    
  1055.             elif verssel == '6':
  1056.                print("returning to main menu..")
  1057.                time.sleep(0.9)
  1058.                main()
  1059.    
  1060.             else:
  1061.                print("an error has occurred. returning to main menu..")
  1062.                time.sleep(0.9)
  1063.                main()
  1064.            
  1065.             if re.search(r'^[1-7]$', flashsel):
  1066.                print("\n\033[34mrebooting into bootloader...\033[0m\n")
  1067.                obj.reboot("bootloader")
  1068.            
  1069.             if flashsel == '1':
  1070.                imgfile = vers + "/boot.img"
  1071.                while not os.path.isfile(imgfile):
  1072.                   if not os.path.exists(vers):
  1073.                      os.makedirs(vers, 0755)
  1074.                   print("downloading %s...") % imgfile
  1075.                   dlimg(imgfile)
  1076.                raw_input("press ENTER to proceed with flashing boot image..")
  1077.                obj.flashf("boot", imgfile)
  1078.                raw_input("press ENTER key to continue...")
  1079.                flashmenu()
  1080.                
  1081.             elif flashsel == '2':
  1082.                whichsize = raw_input("IMPORTANT!! choose correct storage capacity: enter 1 for 16gb device, or 2 for 64gb device. --> ")
  1083.                while not re.search(r'^[12]$', whichsize):
  1084.                   whichsize = raw_input("invalid selection. enter 1 for 16gb device, or 2 for 64gb device. --> ")
  1085.                if whichsize == '1':
  1086.                   imgfile = vers + "/userdata.img"
  1087.                elif whichsize == '2':
  1088.                   imgfile = vers + "/userdata_64G.img"
  1089.                else:
  1090.                   print("ERROR: an unknown error has occurred.")
  1091.                while not os.path.isfile(imgfile):
  1092.                   if not os.path.exists(vers):
  1093.                      os.makedirs(vers, 0755)
  1094.                   print("downloading %s") % imgfile
  1095.                   dlimg(imgfile)
  1096.                raw_input("press ENTER to proceed with flashing data.")
  1097.                obj.flashf("data", imgfile)
  1098.                raw_input("press ENTER key to return to flash menu...")
  1099.                flashmenu()
  1100.                
  1101.             elif flashsel == '3':
  1102.                imgfile = vers + "/system.img"
  1103.                while not os.path.isfile(imgfile):
  1104.                   if not os.path.exists(vers):
  1105.                      os.makedirs(vers, 0755)
  1106.                   print("downloading %s...") % imgfile
  1107.                   dlimg(imgfile)
  1108.                raw_input("press ENTER to proceed with flashing system.")
  1109.                obj.flashf("system", imgfile)
  1110.                raw_input("press ENTER key to continue...")
  1111.                flashmenu()
  1112.                
  1113.             elif flashsel == '4':
  1114.                imgfile = vers + "/recovery.img"
  1115.                while not os.path.isfile(imgfile):
  1116.                   if not os.path.exists(vers):
  1117.                      os.makedirs(vers, 0755)
  1118.                   print("downloading %s...") % imgfile
  1119.                   dlimg(imgfile)
  1120.                raw_input("press ENTER to proceed with flashing recovery.")
  1121.                obj.flashf("recovery", imgfile)
  1122.                raw_input("press ENTER key to continue...")
  1123.                flashmenu()
  1124.                
  1125.             elif flashsel == '5':
  1126.                imgfile = vers + "/cache.img"
  1127.                while not os.path.isfile(imgfile):
  1128.                   if not os.path.exists(vers):
  1129.                      os.makedirs(vers, 0755)
  1130.                   print("downloading %s...") % imgfile
  1131.                   dlimg(imgfile)
  1132.                raw_input("press ENTER to proceed with flashing cache.")
  1133.                obj.flashf("cache", imgfile)
  1134.                raw_input("press ENTER key to continue...")
  1135.                flashmenu()
  1136.                
  1137.             elif flashsel == '6':
  1138.                if not os.path.exists(vers):
  1139.                   os.makedirs(vers, 0755)
  1140.                imgfile = vers + "/flash-radio.sh"
  1141.                while not os.path.isfile(imgfile):
  1142.                   print("downloading %s...") % imgfile
  1143.                   dlimg(imgfile)
  1144.                   os.chmod(imgfile, 0755)
  1145.                while not os.path.isfile(vers + "/boot.img"):
  1146.                   print("downloading %s/boot.img..") % vers
  1147.                   dlimg("%s/boot.img") % vers
  1148.                while not os.path.isfile(vers + "/emmc_appsboot.mbn"):
  1149.                   print("downloading %s/emmc_appsboot.mbn..") % vers
  1150.                   dlimg("%s/emmc_appsboot.mbn") % vers
  1151.                while not os.path.isfile(vers + "/NON-HLOS.bin"):
  1152.                   print("downloading %s/NON-HLOS.bin..") % vers
  1153.                   dlimg("%s/NON-HLOS.bin") % vers
  1154.                while not os.path.isfile(vers + "/rpm.mbn"):
  1155.                   print("downloading %s/rpm.mbn..") % vers
  1156.                   dlimg("%s/rpm.mbn") % vers
  1157.                while not os.path.isfile(vers + "/sbl1.mbn"):
  1158.                   print("downloading %s/sbl1.mbn..") % vers
  1159.                   dlimg("%s/sbl1.mbn") % vers
  1160.                while not os.path.isfile(vers + "/sdi.mbn"):
  1161.                   print("downloading %s/sdi.mbn..") % vers
  1162.                   dlimg("%s/sdi.mbn") % vers
  1163.                while not os.path.isfile(vers + "/tz.mbn"):
  1164.                   print("downloading %s/tz.mbn..") % vers
  1165.                   dlimg("%s/tz.mbn") % vers
  1166.                while not os.path.isfile(vers + "/logo.bin"):
  1167.                   print("downloading %s/logo.bin..") % vers
  1168.                   dlimg("%s/logo.bin") % vers
  1169.                subprocess.call(['./flash-radio.sh'], cwd='%s', shell=True) % vers
  1170.                raw_input("press ENTER key to continue...")
  1171.                flashmenu()
  1172.                
  1173.             elif flashsel == '7':
  1174.                if not os.path.exists(vers):
  1175.                   os.makedirs(vers, 0755)
  1176.                while not os.path.isfile(vers + "/boot.img"):
  1177.                   print("downloading %s/boot.img..") % vers
  1178.                   dlimg("%s/boot.img") % vers
  1179.                while not os.path.isfile(vers + "/emmc_appsboot.mbn"):
  1180.                   print("downloading %s/emmc_appsboot.mbn..") % vers
  1181.                   dlimg("%s/emmc_appsboot.mbn") % vers
  1182.                while not os.path.isfile(vers + "/NON-HLOS.bin"):
  1183.                   print("downloading %s/NON-HLOS.bin..") % vers
  1184.                   dlimg("%s/NON-HLOS.bin") % vers
  1185.                while not os.path.isfile(vers + "/rpm.mbn"):
  1186.                   print("downloading %s/rpm.mbn..") % vers
  1187.                   dlimg("%s/rpm.mbn") % vers
  1188.                while not os.path.isfile(vers + "/sbl1.mbn"):
  1189.                   print("downloading %s/sbl1.mbn..") % vers
  1190.                   dlimg("%s/sbl1.mbn") % vers
  1191.                while not os.path.isfile(vers + "/flash-extras.sh"):
  1192.                   print("downloading %s/flash-extras.sh..") % vers
  1193.                   dlimg("%s/flash-extras.sh") % vers
  1194.                   os.chmod(vers + "/flash-extras.sh", 0755)
  1195.                raw_input("press ENTER to proceed with running flash-extras.sh script.")
  1196.                subprocess.call(['./flash-extras.sh'], cwd='%s', shell=True) % vers
  1197.                raw_input("press ENTER key to continue...")
  1198.                obj.fastreboot("android")
  1199.                flashmenu()
  1200.                
  1201.             elif flashsel == '8':
  1202.                romsel = raw_input("enter 1 to flash stock ROM for %s, 2 to flash custom ROM, or 3 to return to main menu. --> ") % vers
  1203.                while not re.search(r'^[1-3]$', romsel):
  1204.                   romsel = raw_input("invalid selection. enter an option 1-3. --> ")
  1205.                if romsel == '1':
  1206.                   imgfile = vers + "/%s-bacon-signed-fastboot.zip" % vers
  1207.                   if not os.path.exists(vers):
  1208.                      os.makedirs(vers, 0755)
  1209.                   while not os.path.isfile(imgfile):
  1210.                      print("file \033[32m" + imgfile + " \033[0mnot found. attempting download...\n")
  1211.                      dlimg(imgfile)
  1212.                   print("file \033[32m" + imgfile + " \033[0mfound!\n")
  1213.                   raw_input("press ENTER to reboot into bootloader..")
  1214.                   obj.reboot("bootloader")
  1215.                   obj.update(imgfile)
  1216.                   failupd = raw_input("if update failed, press 1. otherwise, press ENTER key to continue. --> ")
  1217.                   if failupd == '1':
  1218.                      obj.fastreboot("android")
  1219.                      raw_input("check that device is unlocked and computer is authorized for ADB access. press ENTER to continue..")
  1220.                      imgfileonly = imgfile[8:]
  1221.                      rimgfile = "/sdcard/" + imgfileonly
  1222.                      obj.push(imgfile, rimgfile)
  1223.                      raw_input("press ENTER to reboot into recovery.")
  1224.                      obj.reboot("recovery")
  1225.                      print("choose APPLY UPDATE from recovery menu and select APPLY FROM ADB.\n")
  1226.                      raw_input("press ENTER to install from stock image now.")
  1227.                      obj.sideload(imgfile)
  1228.                      failside = raw_input("if update failed, press 1 to update from device storage. else, push POWER button on device to reboot, then press ENTER to continue. --> ")
  1229.                      if failside == '1':
  1230.                         print("choose APPLY UPDATE from recovery menu, then select CHOOSE FROM INTERNAL STORAGE.\n")
  1231.                         print("select file \033[32m" + imgfileonly + " \033[0mfrom root of SDCARD directory and install.\n")
  1232.                         print("\033[35mif update fails again, return to main menu and choose option 3 to reboot into custom recovery.\033[0m\n\n")
  1233.                         menusel = raw_input("enter 1 to return to flash menu, or 2 to return to main menu. --> ")
  1234.                         while not re.search(r'^[12]$',menusel):
  1235.                            menusel = raw_input("invalid selection. press 1 for flash menu, or 2 to return to main menu. --> ")
  1236.                         if menusel == '1':
  1237.                            time.sleep(0.9)
  1238.                            flashmenu()
  1239.                         elif menusel == '2':
  1240.                            time.sleep(0.9)
  1241.                            main()
  1242.                         else:
  1243.                            print("error connecting to device. returning to main menu...\n")
  1244.                            time.sleep(0.9)
  1245.                            main()
  1246.                      else:
  1247.                         print("\033[32mreturning to flash menu..\033[0m\n\n")
  1248.                         time.sleep(0.9)
  1249.                         flashmenu()
  1250.                   else:
  1251.                      print("\033[32mreturning to flash menu..\033[0m\n\n")
  1252.                      time.sleep(0.9)
  1253.                      flashmenu()
  1254.                elif romsel == '2':
  1255.                   print("\033[31mmake sure device is unlocked and PC is authenticated for ADB access.\033[0m\n")
  1256.                   romname = raw_input("place ROM file into same directory as the script home, then enter filename --> ")
  1257.                   while not os.path.isfile(romname):
  1258.                      romname = raw_input("invalid filename. make sure ROM ZIP file to flash is in correct location, then enter filename --> ")
  1259.                   rimgfile = "/sdcard/" + romname
  1260.                   print("\033[32mpushing update file to device..\033[0m\n")
  1261.                   obj.push(romname, rimgfile)
  1262.                   raw_input("press ENTER to reboot to bootloader.")
  1263.                   obj.reboot("bootloader")
  1264.                   while not os.path.isfile("twrp.img"):
  1265.                      print("file \033[32mtwrp.img \033[0mnot found. attempting download...\n")
  1266.                      dlimg("twrp.img")
  1267.                   print("file \033[32mtwrp.img \033[0mfound!\n")
  1268.                   raw_input("press ENTER to continue booting into TWRP recovery.")
  1269.                   obj.bootimg("twrp.img")
  1270.                   print("on device, choose ADVANCED from TWRP menu, then select INSTALL ZIP and to APPLY VIA ADB SIDELOAD.\n")
  1271.                   raw_input("press ENTER to install the zip file you specified.")
  1272.                   obj.sideload(imgfile)
  1273.                   failside = raw_input("if update failed, enter 1 to try installing from device storage. otherwise, push select REBOOT from device recovery menu, reboot into system, and press ENTER to continue. --> ")
  1274.                   if failside == '1':
  1275.                      print("select INSTALL on device TWRP menu, then find your file \033[32m" + romname + " \033[0min device SDCARD root and swipe to install file.\n")
  1276.                      menusel = raw_input("when flash complete, select REBOOT into SYSTEM from recovery options on device. then enter 1 to return to flash menu, or 2 for main menu.")
  1277.                      while not re.search(r'^[12]$',menusel):
  1278.                         menusel = raw_input("invalid selection. enter 1 for flash menu, or 2 to return to main menu.")
  1279.                      if menusel == '1':
  1280.                         time.sleep(0.9)
  1281.                         flashmenu()
  1282.                      elif menusel == '2':
  1283.                         time.sleep(0.9)
  1284.                         main()
  1285.                      else:
  1286.                         print("an unknown error has occurred. returning to main menu...\n")
  1287.                         time.sleep(0.9)
  1288.                         main()
  1289.                        
  1290.                elif romsel == '3':
  1291.                   print("returning to main menu..")
  1292.                   time.sleep(0.9)
  1293.                   main()
  1294.                  
  1295.             elif flashsel == '0':
  1296.                checkreboot = raw_input("press 1 to reboot device into system, or ENTER to continue.. --> ")
  1297.                if checkreboot == '1':
  1298.                   obj.fastreboot("android")
  1299.                time.sleep(0.9)
  1300.                main()
  1301.                
  1302.             else:
  1303.                print("unable to connect to device. returning to flash menu..")
  1304.                time.sleep(0.9)
  1305.                flashmenu()
  1306.          
  1307.          flashmenu()
  1308.          time.sleep(0.9)
  1309.          main()
  1310.  
  1311. ############################################################
  1312. ############################################################
  1313. # OPTION 9 - UNLOCK BOOTLOADER #
  1314. ############################################################
  1315. ############################################################
  1316.  
  1317.       elif option == '9': # unlock bootloader
  1318.      
  1319.          def recovflash():
  1320.             flashcont = raw_input("select 1 to continue flashing recovery. select 2 to flash a stock or custom image. select 3 to return to flash menu. --> ")
  1321.             while not re.search(r'^[123]$', flashcont):
  1322.                flashcont = raw_input("invalid selection. select 1 to continue flashing recovery. select 2 to flash a stock partition image. select 3 to return to flash menu. --> ")
  1323.             if flashcont == '1':
  1324.                recovchoice = raw_input("enter 1 for TWRP, 2 for ClockworkMod, or 3 for Philz recovery --> ")
  1325.                while not re.search(r'^[1-3]$', recovchoice):
  1326.                   recovchoice = raw_input("invalid selection. please choose 1 for TWRP, 2 for CWM, or 3 for Philz --> ")
  1327.                obj.reboot("bootloader")
  1328.                if recovchoice == '1':
  1329.                   recovfile = "twrp.img"
  1330.                   while not os.path.isfile(recovfile):
  1331.                      print("file \033[32mtwrp.img \033[0mnot found. attempting download...\n")
  1332.                      dlrecov(recovfile)
  1333.                   print("file \033[32mtwrp.img \033[0mfound!\n")
  1334.                   raw_input("press ENTER to flash twrp.img over current recovery.")
  1335.                   obj.flashf("recovery","twrp.img")
  1336.                elif recovchoice == '2':
  1337.                   recovfile = "cwm.img"
  1338.                   while not os.path.isfile(recovfile):
  1339.                      print("file \033[32mcwm.img \033[0mnot found. attempting download...\n")
  1340.                      dlrecov(recovfile)
  1341.                   print("file \033[32mcwm.img \033[0mfound!\n")
  1342.                   raw_input("press ENTER to flash cwm.img over current recovery.")
  1343.                   obj.flashf("recovery","cwm.img")
  1344.                elif recovchoice == '3':
  1345.                   recovfile = "philz.img"
  1346.                   while not os.path.isfile(recovfile):
  1347.                      print("file \033[32mphilz.img \033[0mnot found. attempting download...\n")
  1348.                      dlrecov(recovfile)
  1349.                   print("file \033[32mphilz.img \033[0mfound!\n")
  1350.                   raw_input("press ENTER to flash philz.img over current recovery.")
  1351.                   obj.flashf("recovery","philz.img")
  1352.                else:
  1353.                   print("unable to connect to device.\n")
  1354.                  
  1355.             elif flashcont == '2':
  1356.                flashmenu()  
  1357.                                
  1358.             elif flashcont == '3':
  1359.                main()
  1360.                
  1361.             else:
  1362.                print("unable to connect to device.\n")
  1363.            
  1364.             time.sleep(0.9)
  1365.            
  1366.          bootcolormenu = '''
  1367.         \033[33m***UNLOCKING YOUR BOOTLOADER WILL WIPE YOUR DEVICE!!!***\033[0m
  1368.         \033[37mIF YOUR DEVICE HOLDS IMPORTANT DATA, BACK UP DEVICE BEFORE YOU CONTINUE!\033[0m
  1369.         '''
  1370.          bootcleanmenu = '''
  1371.         ***UNLOCKING YOUR BOOTLOADER WILL WIPE YOUR DEVICE!!!***
  1372.         IF YOUR DEVICE HOLDS IMPORTANT DATA, BACK UP DEVICE BEFORE YOU CONTINUE!'''
  1373.          
  1374.          if usecolor == 'color':
  1375.             print(bootcolormenu)
  1376.          else:
  1377.             print(bootcleanmenu)
  1378.            
  1379.          bunlock = raw_input("enter 1 to continue unlocking bootloader. enter 2 to skip to flashing custom recovery or images. enter 3 to re-lock bootloader. or enter 4 to return to previous menu. --> ")
  1380.          while not re.search(r'^[1-4]$', bunlock):
  1381.             bunlock = raw_input("invalid selection. enter 1 to unlock bootloader and wipe device. enter 2 to skip to flashing custom recovery or images. enter 3 to re-lock bootloader. or enter 4 to return to previous menu. --> ")
  1382.          
  1383.          if bunlock == '1':
  1384.             obj.reboot("bootloader")
  1385.             obj.unlockboot()
  1386.             print("your device should reboot after successfully unlocking the bootloader.\n")
  1387.             raw_input("press ENTER to continue...")
  1388.             recovflash()
  1389.            
  1390.          elif bunlock == '2':
  1391.             recovflash()
  1392.                    
  1393.          elif bunlock == '3':
  1394.             print("\033[33mREMINDER: to unlock your device again, you MUST downgrade to firmware release XNPH25R or earlier!\033[0m\n")
  1395.             btlockconfirm = raw_input("press ENTER to continue, or 1 to exit to the previous menu --> ")
  1396.             if btlockconfirm == '1':
  1397.                flashmenu()
  1398.             else:
  1399.                obj.reboot("bootloader")
  1400.                obj.lockboot()
  1401.                raw_input("press ENTER to reboot your device")
  1402.                obj.fastreboot("android")
  1403.          
  1404.          elif bunlock == '4':
  1405.             print("returning to previous menu menu..")
  1406.             time.sleep(0.9)
  1407.             flashmenu()
  1408.                  
  1409.          else:
  1410.             print("an unknown error has occurred. returning to main menu..")
  1411.             time.sleep(0.9)
  1412.             flashmenu()
  1413.                
  1414.          time.sleep(0.9)
  1415.          main()
  1416.  
  1417. ############################################################
  1418. ############################################################
  1419. # OPTION 10 - RUN SHELL COMMAND #
  1420. ############################################################
  1421. ############################################################
  1422.  
  1423.       elif option == '10': #run shell command
  1424.          shellcmd = raw_input("enter shell command --> ")
  1425.          while shellcmd:
  1426.             obj.shell(shellcmd)
  1427.             shellcmd = raw_input("enter another shell command, or press ENTER to return to main menu --> ")
  1428.          time.sleep(0.9)
  1429.          main()
  1430.  
  1431. ############################################################
  1432. ############################################################
  1433. # OPTION 11 - GET BUGREPORT #
  1434. ############################################################
  1435. ############################################################
  1436.  
  1437.       elif option is '11': #get bugreport
  1438.          raw_input("please allow several minutes for process to complete. press ENTER to start generating bug report.")
  1439.          obj.bugreport()
  1440.          raw_input("press ENTER to return to main menu.")
  1441.          time.sleep(0.9)
  1442.          main()
  1443.  
  1444. ############################################################
  1445. ############################################################
  1446. # OPTION 12 - LIST INSTALLED PACKAGES #
  1447. ############################################################
  1448. ############################################################
  1449.  
  1450.       elif option == '12': # list packages
  1451.          print("LISTING INSTALLED PACKAGES...")
  1452.          obj.listpkg()
  1453.          raw_input("press ENTER to return to main menu.")
  1454.          time.sleep(0.9)
  1455.          main()
  1456.  
  1457. ############################################################
  1458. ############################################################
  1459. # OPTION 13 - LIST SERVICES #
  1460. ############################################################
  1461. ############################################################
  1462.  
  1463.       elif option == '13': # list services
  1464.          print("LISTING RUNNING SERVICES...")
  1465.          obj.listsvc()
  1466.          raw_input("press ENTER to return to main menu.")
  1467.          time.sleep(0.9)
  1468.          main()
  1469.  
  1470. ############################################################
  1471. ############################################################
  1472. # OPTION 14 - GET LOGCAT #
  1473. ############################################################
  1474. ############################################################
  1475.                  
  1476.       elif option == '14': #get logcat
  1477.          print("logcat will open in a new window. close logcat window to return to menu.")
  1478.          if os.name == 'nt':
  1479.             process = subprocess.Popen('start /wait adb logcat', shell=True, creationflags=subprocess.CREATE_NEW_CONSOLE, stdout=subprocess.PIPE)
  1480.          else:
  1481.             process = subprocess.Popen(['xterm', '-e', 'adb', 'logcat', 'sleep 4'], stdout=subprocess.PIPE)
  1482.          line = process.stdout.readline()
  1483.          while line:
  1484.             print line
  1485.             line = process.stdout.readline()
  1486.          time.sleep(0.9)
  1487.          main()
  1488.  
  1489. ############################################################
  1490. ############################################################
  1491. # OPTION 0 - QUIT #
  1492. ############################################################
  1493. ############################################################
  1494.  
  1495.       elif option == '0': #quit
  1496.          print("thanks for using the HALF-ASSED ONEPLUS ONE TOOLKIT! bye!")
  1497.          sys.exit()
  1498.                  
  1499.       else:
  1500.          print '\n\033[32man unhandled exception occurred. returning to main menu..\033[0m\n'
  1501.          time.sleep(0.9)
  1502.          main()
  1503.  
  1504. main()
  1505. sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement