Exemplo n.º 1
0
    def generate_screenshot(self, origin):
        devicemappings = self._mapping_manager.get_all_devicemappings()
        screenshot_type: ScreenshotType = ScreenshotType.JPEG
        if devicemappings.get(origin, {}).get("screenshot_type", "jpeg") == "png":
            screenshot_type = ScreenshotType.PNG

        screenshot_quality: int = devicemappings.get(origin, {}).get("screenshot_quality", 80)

        temp_comm = self._ws_server.get_origin_communicator(origin)
        temp_comm.get_screenshot(generate_device_screenshot_path(origin, devicemappings, self._args),
                                 screenshot_quality, screenshot_type)

        filename = generate_device_screenshot_path(origin, devicemappings, self._args)
        image_resize(filename, os.path.join(mapadroid.MAD_ROOT, self._args.temp_path, "madmin"), width=250)

        return
Exemplo n.º 2
0
    def get_phonescreens(self):
        if not os.path.exists(
                os.path.join(mapadroid.MAD_ROOT, 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()
        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 <i class="fa fa-exclamation-triangle"></i></b>'
                        filename = generate_device_screenshot_path(
                            pho, devicemappings, self._args)
                        if os.path.isfile(filename):
                            image_resize(filename,
                                         os.path.join(mapadroid.MAD_ROOT,
                                                      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")