本文整理汇总了Python中util.adb_helper.AdbWrapper类的典型用法代码示例。如果您正苦于以下问题:Python AdbWrapper类的具体用法?Python AdbWrapper怎么用?Python AdbWrapper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AdbWrapper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: backup_sdcard
def backup_sdcard(self, local_dir, serial=None):
"""
Backup data from device's SDCard to local folder.
@param local_dir: the target local folder, will store data from device's SDCard to this folder.
"""
logger.info('Backing up SD card...')
# try to get the /sdcard folder on device
output, retcode = AdbWrapper.adb_shell('ls -d {0}; echo $?'.format(self._REMOTE_DIR_SDCARD), serial=serial)
output_list = [item for item in re.split(r'\n+', re.sub(r'\r+', '', output)) if item]
ret_code = output_list[-1]
output_list.remove(output_list[-1])
ret_msg = '\n'.join(output_list)
if ret_code == '0':
target_dir = os.path.join(local_dir, self._LOCAL_DIR_SDCARD)
os.makedirs(target_dir)
logger.info('Backup: {0} to {1}'.format(self._REMOTE_DIR_SDCARD, target_dir))
try:
AdbWrapper.adb_pull(self._REMOTE_DIR_SDCARD, target_dir, serial=serial)
except Exception as e:
logger.debug(e)
logger.error('Can not pull files from {0} to {1}.'.format(self._REMOTE_DIR_SDCARD, target_dir))
logger.info('Backup SD card done.')
else:
logger.info(ret_msg)
示例2: cli
def cli(self):
"""
Handle the argument parse, and the return the instance itself.
"""
# argument parser
arg_parser = argparse.ArgumentParser(description='Check the version information of Firefox OS.',
formatter_class=ArgumentDefaultsHelpFormatter)
arg_parser.add_argument('--no-color', action='store_true', dest='no_color', default=False,
help='Do not print with color. NO_COLOR will overrides this option.')
arg_parser.add_argument('-s', '--serial', action='store', dest='serial', default=None,
help='Directs command to the device or emulator with the given serial number. '
'Overrides ANDROID_SERIAL environment variable.')
arg_parser.add_argument('--log-text', action='store', dest='log_text', default=None, help='Text ouput.')
arg_parser.add_argument('--log-json', action='store', dest='log_json', default=None, help='JSON output.')
arg_parser.add_argument('-v', '--verbose', action='store_true', dest='verbose', default=False,
help='Turn on verbose output, with all the debug logger.')
# parse args and setup the logging
args = arg_parser.parse_args()
# setup the logging config
if args.verbose is True:
verbose_formatter = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
logging.basicConfig(level=logging.DEBUG, format=verbose_formatter)
else:
formatter = '%(levelname)s: %(message)s'
logging.basicConfig(level=logging.INFO, format=formatter)
# check ADB
AdbWrapper.check_adb()
# assign variable
self.set_no_color(args.no_color)
self.set_serial(args.serial)
self.set_log_text(args.log_text)
self.set_log_json(args.log_json)
# return instance
return self
示例3: cli
def cli(self):
"""
Handle the argument parse, and the return the instance itself.
"""
# argument parser
arg_parser = argparse.ArgumentParser(description='Reset Firefox OS Phone.',
formatter_class=ArgumentDefaultsHelpFormatter)
arg_parser.add_argument('-s', '--serial', action='store', dest='serial', default=None,
help='Directs command to the device or emulator with the given serial number.'
'Overrides ANDROID_SERIAL environment variable.')
arg_parser.add_argument('-v', '--verbose', action='store_true', dest='verbose', default=False,
help='Turn on verbose output, with all the debug logger.')
# parse args and setup the logging
args = arg_parser.parse_args()
# setup the logging config
if args.verbose is True:
verbose_formatter = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
logging.basicConfig(level=logging.DEBUG, format=verbose_formatter)
else:
formatter = '%(levelname)s: %(message)s'
logging.basicConfig(level=logging.INFO, format=formatter)
# check ADB
AdbWrapper.check_adb()
# assign the variable
self.set_serial(args.serial)
# return instance
return self
示例4: __init__
def __init__(self, **kwargs):
self.arg_parser = argparse.ArgumentParser(description='Enable Certified Apps Debugging.',
formatter_class=RawTextHelpFormatter,
epilog=textwrap.dedent('''\
Please enable "ADB and Devtools" of device.
Ref:
- https://developer.mozilla.org/en-US/docs/Tools/WebIDE
- https://developer.mozilla.org/en-US/docs/Tools/WebIDE/Running_and_debugging_apps#Debugging_apps
'''))
self.arg_parser.add_argument('-s', '--serial', action='store', dest='serial', default=None,
help=textwrap.dedent('''\
Directs command to the device or emulator with the
given serial number. Overrides ANDROID_SERIAL
environment variable. (default: %(default)s)
'''))
self.arg_parser.add_argument('--disable', action='store_true', dest='disable', default=False, help='Disable the privileges. (default: %(default)s)')
self.arg_parser.add_argument('-v', '--verbose', action='store_true', dest='verbose', default=False,
help=textwrap.dedent('''\
Turn on verbose output, with all the debug logger.
(default: %(default)s)
'''))
self.args = self.arg_parser.parse_args()
# setup the logging config
if self.args.verbose is True:
verbose_formatter = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
logging.basicConfig(level=logging.DEBUG, format=verbose_formatter)
else:
formatter = '%(levelname)s: %(message)s'
logging.basicConfig(level=logging.INFO, format=formatter)
AdbWrapper.check_adb()
示例5: __init__
def __init__(self, **kwargs):
self._FILE_PROFILE_INI = 'profiles.ini'
self._FILE_COMPATIBILITY_INI = 'compatibility.ini'
self._LOCAL_DIR_SDCARD = 'sdcard'
self._LOCAL_DIR_WIFI = 'wifi'
self._LOCAL_FILE_WIFI = 'wifi/wpa_supplicant.conf'
self._LOCAL_DIR_B2G = 'b2g-mozilla'
self._LOCAL_DIR_DATA = 'data-local'
self._LOCAL_DIR_DATA_APPS = 'webapps'
self._REMOTE_DIR_SDCARD = '/sdcard/'
self._REMOTE_FILE_WIFI = '/data/misc/wifi/wpa_supplicant.conf'
self._REMOTE_FILE_WIFI_OWNER = 'system:wifi'
self._REMOTE_DIR_B2G = '/data/b2g/mozilla'
self._REMOTE_DIR_DATA = '/data/local'
self.arg_parser = argparse.ArgumentParser(description='Workaround for backing up and restoring Firefox OS profiles. (BETA)',
formatter_class=ArgumentDefaultsHelpFormatter)
self.arg_parser.add_argument('-s', '--serial', action='store', dest='serial', default=None, help='Directs command to the device or emulator with the given serial number. Overrides ANDROID_SERIAL environment variable.')
br_group = self.arg_parser.add_mutually_exclusive_group(required=True)
br_group.add_argument('-b', '--backup', action='store_true', dest='backup', default=False, help='Backup user profile.')
br_group.add_argument('-r', '--restore', action='store_true', dest='restore', default=False, help='Restore user profile.')
self.arg_parser.add_argument('--sdcard', action='store_true', dest='sdcard', default=False, help='Also backup/restore SD card.')
self.arg_parser.add_argument('--no-reboot', action='store_true', dest='no_reboot', default=False, help='Do not reboot B2G after backup/restore.')
self.arg_parser.add_argument('-p', '--profile-dir', action='store', dest='profile_dir', default='mozilla-profile', help='Specify the profile folder.')
self.arg_parser.add_argument('-v', '--verbose', action='store_true', dest='verbose', default=False, help='Turn on verbose output, with all the debug logger.')
self.args = self.arg_parser.parse_args()
# setup the logging config
if self.args.verbose is True:
verbose_formatter = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
logging.basicConfig(level=logging.DEBUG, format=verbose_formatter)
else:
formatter = '%(levelname)s: %(message)s'
logging.basicConfig(level=logging.INFO, format=formatter)
AdbWrapper.check_adb()
示例6: get_crashreports
def get_crashreports(self, serial=None):
"""
Print the pending and submitted crash reports on device.
The submitted crashs report will be displayed with URL link.
@param serial: device serial number. (optional)
"""
AdbWrapper.adb_root(serial=serial)
logger.info('Getting Crash Reports...')
self.pending_stdout, retcode_pending = AdbWrapper.adb_shell('ls -al "{}"'.format(self.pending_path),
serial=serial)
print('Pending Crash Reports:\n{}\n'.format(self.pending_stdout))
self.submitted_stdout, retcode_submitted = AdbWrapper.adb_shell('ls -al "{}"'.format(self.submitted_path),
serial=serial)
print('Submitted Crash Reports:\n{}\n'.format(self.submitted_stdout))
# parse stdout for getting filepath
self.pending_files = self._parse_stdout(self.pending_path, self.pending_stdout)
self.submitted_files = self._parse_stdout(self.submitted_path, self.submitted_stdout)
self.submitted_url_list = []
if retcode_submitted == 0:
print('The links of Submitted Crash Reports:')
for line in self.submitted_stdout.split('\n'):
submmited_id = re.sub(r'\.txt\s*$', '', re.sub(r'^.+bp-', '', line))
submitted_url = 'https://crash-stats.mozilla.com/report/index/{}'.format(submmited_id)
self.submitted_url_list.append(submitted_url)
print(submitted_url)
示例7: prepare_step
def prepare_step(self):
# checking the adb root
if not AdbWrapper.adb_root(serial=self.serial):
raise Exception('No root permission for shallow flashing.')
# checking the adb remount
if not AdbWrapper.adb_remount(serial=self.serial):
raise Exception('No permission to remount for shallow flashing.')
# Stop B2G
B2GHelper.stop_b2g(serial=self.serial)
示例8: _check_profile_version
def _check_profile_version(self, local_dir, serial=None):
"""
Check the versions of backup and device.
The lower backup can restore to device. However the higher backup cannot.
@param local_dir: the local backup folder.
@param serial: device serial number. (optional)
@return: True if backup version is lower than device's.
@raise exception: if cannot load profiles or versions.
"""
if self.skip_version_check:
logger.info('Skip version check.')
return True
logger.info('Checking profile...')
# get local version
if os.path.isdir(local_dir):
local_profile_path = self._get_profile_path(
os.path.join(local_dir, self._LOCAL_DIR_B2G, self._FILE_PROFILE_INI))
version_of_backup = self._get_version_from_profile(
os.path.join(local_dir, self._LOCAL_DIR_B2G, local_profile_path, self._FILE_COMPATIBILITY_INI))
else:
raise Exception('Can not load profile from [{}]'.format(os.path.abspath(local_dir)))
tmp_dir = None
try:
# get remote version
tmp_dir = tempfile.mkdtemp(prefix='backup_restore_')
logger.debug('TEMP Folder for check profile: {}'.format(tmp_dir))
try:
AdbWrapper.adb_pull(os.path.join(self._REMOTE_DIR_B2G, self._FILE_PROFILE_INI), tmp_dir, serial=serial)
except:
raise Exception(
'Can not pull {2} from {0} to {1}. '
'Please run with --skip-version-check if you want to restore.'.format(
self._REMOTE_DIR_B2G, tmp_dir, self._FILE_PROFILE_INI))
remote_profile_path = self._get_profile_path(os.path.join(tmp_dir, self._FILE_PROFILE_INI))
try:
AdbWrapper.adb_pull(
os.path.join(self._REMOTE_DIR_B2G, remote_profile_path, self._FILE_COMPATIBILITY_INI), tmp_dir,
serial=serial)
except:
raise Exception(
'Can not pull {2} from {0} to {1}. '
'Please run with --skip-version-check if you want to restore.'.format(
self._REMOTE_DIR_B2G, tmp_dir, self._FILE_COMPATIBILITY_INI))
version_of_device = self._get_version_from_profile(
os.path.join(os.path.join(tmp_dir, self._FILE_COMPATIBILITY_INI)))
# compare
return self._compare_version(version_of_backup, version_of_device)
finally:
if tmp_dir:
logger.debug('Removing [{0}] folder...'.format(tmp_dir))
shutil.rmtree(tmp_dir)
logger.debug('TEMP Folder for check profile removed: {}'.format(tmp_dir))
示例9: restore_sdcard
def restore_sdcard(self, local_dir, serial=None):
logger.info('Restoring SD card...')
target_dir = os.path.join(local_dir, self._LOCAL_DIR_SDCARD)
if os.path.isdir(target_dir):
logger.info('Restore: {0} to {1}'.format(target_dir, self._REMOTE_DIR_SDCARD))
try:
AdbWrapper.adb_push(target_dir, self._REMOTE_DIR_SDCARD, serial=serial)
except:
logger.warning('Can not push files from {0} to {1}'.format(target_dir, self._REMOTE_DIR_SDCARD))
else:
logger.info('{0}: No such file or directory'.format(target_dir))
return
logger.info('Restore SD card done.')
示例10: prepare
def prepare(self):
"""
parse args and setup the logging
"""
self.args = self.arg_parser.parse_args()
# setup the logging config
if self.args.verbose is True:
verbose_formatter = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
logging.basicConfig(level=logging.DEBUG, format=verbose_formatter)
else:
formatter = "%(levelname)s: %(message)s"
logging.basicConfig(level=logging.INFO, format=formatter)
AdbWrapper.check_adb()
示例11: cli
def cli(self):
"""
Handle the argument parse, and the return the instance itself.
"""
# argument parser
arg_parser = argparse.ArgumentParser(
description='Workaround for backing up and restoring Firefox OS profiles. (BETA)',
formatter_class=ArgumentDefaultsHelpFormatter)
arg_parser.add_argument('-s', '--serial', action='store', dest='serial', default=None,
help='Directs command to the device or emulator with the given serial number. '
'Overrides ANDROID_SERIAL environment variable.')
br_group = arg_parser.add_mutually_exclusive_group(required=True)
br_group.add_argument('-b', '--backup', action='store_true', dest='backup', default=False,
help='Backup user profile.')
br_group.add_argument('-r', '--restore', action='store_true', dest='restore', default=False,
help='Restore user profile.')
arg_parser.add_argument('--sdcard', action='store_true', dest='sdcard', default=False,
help='Also backup/restore SD card.')
arg_parser.add_argument('--no-reboot', action='store_true', dest='no_reboot', default=False,
help='Do not reboot B2G after backup/restore.')
arg_parser.add_argument('-p', '--profile-dir', action='store', dest='profile_dir', default='mozilla-profile',
help='Specify the profile folder.')
arg_parser.add_argument('--skip-version-check', action='store_true', dest='skip_version_check', default=False,
help='Turn off version check between backup profile and device.')
arg_parser.add_argument('-v', '--verbose', action='store_true', dest='verbose', default=False,
help='Turn on verbose output, with all the debug logger.')
# parse args and setup the logging
args = arg_parser.parse_args()
# setup the logging config
if args.verbose is True:
verbose_formatter = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
logging.basicConfig(level=logging.DEBUG, format=verbose_formatter)
else:
formatter = '%(levelname)s: %(message)s'
logging.basicConfig(level=logging.INFO, format=formatter)
# check ADB
AdbWrapper.check_adb()
# assign the variable
self.set_serial(args.serial)
if args.backup:
self.set_backup(args.backup)
elif args.restore:
self.set_restore(args.restore)
self.set_sdcard(args.sdcard)
self.set_no_reboot(args.no_reboot)
self.set_profile_dir(args.profile_dir)
self.set_skip_version_check(args.skip_version_check)
# return instance
return self
示例12: __init__
def __init__(self, **kwargs):
self.arg_parser = argparse.ArgumentParser(description='Get the Crash Reports from Firefox OS Phone.',
formatter_class=ArgumentDefaultsHelpFormatter)
self.arg_parser.add_argument('-s', '--serial', action='store', dest='serial', default=None, help='Directs command to the device or emulator with the given serial number. Overrides ANDROID_SERIAL environment variable.')
self.arg_parser.add_argument('-v', '--verbose', action='store_true', dest='verbose', default=False, help='Turn on verbose output, with all the debug logger.')
self.args = self.arg_parser.parse_args()
# setup the logging config
if self.args.verbose is True:
verbose_formatter = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
logging.basicConfig(level=logging.DEBUG, format=verbose_formatter)
else:
formatter = '%(levelname)s: %(message)s'
logging.basicConfig(level=logging.INFO, format=formatter)
AdbWrapper.check_adb()
示例13: reset_phone
def reset_phone(self, serial=None):
# checking the adb root for backup/restore
if not AdbWrapper.adb_root(serial=serial):
raise Exception('No root permission for backup and resotre.')
# starting to reset
logger.info('Starting to Reset Firefox OS Phone...')
AdbWrapper.adb_shell('rm -r /cache/*', serial=serial)
AdbWrapper.adb_shell('mkdir /cache/recovery', serial=serial)
AdbWrapper.adb_shell('echo "--wipe_data" > /cache/recovery/command', serial=serial)
AdbWrapper.adb_shell('reboot recovery', serial=serial)
logger.info('Reset Firefox OS Phone done.')
示例14: _push_gecko
def _push_gecko(self, source_dir):
# push into device
logger.info('Pushing Gecko: Start')
gecko_dir = os.path.join(source_dir, 'b2g')
# push
target_path = '/system/b2g/'
logger.debug('adb push {} to {}'.format(gecko_dir, target_path))
AdbWrapper.adb_push(gecko_dir, target_path, serial=self.serial)
# set excutable
source_files = os.listdir(gecko_dir)
executable_files = [os.path.join('/system/b2g/', f) for f in source_files if os.access(os.path.join(gecko_dir, f), os.X_OK)]
logger.debug('Add executed permission on device: {}'.format(executable_files))
for file in executable_files:
AdbWrapper.adb_shell('chmod 777 {}'.format(file), serial=self.serial)
logger.info('Pushing Gecko: Done')
示例15: _clean_gaia
def _clean_gaia(self):
logger.info('Cleaning Gaia profile: Start')
command_list = ['rm -r /cache/*',
'rm -r /data/b2g/*',
'rm -r /data/local/storage/persistent/*',
'rm -r /data/local/svoperapps',
'rm -r /data/local/webapps',
'rm -r /data/local/user.js',
'rm -r /data/local/permissions.sqlite*',
'rm -r /data/local/OfflineCache',
'rm -r /data/local/indexedDB',
'rm -r /data/local/debug_info_trigger',
'rm -r /system/b2g/webapps']
for cmd in command_list:
AdbWrapper.adb_shell(cmd, serial=self.serial)
logger.info('Cleaning Gaia profile: Done')