Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- ##### PYADB v1.3
- ##### RELEASE DATE: AUGUST 26, 2014
- ##### AUTHOR: vvn
- ##### unfinished library to port ADB and FASTBOOT functions to PYTHON
- ##### for now it's a required companion to the half-assed one plus one toolkit.
- ##### that's also here on pastebin: http://pastebin.com/y511TjV1
- ##### check out the README file too! http://notworth.it/opo/README
- ##### this project is vaguely based on some github code i found that had too many errors.
- ##### i know it isn't anything new. i know it's probably been done better.
- ##### but i wanted one that worked for me. if it works for you, go ahead and use it too!
- ##### feel free to share, modify, whatever.
- ##### i don't care if you credit me, though that'd be nice.
- ##### to really show your appreciation, you can buy my EP instead!
- ##### you can stream and purchase it at: dreamcorp.bandcamp.com
- ##### questions, comments, feedback, bugs, complaints, death threats, marriage proposals?
- ##### contact me at:
- ##### vvn (at) eudemonics (dot) org
- import os, subprocess, sys
- from subprocess import call, Popen, PIPE
- class pyADB(object):
- # adb commands
- def call_adb(self, command):
- results = ''
- command_text = 'adb %s' % command
- output = Popen(command_text, shell=True, stdout=PIPE, stderr=PIPE, stdin=PIPE)
- response = output.communicate()
- # response = output.stdout()
- return response
- # fastboot commands
- def call_fastboot(self, command):
- results = ''
- command_text = 'fastboot %s' % command
- output = Popen(command_text, shell=True, stdout=PIPE, stderr=PIPE, stdin=PIPE)
- response, errors = output.communicate()[0][1]
- # response = output.stdout()
- return response
- # check for any ADB device
- def adbcallany(self, device_id):
- command = 'devices -s %s' % device_id
- result = self.call_adb(command)
- return result
- pass
- # check for any fastboot device
- def fastbootany(self, device_id):
- command = 'devices -s %s' % device_id
- result = self.call_fastboot(command)
- return result
- pass
- # return list of attached devices
- def attached_devices(self):
- command_text = "adb devices -l"
- output = Popen(command_text, shell=True, stdout=PIPE, stderr=PIPE, stdin=PIPE)
- response = output.communicate()
- return response or None
- # result = self.call_adb(command)
- # devices = result.partition('\n')[2].replace('\n', '').split('\tdevice')
- # return [device for device in devices if len(device) > 2]
- # return result
- # fastboot return list of devices
- def fastboot_devices(self):
- command_text = 'fastboot devices'
- output = Popen(command_text, shell=True, stdout=PIPE, stderr=PIPE, stdin=PIPE)
- response = output.communicate()
- return response or None
- # command = "devices -l"
- # result = self.call_adb(command)
- # return result
- # get device state
- def get_state(self):
- results = ''
- command_text = 'adb get-state'
- output = Popen(command_text, shell=True, stdout=PIPE, stderr=PIPE, stdin=PIPE)
- response = output.communicate()
- return response or None
- #result = self.call_adb("get-state")
- #return result or None
- # install APK
- def install(self, path_to_app):
- command = "install %s" % path_to_app
- result = self.call_adb(command)
- return result
- # uninstall APK
- def uninstall(self, path_to_app, args):
- command = "uninstall %s" % path_to_app
- if 'keep' in args:
- command = "uninstall -k %s" % path_to_app
- result = self.call_adb(command)
- return result
- # reboot
- def reboot(self, rb_type):
- command = "reboot"
- if 'recovery' in rb_type:
- command += " recovery"
- elif 'bootloader' in rb_type:
- command += " bootloader"
- result = self.call_adb(command)
- return result
- # fastboot reboot
- def fastreboot(self, rb_type):
- command = "reboot"
- if 'bootloader' in rb_type:
- command = "reboot-bootloader"
- result = self.call_fastboot(command)
- return result
- # push files
- def push(self, local, remote):
- command = "push -p %s %s" % (local, remote)
- result = self.call_adb(command)
- return result
- # pull files
- def pull(self, remote, local):
- command = "pull -p %s %s" % (remote, local)
- result = self.call_adb(command)
- return result
- # sync
- def sync(self, **directory):
- command = "sync"
- if directory is not None:
- command = "sync %s" % directory
- result = self.call_adb(command)
- return result
- # shell command
- def shell(self, shellcmd):
- command = "shell " + shellcmd
- result = self.call_adb(command)
- return result
- # backup device
- def backup(self, backupfile):
- command = "backup -f %s -all" % backupfile
- result = self.call_adb(command)
- return result
- # restore device
- def restore(self, restorefile):
- command = "restore %s" % restorefile
- result = self.call_adb(command)
- return result
- # boot from image file
- def bootimg(self, boot_file):
- command = "boot " + boot_file
- result = self.call_fastboot(command)
- return result
- # install update ZIP
- def update(self, update_file):
- command = "update " + update_file
- result = self.call_fastboot(command)
- return result
- # fastboot flash image
- def flashf(self, type, file):
- command = "flash %s %s" % (type, file)
- result = self.call_fastboot(command)
- return result
- # unlock bootloader
- def unlockboot(self):
- command = "oem unlock"
- result = self.call_fastboot(command)
- return result
- # lock bootloader
- def lockboot(self):
- command = "oem lock"
- result = self.call_fastboot(command)
- return result
- # sideload installation
- def sideload(self, file):
- command = "sideload %s" % file
- result = self.call_adb(command)
- return result
- # bugreport
- def bugreport(self):
- command = "bugreport"
- result = self.call_adb(command)
- return result
- # wipe/erase partitions
- def wipe(self, parts):
- command = "-w erase"
- if 'system' in parts:
- command = "erase system"
- elif 'all' in parts:
- command = "flashall"
- elif 'data' in parts:
- command = "erase data"
- elif 'cache' in parts:
- command = "erase cache"
- elif 'boot' in parts:
- command = "erase boot"
- elif 'recovery' in parts:
- command = "erase recovery"
- elif 'flashall' in parts:
- command = "flashall"
- else:
- command = "-w erase system"
- result = self.call_fastboot(command)
- return result
Advertisement
Add Comment
Please, Sign In to add comment