Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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...')

        pending, retcode_pending = AdbWrapper.adb_shell(
            'ls -al /data/b2g/mozilla/Crash\ Reports/pending', serial=serial)
        print('Pending Crash Reports:\n{}\n'.format(pending))

        submitted, retcode_submitted = AdbWrapper.adb_shell(
            'ls -al /data/b2g/mozilla/Crash\ Reports/submitted', serial=serial)
        print('Submitted Crash Reports:\n{}\n'.format(submitted))

        if retcode_submitted == 0:
            print('The links of Submitted Crash Reports:')
            for line in submitted.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)
                print(submitted_url)
Exemplo n.º 3
0
    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)
    def set_certapps(self, enable=True, serial=None):
        AdbWrapper.adb_root(serial=serial)
        logger.info('{} Full Privilege for WebIDE...'.format('Enabling' if enable else 'Disabling'))

        need_restart = True
        try:
            tmp_dir = tempfile.mkdtemp(prefix='enablecertapps_')
            # get profile folder name xxx.default under /data/b2g/mozilla/
            profile_dir_name, retcode = AdbWrapper.adb_shell('ls /data/b2g/mozilla/ | grep default', serial=serial)
            device_src_file = os.path.join('/data/b2g/mozilla/', profile_dir_name, 'prefs.js')
            dest_temp_file = os.path.join(tmp_dir, 'prefs.js.origin')
            try:
                logger.info('Pulling prefs.js file...')
                AdbWrapper.adb_pull(device_src_file, dest_temp_file, serial=serial)
            except:
                raise Exception('Error pulling prefs.js file.')

            dest_file = os.path.join(tmp_dir, 'prefs.js')
            with open(dest_temp_file, 'r') as fr:
                with open(dest_file, 'w') as fw:
                    match = False
                    is_forbid = 'false' if enable else 'true'
                    logger.debug('is_forbid: [{}]'.format(is_forbid))
                    for line in fr:
                        if 'devtools.debugger.forbid-certified-apps' in line:
                            logger.debug('line: [{}] to [{}]'.format(line, is_forbid))
                            if is_forbid in line:
                                # do not need to restart if the setting isn't changed
                                logger.info('The full privilege is already {}.'.format('enabled' if enable else 'disabled'))
                                need_restart = False
                                break
                            else:
                                logger.info('Changing setting of pref.js file...')
                                fw.write('user_pref("devtools.debugger.forbid-certified-apps", {});\n'.format(is_forbid))
                            match = True
                        else:
                            fw.write(line)
                    if not match:
                        if not enable:
                            # the forbid is true when there is no setting
                            logger.info('The full privilege is already disabled.')
                            need_restart = False
                        else:
                            if need_restart:
                                # adding setting when there is no setting and need to enable certapps
                                logger.info('Adding setting of pref.js file...')
                                fw.write('user_pref("devtools.debugger.forbid-certified-apps", {});\n'.format(is_forbid))
            if need_restart:
                B2GHelper.stop_b2g(serial=serial)
                try:
                    logger.info('Pushing prefs.js file...')
                    AdbWrapper.adb_push(dest_file, device_src_file, serial=serial)
                except:
                    raise Exception('Error pushing prefs.js file.')
        finally:
            if need_restart:
                B2GHelper.start_b2g(serial=serial)
            shutil.rmtree(tmp_dir)
Exemplo n.º 5
0
    def get_crashreports(self, serial=None):
        AdbWrapper.adb_root(serial=serial)
        logger.info('Getting Crash Reports...')

        pending, retcode_pending = AdbWrapper.adb_shell('ls -al /data/b2g/mozilla/Crash\ Reports/pending', serial=serial)
        print('Pending Crash Reports:\n{}\n'.format(pending))

        submitted, retcode_submitted = AdbWrapper.adb_shell('ls -al /data/b2g/mozilla/Crash\ Reports/submitted', serial=serial)
        print('Submitted Crash Reports:\n{}\n'.format(submitted))

        if retcode_submitted == 0:
            print('The links of Submitted Crash Reports:')
            for line in submitted.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)
                print(submitted_url)
Exemplo n.º 6
0
 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)
Exemplo n.º 7
0
 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)
Exemplo n.º 8
0
    def get_crashreports(self, serial=None):
        AdbWrapper.adb_root(serial=serial)
        logger.info('Getting Crash Reports...')

        pending, retcode_pending = AdbWrapper.adb_shell(
            'ls -al /data/b2g/mozilla/Crash\ Reports/pending', serial=serial)
        print('Pending Crash Reports:\n{}\n'.format(pending))

        submitted, retcode_submitted = AdbWrapper.adb_shell(
            'ls -al /data/b2g/mozilla/Crash\ Reports/submitted', serial=serial)
        print('Submitted Crash Reports:\n{}\n'.format(submitted))

        if retcode_submitted == 0:
            print('The links of Submitted Crash Reports:')
            for line in submitted.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)
                print(submitted_url)
Exemplo n.º 9
0
 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.')
