@@ -0,0 +1,2978 @@
+#-*- encoding: utf-8 -*-%0A%0Aimport os%0Aimport sys%0Aimport getopt%0Aimport re%0Aimport math%0A%0Aclass AdbUtil(object):%0A%0A    def __init__(self, device=''):%0A        self.device = device%0A        if self.device == '' or self.device == None:%0A            self.cmd_prefix = 'adb'%0A        else:%0A            self.cmd_prefix = 'adb -s %25s' %25 self.device%0A%0A    def touch(self, coordinate):%0A        cmd = '%25s shell input tap %25d %25d' %25 (self.cmd_prefix, coordinate%5B0%5D, coordinate%5B1%5D)%0A        os.system(cmd)%0A%0A    def get_resolution(self):%0A        pattern = re.compile(r'.* (%5Cd+)x(%5Cd+).*')%0A        cmd = '%25s shell wm size' %25 self.cmd_prefix%0A        proc = os.popen(cmd)%0A        output = ''.join(proc.readlines())%0A        proc.close()%0A        rematch = pattern.match(output)%0A        if rematch is not None:%0A            resolution = %5Bint(rematch.group(1)), int(rematch.group(2))%5D%0A            return resolution%0A        else:%0A            return None%0A%0A    def get_density(self):%0A        pattern = re.compile(r'Physical density: (%5Cd+)')%0A        cmd = '%25s shell wm density' %25 self.cmd_prefix%0A        proc = os.popen(cmd)%0A        output = ''.join(proc.readlines())%0A        proc.close()%0A        rematch = pattern.match(output)%0A        if rematch is not None:%0A            density = int(rematch.group(1))%0A            return density%0A        else:%0A            return None%0A%0A    def get_screen_size(self):%0A        '''%0A        notice: not exactly%0A        '''%0A        resolution = self.get_resolution()%0A        if resolution is None:%0A            return None%0A%0A        density = self.get_density()%0A        if density is None:%0A            return None%0A%0A        return (math.sqrt(math.pow(resolution%5B0%5D,2)+math.pow(resolution%5B1%5D,2))/density)%0A%0Adef usage():%0A    print(%22%22%22%0A          usage: python adb_util.py %5Boptions%5D%0A%0A          Available options:%0A%0A          -s %7C --size       get screen size in Inch%0A          -r %7C --resolution get resolution%0A          -d %7C --density    get density%0A          %22%22%22)%0A%0Adef main():%0A    try:%0A        opts, args = getopt.getopt(sys.argv%5B1:%5D, 'srd', %5B'size', 'resolution', 'density'%5D)%0A    except getopt.GetoptError as err:%0A        opts = %5B%5D%0A%0A    if len(opts) == 0:%0A        usage()%0A        opts = %5B('-s', '')%5D%0A%0A    adb = AdbUtil()%0A%0A    for o, a in opts:%0A        if o in ('-s', '--size'):%0A            size = adb.get_screen_size()%0A            if size is None:%0A                print('get screen size failed')%0A            else:%0A                print('screen size is %25f inch' %25 size)%0A        elif o in ('-r', '--resolution'):%0A            resolution = adb.get_resolution()%0A            if resolution is None:%0A                print('get resolution failed')%0A            else:%0A                print('resolution is %25dx%25d' %25 (resolution%5B0%5D, resolution%5B1%5D))%0A        elif o in ('-d', '--density'):%0A            density = adb.get_density()%0A            if density is None:%0A                print('get density failed')%0A            else:%0A                print('density is %25d' %25 density)%0A%0Aif __name__ == '__main__':%0A    main()%0A

add adb util script