Skip to content

Commit

Permalink
Add adb root command for backup/restore.
Browse files Browse the repository at this point in the history
  • Loading branch information
askeing committed Jun 30, 2015
1 parent fe9fbfc commit de53af8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
22 changes: 14 additions & 8 deletions backup_restore_profile.py
Expand Up @@ -189,15 +189,21 @@ def run(self):
elif 'ANDROID_SERIAL' in os.environ and os.environ['ANDROID_SERIAL'] in devices: elif 'ANDROID_SERIAL' in os.environ and os.environ['ANDROID_SERIAL'] in devices:
self.logger.debug('Setup serial to [{0}] by ANDROID_SERIAL'.format(os.environ['ANDROID_SERIAL'])) self.logger.debug('Setup serial to [{0}] by ANDROID_SERIAL'.format(os.environ['ANDROID_SERIAL']))
device_serial = os.environ['ANDROID_SERIAL'] device_serial = os.environ['ANDROID_SERIAL']
elif self.args.serial is None and not 'ANDROID_SERIAL' in os.environ:
if len(devices) == 1:
self.logger.debug('No serial, and only one device')
device_serial = None
else:
self.logger.debug('No serial, but there are more than one device')
self.logger.warning('Please specify the device by --serial option.')
exit(1)
else: else:
if self.args.serial is None and not 'ANDROID_SERIAL' in os.environ: device_serial = None
if len(devices) == 1:
self.logger.debug('No serial, and only one device') # checking the adb root for backup/restore
device_serial = None if not AdbHelper.adb_root(serial=device_serial):
else: exit(2)
self.logger.debug('No serial, but there are more than one device')
self.logger.warning('Please specify the device by --serial option.')
exit(1)
# Backup # Backup
if self.args.backup: if self.args.backup:
try: try:
Expand Down
17 changes: 17 additions & 0 deletions utilities/adb_helper.py
Expand Up @@ -79,3 +79,20 @@ def adb_shell(command, serial=None):
AdbHelper.logger.debug('cmd: {0}'.format(cmd)) AdbHelper.logger.debug('cmd: {0}'.format(cmd))
AdbHelper.logger.debug('output: {0}'.format(output)) AdbHelper.logger.debug('output: {0}'.format(output))
return output return output

@staticmethod
def adb_root(serial=None):
if serial is None:
cmd = 'adb root'
else:
cmd = 'adb -s %s root' % (serial,)
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output = p.communicate()[0]
AdbHelper.logger.debug('cmd: {0}'.format(cmd))
AdbHelper.logger.debug('output: {0}'.format(output))
if p.returncode is 0 and (not 'cannot' in output):
AdbHelper.logger.info(output)
return True
else:
AdbHelper.logger.warning(output)
return False

0 comments on commit de53af8

Please sign in to comment.