Exemplo n.º 10
0
    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...')

        pending, retcode_pending = AdbWrapper.adb_shell('ls -al /data/b2g/mozilla/Crash\ Reports/pending', serial=serial)
        print('Pending Crash Reports:\n{}\n'.format(pending))

        submitted, retcode_submitted = AdbWrapper.adb_shell('ls -al /data/b2g/mozilla/Crash\ Reports/submitted', serial=serial)
        print('Submitted Crash Reports:\n{}\n'.format(submitted))

        if retcode_submitted == 0:
            print('The links of Submitted Crash Reports:')
            for line in submitted.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)
                print(submitted_url)
Exemplo n.º 11
0
 def reset_phone(self, serial=None):
     '''
     Reset the B2G device.
     @param serial: device serial number. (optional)
     @raise exception: When no root permission for reset device.
     '''
     # checking the adb root for backup/restore
     if not AdbWrapper.adb_root(serial=serial):
         raise Exception('No root permission for reset device.')
     # 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.')
Exemplo n.º 12
0
 def reset_phone(serial=None):
     """
     Reset the B2G device.
     @param serial: device serial number. (optional)
     @raise exception: When no root permission for reset device.
     """
     # checking the adb root for backup/restore
     if not AdbWrapper.adb_root(serial=serial):
         raise Exception('No root permission for reset device.')
     # 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.')
    def run(self):
        # get the device's serial number
        devices = AdbWrapper.adb_devices()
        if len(devices) == 0:
            raise Exception('No device.')
        else:
            device_serial = AdbHelper.get_serial(self.args.serial)
            if device_serial is None:
                if len(devices) == 1:
                    logger.debug('No serial, and only one device')
                else:
                    logger.debug('No serial, but there are more than one device')
                    raise Exception('Please specify the device by --serial option.')
            else:
                logger.debug('Setup serial to [{0}]'.format(device_serial))

        # checking the adb root for backup/restore
        if not AdbWrapper.adb_root(serial=device_serial):
            raise Exception('No root permission for backup and resotre.')

        # Backup
        if self.args.backup:
            try:
                logger.info('Target device [{0}]'.format(device_serial))
                # Create temp folder
                tmp_dir = tempfile.mkdtemp(prefix='backup_restore_')
                logger.debug('TEMP Foler: {}'.format(tmp_dir))
                # Stop B2G
                B2GHelper.stop_b2g(serial=device_serial)
                # Backup User Profile
                self.backup_profile(local_dir=tmp_dir, serial=device_serial)
                # Backup SDCard
                if self.args.sdcard:
                    self.backup_sdcard(local_dir=tmp_dir, serial=device_serial)
                # Copy backup files from temp folder to target folder
                if os.path.isdir(self.args.profile_dir):
                    logger.warning('Removing [{0}] folder...'.format(self.args.profile_dir))
                    shutil.rmtree(self.args.profile_dir)
                logger.info('Copy profile from [{0}] to [{1}].'.format(tmp_dir, self.args.profile_dir))
                shutil.copytree(tmp_dir, self.args.profile_dir)
                # Start B2G
                if not self.args.no_reboot:
                    B2GHelper.start_b2g(serial=device_serial)
            finally:
                logger.debug('Removing [{0}] folder...'.format(tmp_dir))
                shutil.rmtree(tmp_dir)
        # Restore
        elif self.args.restore:
            logger.info('Target device [{0}]'.format(device_serial))
            # Checking the Version of Profile
            if self.check_profile_version(local_dir=self.args.profile_dir, serial=device_serial):
                # Stop B2G
                B2GHelper.stop_b2g(serial=device_serial)
                # Restore User Profile
                self.restore_profile(local_dir=self.args.profile_dir, serial=device_serial)
                # Restore SDCard
                if self.args.sdcard:
                    self.restore_sdcard(local_dir=self.args.profile_dir, serial=device_serial)
                # Start B2G
                if not self.args.no_reboot:
                    B2GHelper.start_b2g(serial=device_serial)
            else:
                logger.warning('The version on device is smaller than backup\'s version.')
