Ejemplo n.º 1
0
    def get_phonescreens(self):
        if not os.path.exists(os.path.join(self._args.temp_path, "madmin")):
            os.makedirs(os.path.join(self._args.temp_path, "madmin"))

        screens_phone = []
        ws_connected_phones = []
        if self._ws_server is not None:
            phones = self._ws_server.get_reg_origins().copy()
        else:
            phones = []
        devicemappings = self._mapping_manager.get_all_devicemappings()

        # Sort devices by name.
        phones = sorted(phones)
        for phonename in phones:
            ws_connected_phones.append(phonename)
            add_text = ""
            adb_option = False
            adb = devicemappings.get(phonename, {}).get('adb', False)
            if adb is not None and self._adb_connect.check_adb_status(
                    adb) is not None:
                self._ws_connected_phones.append(adb)
                adb_option = True
                add_text = '<b>ADB</b>'
            else:
                self._ws_connected_phones.append(adb)

            filename = generate_device_screenshot_path(phonename,
                                                       devicemappings,
                                                       self._args)
            try:
                screenshot_ending: str = ".jpg"
                image_resize(filename,
                             os.path.join(self._args.temp_path, "madmin"),
                             width=250)
                screen = "screenshot/madmin/screenshot_" + str(
                    phonename) + screenshot_ending
                screens_phone.append(
                    generate_phones(phonename,
                                    add_text,
                                    adb_option,
                                    screen,
                                    filename,
                                    self._datetimeformat,
                                    dummy=False))
            except IOError:
                screen = "static/dummy.png"
                screens_phone.append(
                    generate_phones(phonename,
                                    add_text,
                                    adb_option,
                                    screen,
                                    filename,
                                    self._datetimeformat,
                                    dummy=True))
                try:
                    os.remove(filename)
                    self._logger.info(
                        "Screenshot {} was corrupted and has been deleted",
                        filename)
                except:
                    pass

        for phonename in self._adb_connect.return_adb_devices():
            if phonename.serial not in self._ws_connected_phones:
                devicemappings = self._mapping_manager.get_all_devicemappings()
                for pho in devicemappings:
                    if phonename.serial == devicemappings[pho].get(
                            'adb', False):
                        adb_option = True
                        add_text = '<b>ADB - no WS<img src="/static/warning.png" width="20px" ' \
                                   'alt="NO websocket connection!"></b>'
                        filename = generate_device_screenshot_path(
                            pho, devicemappings, self._args)
                        if os.path.isfile(filename):
                            image_resize(filename,
                                         os.path.join(self._args.temp_path,
                                                      "madmin"),
                                         width=250)
                            screenshot_ending: str = ".jpg"
                            screen = "screenshot/madmin/screenshot_" + str(
                                pho) + screenshot_ending
                            screens_phone.append(
                                generate_phones(pho,
                                                add_text,
                                                adb_option,
                                                screen,
                                                filename,
                                                self._datetimeformat,
                                                dummy=False))
                        else:
                            screen = "static/dummy.png"
                            screens_phone.append(
                                generate_phones(pho,
                                                add_text,
                                                adb_option,
                                                screen,
                                                filename,
                                                self._datetimeformat,
                                                dummy=True))

        return render_template('phonescreens.html',
                               editform=screens_phone,
                               header="Device control",
                               title="Device control")
Ejemplo n.º 2
0
    def get_phonescreens(self):
        if not os.path.exists(os.path.join(self._args.temp_path, "madmin")):
            os.makedirs(os.path.join(self._args.temp_path, "madmin"))

        screens_phone = []
        ws_connected_phones = []
        if self._ws_server is not None:
            phones = self._ws_server.get_reg_origins().copy()
        else:
            phones = []
        for phonename in phones:
            ws_connected_phones.append(phonename)
            add_text = ""
            adb_option = False
            adb = self._device_mapping[phonename].get('adb', False)
            if adb is not None and self._adb_connect.check_adb_status(
                    adb) is not None:
                self._ws_connected_phones.append(adb)
                adb_option = True
                add_text = '<b>ADB</b>'
            else:
                self._ws_connected_phones.append(adb)

            filename = generate_device_screenshot_path(phonename,
                                                       self._device_mapping,
                                                       self._args)
            if os.path.isfile(filename):
                screenshot_ending: str = ".jpg"
                image_resize(filename,
                             os.path.join(self._args.temp_path, "madmin"),
                             width=250)
                screen = "screenshot/madmin/screenshot_" + str(
                    phonename) + screenshot_ending
                screens_phone.append(
                    generate_phones(phonename,
                                    add_text,
                                    adb_option,
                                    screen,
                                    filename,
                                    self._datetimeformat,
                                    dummy=False))
            else:
                screen = "static/dummy.png"
                screens_phone.append(
                    generate_phones(phonename,
                                    add_text,
                                    adb_option,
                                    screen,
                                    filename,
                                    self._datetimeformat,
                                    dummy=True))

        for phonename in self._adb_connect.return_adb_devices():
            if phonename.serial not in self._ws_connected_phones:
                for pho in self._device_mapping:
                    if phonename.serial == self._device_mapping[pho].get(
                            'adb', False):
                        adb_option = True
                        add_text = '<b>ADB - no WS<img src="/static/warning.png" width="20px" ' \
                                   'alt="NO websocket connection!"></b>'
                        filename = generate_device_screenshot_path(
                            pho, self._device_mapping, self._args)
                        if os.path.isfile(filename):
                            image_resize(filename,
                                         os.path.join(self._args.temp_path,
                                                      "madmin"),
                                         width=250)
                            screenshot_ending: str = ".jpg"
                            screen = "screenshot/madmin/screenshot_" + str(
                                pho) + screenshot_ending
                            screens_phone.append(
                                generate_phones(pho,
                                                add_text,
                                                adb_option,
                                                screen,
                                                filename,
                                                self._datetimeformat,
                                                dummy=False))
                        else:
                            screen = "static/dummy.png"
                            screens_phone.append(
                                generate_phones(pho,
                                                add_text,
                                                adb_option,
                                                screen,
                                                filename,
                                                self._datetimeformat,
                                                dummy=True))

        return render_template('phonescreens.html',
                               editform=screens_phone,
                               header="Phonecontrol",
                               title="Phonecontrol",
                               running_ocr=(self._args.only_ocr))