r'.*DisplayViewport{valid=true, .*orientation=(?P<orientation>\d+), .*deviceWidth=(?P<width>\d+), deviceHeight=(?P<height>\d+).*' ) _PROP_PATTERN = re.compile(r'\[(?P<key>.*?)\]:\s*\[(?P<value>.*)\]') _INPUT_METHOD_RE = re.compile(r'mCurMethodId=([-_./\w]+)') _DEFAULT_IME = 'com.netease.atx.assistant/.ime.Utf7ImeService' UINode = collections.namedtuple('UINode', [ 'xml', 'bounds', 'selected', 'checkable', 'clickable', 'scrollable', 'focusable', 'enabled', 'focused', 'long_clickable', 'password', 'class_name', 'index', 'resource_id', 'text', 'content_desc', 'package' ]) log = logutils.getLogger(__name__) def getenvs(*names): for name in names: if os.getenv(name): return os.getenv(name) class AndroidDevice(DeviceMixin, UiaDevice): def __init__(self, serialno=None, **kwargs): """Initial AndroidDevice Args: serialno: string specify which device Returns:
import cv2 import tornado.ioloop import tornado.web import tornado.websocket from tornado.concurrent import run_on_executor from concurrent.futures import ThreadPoolExecutor # `pip install futures` for python2 import atx from atx import logutils from atx import base from atx import imutils __dir__ = os.path.dirname(os.path.abspath(__file__)) log = logutils.getLogger("webide", level=logging.DEBUG) log.setLevel(logging.DEBUG) IMAGE_PATH = ['.', 'imgs', 'images'] workdir = '.' device = None atx_settings = {} def read_file(filename, default=''): if not os.path.isfile(filename): return default with open(filename, 'rb') as f: return f.read()
import subprocess32 as subprocess import shutil import sys import time import tempfile import urllib2 import tqdm import atx.androaxml as apkparse from atx import logutils from atx import adbkit from atx.cmds import utils log = logutils.getLogger('install') DEFAULT_REMOTE_PATH = '/data/local/tmp/_atx_tmp.apk' __apks = dict( utf8ime='http://7rfh09.com2.z0.glb.qiniucdn.com/Utf7Ime.apk') def clean(tmpdir): log.info('Remove temp directory') shutil.rmtree(tmpdir) def adb_pushfile(adb, filepath, remote_path): filesize = os.path.getsize(filepath) pb = tqdm.tqdm(unit='B', unit_scale=True, total=filesize) p = adb.raw_cmd('push', filepath, remote_path)
# Created: ydbn2153 <2016-03-15> # Modified: hzsunshx <2016-03-19> import argparse import os import sys import shutil import subprocess import tempfile import urllib import functools from atx import logutils from atx.cmds.utils import http_download logger = logutils.getLogger('minicap') def log(*args): logger.info(*args) def check_output(cmdstr, shell=True): output = subprocess.check_output(cmdstr, stderr=subprocess.STDOUT, shell=shell) return output def run_adb(*args, **kwargs): cmds = ['adb'] serialno = kwargs.get('serialno', None) if serialno:
# -*- coding: utf-8 -*- from __future__ import absolute_import import functools import os import sys import subprocess32 as subprocess import tempfile import inspect from PIL import Image from atx import logutils logger = logutils.getLogger(__name__) def look_path(name, search_paths=[], env_path=True): os.pathsep if env_path: search_paths += os.getenv('PATH').split(os.pathsep) for directory in search_paths: if not os.path.isdir(directory): continue filepath = os.path.join(directory, name) if os.path.isfile(filepath): return filepath return None __execpath = {}
import re import subprocess32 as subprocess import shutil import sys import time import tempfile import urllib2 import tqdm import atx.androaxml as apkparse from atx import logutils from atx import adbkit from atx.cmds import utils log = logutils.getLogger('install') DEFAULT_REMOTE_PATH = '/data/local/tmp/_atx_tmp.apk' __apks = { 'utf7ime': 'http://o8oookdsx.qnssl.com/android_unicode_ime-debug.apk', 'atx-assistant': 'http://obq2bnw3f.bkt.clouddn.com/atx-assistant-latest.apk', } def clean(tmpdir): log.info('Remove temp directory') shutil.rmtree(tmpdir) def adb_pushfile(adb, filepath, remote_path): filesize = os.path.getsize(filepath)
#!/usr/bin/env python # -*- coding: utf-8 -*- import threading import time from functools import partial from atx import logutils log = logutils.getLogger(__name__) #base.getLogger('patch') def run_once(f): ''' Decorator: Make sure function only call once not thread safe @run_once def foo(): print 'bar' return 1+2 foo() foo() # 'bar' only print once ''' def wrapper(*args, **kwargs): if not wrapper.has_run: wrapper.result = f(*args, **kwargs) wrapper.has_run = True return wrapper.result wrapper.has_run = False
import json import cv2 import tornado.ioloop import tornado.web import tornado.websocket from tornado.concurrent import run_on_executor from concurrent.futures import ThreadPoolExecutor # `pip install futures` for python2 from atx import logutils from atx import base from atx import imutils __dir__ = os.path.dirname(os.path.abspath(__file__)) log = logutils.getLogger("webide") log.setLevel(logging.DEBUG) IMAGE_PATH = ['.', 'imgs', 'images'] workdir = '.' def read_file(filename, default=''): if not os.path.isfile(filename): return default with open(filename, 'rb') as f: return f.read() def write_file(filename, content): with open(filename, 'w') as f:
import numpy as np import aircv as ac from uiautomator import AutomatorDeviceObject from PIL import Image from atx import consts from atx import errors from atx import patch from atx import base from atx import logutils from atx import imutils from atx import adb from atx.device import Pattern, Bounds, FindPoint log = logutils.getLogger('atx') log.setLevel(logging.INFO) __dir__ = os.path.dirname(os.path.abspath(__file__)) _Condition = collections.namedtuple('WatchCondition', ['pattern', 'exists']) class WatcherItem(object): """ How to use, for example: with d.watch('xx') as w: w.on('button.png').on('enter.png').click() w.on('yes.png').on_not('exit.png').click()
#!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import absolute_import from __future__ import print_function import time import threading from functools import partial from atx import logutils log = logutils.getLogger(__name__) #base.getLogger('patch') def run_once(f): ''' Decorator: Make sure function only call once not thread safe @run_once def foo(): print 'bar' return 1+2 foo() foo() # 'bar' only print once ''' def wrapper(*args, **kwargs): if not wrapper.has_run: wrapper.result = f(*args, **kwargs) wrapper.has_run = True
# http://www.tutorialspoint.com/python/tk_canvas.htm import os import time import threading import logging import Tkinter as tk import tkSimpleDialog import tkFileDialog from Queue import Queue import atx from atx import logutils from PIL import Image, ImageTk log = logutils.getLogger('tkgui') log.setLevel(logging.DEBUG) def insert_code(filename, code, save=True, marker='# ATX CODE END'): """ Auto append code """ content = '' found = False for line in open(filename, 'rb'): if not found and line.strip() == marker: found = True cnt = line.find(marker) content += line[:cnt] + code content += line if not found: if not content.endswith('\n'):
import cv2 import numpy as np import aircv as ac from uiautomator import AutomatorDeviceObject from PIL import Image from atx import consts from atx import errors from atx import patch from atx import base from atx import logutils from atx import imutils from atx import adb from atx.device import Pattern, Bounds, FindPoint log = logutils.getLogger('atx') log.setLevel(logging.INFO) __dir__ = os.path.dirname(os.path.abspath(__file__)) _Condition = collections.namedtuple('WatchCondition', ['pattern', 'exists']) class WatcherItem(object): """ How to use, for example: with d.watch('xx') as w: w.on('button.png').on('enter.png').click() w.on('yes.png').on_not('exit.png').click()
# Created: ydbn2153 <2016-03-15> # Modified: hzsunshx <2016-03-19> import argparse import os import sys import shutil import subprocess import tempfile import urllib import functools from atx import logutils from atx.cmds.utils import http_download logger = logutils.getLogger('minicap') def log(*args): logger.info(*args) def check_output(cmdstr, shell=True): output = subprocess.check_output(cmdstr, stderr=subprocess.STDOUT, shell=shell) return output def run_adb(*args, **kwargs): cmds = ['adb']
import socket import time import tornado.ioloop import tornado.web import tornado.websocket from tornado.concurrent import run_on_executor from concurrent.futures import ThreadPoolExecutor # `pip install futures` for python2 from atx import logutils from atx import base __dir__ = os.path.dirname(os.path.abspath(__file__)) log = logutils.getLogger("webide") log.setLevel(logging.DEBUG) IMAGE_PATH = ['.', 'imgs', 'images'] workdir = '.' def read_file(filename, default=''): if not os.path.isfile(filename): return default with open(filename, 'rb') as f: return f.read() def write_file(filename, content): with open(filename, 'w') as f: f.write(content.encode('utf-8'))