Exemplo n.º 14
0
    def set_certapps(self, enable=True, serial=None):
        '''
        Set the devtools permission for certapps.
        @param enable: True will turn on the permission. False will turn off the permission.
        @param serial: device serial number. (optional)
        @raise exception: When it cannot pulling/pushing the pref.js file of device.
        '''
        AdbWrapper.adb_root(serial=serial)
        logger.info('{} Full Privilege for WebIDE...'.format(
            'Enabling' if enable else 'Disabling'))

        need_restart = True
        try:
            tmp_dir = tempfile.mkdtemp(prefix='enablecertapps_')
            # get profile folder name xxx.default under /data/b2g/mozilla/
            profile_dir_name, retcode = AdbWrapper.adb_shell(
                'ls /data/b2g/mozilla/ | grep default', serial=serial)
            device_src_file = os.path.join('/data/b2g/mozilla/',
                                           profile_dir_name, 'prefs.js')
            dest_temp_file = os.path.join(tmp_dir, 'prefs.js.origin')
            try:
                logger.info('Pulling prefs.js file...')
                AdbWrapper.adb_pull(device_src_file,
                                    dest_temp_file,
                                    serial=serial)
            except:
                raise Exception('Error pulling prefs.js file.')

            dest_file = os.path.join(tmp_dir, 'prefs.js')
            with open(dest_temp_file, 'r') as fr:
                with open(dest_file, 'w') as fw:
                    match = False
                    is_forbid = 'false' if enable else 'true'
                    logger.debug('is_forbid: [{}]'.format(is_forbid))
                    for line in fr:
                        if 'devtools.debugger.forbid-certified-apps' in line:
                            logger.debug('line: [{}] to [{}]'.format(
                                line, is_forbid))
                            if is_forbid in line:
                                # do not need to restart if the setting isn't changed
                                logger.info(
                                    'The full privilege is already {}.'.format(
                                        'enabled' if enable else 'disabled'))
                                need_restart = False
                                break
                            else:
                                logger.info(
                                    'Changing setting of pref.js file...')
                                fw.write(
                                    'user_pref("devtools.debugger.forbid-certified-apps", {});\n'
                                    .format(is_forbid))
                            match = True
                        else:
                            fw.write(line)
                    if not match:
                        if not enable:
                            # the forbid is true when there is no setting
                            logger.info(
                                'The full privilege is already disabled.')
                            need_restart = False
                        else:
                            if need_restart:
                                # adding setting when there is no setting and need to enable certapps
                                logger.info(
                                    'Adding setting of pref.js file...')
                                fw.write(
                                    'user_pref("devtools.debugger.forbid-certified-apps", {});\n'
                                    .format(is_forbid))
            if need_restart:
                B2GHelper.stop_b2g(serial=serial)
                try:
                    logger.info('Pushing prefs.js file...')
                    AdbWrapper.adb_push(dest_file,
                                        device_src_file,
                                        serial=serial)
                except:
                    raise Exception('Error pushing prefs.js file.')
        finally:
            if need_restart:
                B2GHelper.start_b2g(serial=serial)
            shutil.rmtree(tmp_dir)
    def run(self):
        # get the device's serial number
        devices = AdbWrapper.adb_devices()
        if len(devices) == 0:
            raise Exception('No device.')
        else:
            device_serial = AdbHelper.get_serial(self.args.serial)
            if device_serial is None:
                if len(devices) == 1:
                    logger.debug('No serial, and only one device')
                else:
                    logger.debug(
                        'No serial, but there are more than one device')
                    raise Exception(
                        'Please specify the device by --serial option.')
            else:
                logger.debug('Setup serial to [{0}]'.format(device_serial))

        # checking the adb root for backup/restore
        if not AdbWrapper.adb_root(serial=device_serial):
            raise Exception('No root permission for backup and resotre.')

        # Backup
        if self.args.backup:
            try:
                logger.info('Target device [{0}]'.format(device_serial))
                # Create temp folder
                tmp_dir = tempfile.mkdtemp(prefix='backup_restore_')
                logger.debug('TEMP Foler: {}'.format(tmp_dir))
                # Stop B2G
                B2GHelper.stop_b2g(serial=device_serial)
                # Backup User Profile
                self.backup_profile(local_dir=tmp_dir, serial=device_serial)
                # Backup SDCard
                if self.args.sdcard:
                    self.backup_sdcard(local_dir=tmp_dir, serial=device_serial)
                # Copy backup files from temp folder to target folder
                if os.path.isdir(self.args.profile_dir):
                    logger.warning('Removing [{0}] folder...'.format(
                        self.args.profile_dir))
                    shutil.rmtree(self.args.profile_dir)
                logger.info('Copy profile from [{0}] to [{1}].'.format(
                    tmp_dir, self.args.profile_dir))
                shutil.copytree(tmp_dir, self.args.profile_dir)
                # Start B2G
                if not self.args.no_reboot:
                    B2GHelper.start_b2g(serial=device_serial)
            finally:
                logger.debug('Removing [{0}] folder...'.format(tmp_dir))
                shutil.rmtree(tmp_dir)
        # Restore
        elif self.args.restore:
            logger.info('Target device [{0}]'.format(device_serial))
            # Checking the Version of Profile
            if self.check_profile_version(local_dir=self.args.profile_dir,
                                          serial=device_serial):
                # Stop B2G
                B2GHelper.stop_b2g(serial=device_serial)
                # Restore User Profile
                self.restore_profile(local_dir=self.args.profile_dir,
                                     serial=device_serial)
                # Restore SDCard
                if self.args.sdcard:
                    self.restore_sdcard(local_dir=self.args.profile_dir,
                                        serial=device_serial)
                # Start B2G
                if not self.args.no_reboot:
                    B2GHelper.start_b2g(serial=device_serial)
            else:
                logger.warning(
                    'The version on device is smaller than backup\'s version.')