Пример #1
0
 def download_check(self):
     upload_rgc(self.storage_elem)
     gen = file_generator(self.db_wrapper, self.storage_elem, APK_Type.rgc, APK_Arch.noarch)
     data = io.BytesIO()
     for chunk in gen:
         data.write(chunk)
     self.assertTrue(data.getbuffer().nbytes == os.stat(filepath_rgc).st_size)
Пример #2
0
    def start_job_type(self, item, jobtype, ws_conn):
        try:
            jobtype = JobType[jobtype.split('.')[1]]
            if jobtype == JobType.INSTALLATION:
                file_ = self._log[str(item)]['file']
                if str(file_).lower().endswith(".apk"):
                    returning = ws_conn.install_apk(300,
                                                    filepath=os.path.join(
                                                        self._args.upload_path,
                                                        file_))
                elif str(file_).lower().endswith(".zip"):
                    returning = ws_conn.install_bundle(
                        600,
                        filepath=os.path.join(self._args.upload_path, file_))
                else:
                    # unknown filetype
                    returning = False
                return returning if not 'RemoteGpsController'.lower() in str(
                    file_).lower() else True
            elif jobtype == jobtype.SMART_UPDATE:
                package_ver: str = None
                package_raw = self._log[str(item)]['file']
                version_job = "dumpsys package %s | grep versionName" % (
                    package_raw, )
                architecture_job = ws_conn.passthrough(
                    'getprop ro.product.cpu.abi')
                package_ver_job = ws_conn.passthrough(version_job)
                try:
                    architecture_raw = re.search(r'\[(\S+)\]',
                                                 architecture_job).group(1)
                except AttributeError:
                    logger.warning(
                        'Unable to determine the architecture of the device')
                    return False
                try:
                    package_ver = re.search(r'versionName=([0-9\.]+)',
                                            package_ver_job).group(1)
                except AttributeError:
                    if package_ver_job and package_ver_job.split(
                            '\n')[0].strip() == 'OK':
                        logger.info(
                            'No information returned.  Assuming package is not installed'
                        )
                    else:
                        logger.warning(
                            'Unable to determine version for {}: {}',
                            self._log[str(item)]['file'], package_ver_job)
                        return False
                package = getattr(APKType, APKPackage(package_raw).name)
                architecture = lookup_arch_enum(architecture_raw)
                package_all: MADPackages = self._storage_obj.get_current_package_info(
                    package)
                if package_all is None:
                    logger.warning('No MAD APK for {} [{}]', package,
                                   architecture.name)
                    return False
                try:
                    mad_apk = package_all[architecture]
                except KeyError:
                    architecture = APKArch.noarch
                    mad_apk = package_all[architecture.noarch]

                if mad_apk.filename is None:
                    logger.warning('No MAD APK for {} [{}]', package,
                                   architecture.name)
                    return False
                # Validate it is supported
                if package == APKType.pogo:
                    if not supported_pogo_version(architecture,
                                                  mad_apk.version):
                        self.write_status_log(str(item),
                                              field='status',
                                              value='not supported')
                        return True
                if not is_newer_version(mad_apk.version, package_ver):
                    logger.info(
                        'Both versions are the same.  No update required')
                    self.write_status_log(str(item),
                                          field='status',
                                          value='not required')
                    return True
                else:
                    logger.info('Smart Update APK Installation for {} to {}',
                                package.name, self._log[str(item)]['origin'])
                    apk_file = bytes()
                    for chunk in file_generator(self._db, self._storage_obj,
                                                package, architecture):
                        apk_file += chunk
                    if mad_apk.mimetype == 'application/zip':
                        returning = ws_conn.install_bundle(300, data=apk_file)
                    else:
                        returning = ws_conn.install_apk(300, data=apk_file)
                    return returning if not 'RemoteGpsController'.lower(
                    ) in str(self._log[str(item)]['file']).lower() else True
            elif jobtype == JobType.REBOOT:
                return ws_conn.reboot()
            elif jobtype == JobType.RESTART:
                return ws_conn.restart_app("com.nianticlabs.pokemongo")
            elif jobtype == JobType.STOP:
                return ws_conn.stop_app("com.nianticlabs.pokemongo")
            elif jobtype == JobType.START:
                return ws_conn.start_app("com.nianticlabs.pokemongo")
            elif jobtype == JobType.PASSTHROUGH:
                command = self._log[str(item)]['file']
                returning = ws_conn.passthrough(command).replace(
                    '\r', '').replace('\n', '').replace('  ', '')
                self.write_status_log(str(item),
                                      field='returning',
                                      value=returning)
                self.set_returning(
                    origin=self._log[str(item)]['origin'],
                    fieldname=self._log[str(item)].get('fieldname'),
                    value=returning)
                return returning if 'KO' not in returning else False
            return False
        except Exception as e:
            logger.error(
                'Error while getting response from device - Reason: {}', e)
        return False
Пример #3
0
 def test_check_invalid(self):
     gen = file_generator(self.db_wrapper, self.storage_elem, APK_Type.rgc, APK_Arch.noarch)
     self.assertTrue(isinstance(gen, Response))
     self.assertTrue(gen.status_code == 404)