示例#1
0
class Grabel(object):
    def __init__(self, serial_no: str):
        self.serial_no = serial_no
        self.mnc = MNCDevice(serial_no)
        self.adb = ADBDevice(serial_no)

    def get_tree(self) -> Tree:
        raw_xml = self.adb.dump_ui()
        xml_dict = xmltodict.parse(raw_xml, encoding="utf-8")

        c = Compiler()
        return c.compile2tree(xml_dict)

    def get_screen_array(self) -> np.ndarray:
        temp = "temp.png"
        self.mnc.screen_shot()
        self.mnc.export_screen(temp)
        obj = cv2.imread(temp)
        # remove temp file
        os.remove(temp)
        return obj

    @staticmethod
    def node_filter(tree: Tree, rules: dict) -> typing.List[Node]:
        result = list()
        for each in tree.loop_from_root():
            # custom filter
            for k, v in rules.items():
                if not hasattr(each, k):
                    continue
                if getattr(each, k) != v:
                    continue
                result.append(each)
        return result

    @staticmethod
    def get_node_location(node: Node) -> typing.Tuple:
        location_str = getattr(node, "@bounds")
        return tuple(re.findall(r"\[(.*?),(.*?)\]", location_str))

    @staticmethod
    def crop(
        origin: np.ndarray, left_top: typing.Sequence, right_bottom: typing.Sequence
    ) -> np.ndarray:
        return origin[
            int(left_top[1]) : int(right_bottom[1]),
            int(left_top[0]) : int(right_bottom[0]),
        ]

    def dump_csv(self, pic_name: str, node_list: typing.List[Node], type_: str) -> typing.List[str]:
        lines = list()
        for each in node_list:
            location = self.get_node_location(each)
            line = ",".join([pic_name, *location[0], *location[1], type_])
            lines.append(line)
        return lines
示例#2
0
    def __init__(self, serial_no: str = None, fps: int = 60):
        # args
        self.serial_no: str = serial_no
        self.fps: int = fps

        # others
        self.device: ADBDevice = ADBDevice(self.serial_no)
        self.record_stop: typing.Optional[typing.Callable] = None
        self.video_path: str = ""
        logger.info(f"capture config: {self.__dict__}")
示例#3
0
def main():
    parser = argparse.ArgumentParser(description="minadb cli")
    parser.add_argument("-s", "--serial_no", nargs="?")
    parser.add_argument("command", nargs="*", default="")
    args = parser.parse_args()

    serial_no = args.serial_no
    command = args.command
    if not command:
        pprint.pprint(ADBDevice.__dict__)
        raise RuntimeError("no command")
    func = command[0]
    extras = command[1:]
    device = ADBDevice(serial_no)
    assert hasattr(device, func), f"no function named {func}"
    getattr(device, func)(*extras)
示例#4
0
    def __init__(self,
                 serial_no: str = None,
                 fps: int = 60,
                 manual_mode: bool = None):
        super(ScrcpyCapture, self).__init__()
        # args
        self.serial_no: str = serial_no
        self.fps: int = fps

        # others
        self.device: ADBDevice = ADBDevice(self.serial_no)
        self.record_stop: typing.Optional[typing.Callable] = None
        self.record_proc: typing.Optional[subprocess.Popen] = None
        self.video_path: str = ""
        self.temp_video_path: str = ""
        self.manual_mode: bool = bool(manual_mode)
        logger.info(f"config: {self.__dict__}")
示例#5
0
 def __init__(self, serial_no: str):
     self.serial_no = serial_no
     self.mnc = MNCDevice(serial_no)
     self.adb = ADBDevice(serial_no)