Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- ##### PYADB v1.0 STABLE!
- ##### lazy, unfinished library to port ADB and FASTBOOT functions to PYTHON
- ##### author: vvn
- ##### release date: august 18, 2014
- ##### for now it's a required companion to the half-assed one plus one toolkit.
- ##### here is the half-assed one plus one toolkit: http://pastebin.com/ciAj8NJy
- ##### you need python 2.7 and the android SDK installed to run it. go to toolkit link above for download links.
- ##### this project is vaguely based on something i found on github but had way too many errors.
- ##### feel free to share, modify, whatever.
- ##### i don't care if you credit me, it'd be nice. though i prefer you buy my EP instead to thank me. :)
- ##### you can stream and buy it here: dreamcorp.bandcamp.com
- ##### questions, comments, feedback, bugs?
- ##### contact me at:
- ##### vvn (at) eudemonics (dot) org
- import os, readline
- from subprocess import call
- class pyADB(object):
- def call_adb(self, command):
- results = ''
- command_text = 'adb %s' % command
- results = call(command_text, shell=True)
- #while 1:
- # line = results.readline()
- # if not line: break
- # command_result += line
- return results
- def call_fastboot(self, command):
- results = ''
- command_text = 'fastboot %s' % command
- results = call(command_text, shell=True)
- return results
- # check for any fastboot device
- def fastboot(self, device_id):
- command = 'devices -s %s' % device_id
- result = self.call_fastboot(command)
- pass
- # return list of attached devices
- def attached_devices(self):
- command = "devices -l"
- 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 = "devices -l"
- result = self.call_adb(command)
- return result
- # get device state
- def get_state(self):
- 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):
- result = self.call_adb("push -p %s %s" % (local, remote))
- return result
- # pull files
- def pull(self, remote, local):
- result = self.call_adb("pull -p %s %s" % (remote, local))
- return result
- # sync
- def sync(self, **directory):
- command = "sync"
- if directory:
- command = "sync " + 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 %s" % boot_file
- result = self.call_fastboot(command)
- return result
- # install update ZIP
- def update(self, update_file):
- command = "update %s" % 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"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement