Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# _*_ coding:UTF-8 _*_
import os
import json
import time
import inspect
import functools
import traceback
from copy import copy
from .logger import get_logger
from .snippet import reg_cleanup
LOGGING = get_logger(__name__)
class AirtestLogger(object):
"""logger """
def __init__(self, logfile):
super(AirtestLogger, self).__init__()
self.running_stack = []
self.logfile = None
self.logfd = None
self.set_logfile(logfile)
reg_cleanup(self.handle_stacked_log)
def set_logfile(self, logfile):
if logfile:
self.logfile = os.path.realpath(logfile)
self.logfd = open(self.logfile, "w")
"""模板匹配.
对用户提供的调节参数:
1. threshod: 筛选阈值,默认为0.8
2. rgb: 彩色三通道,进行彩色权识别.
"""
import cv2
import time
from airtest.utils.logger import get_logger
from .utils import generate_result, check_source_larger_than_search, img_mat_rgb_2_gray
from .cal_confidence import cal_rgb_confidence
LOGGING = get_logger(__name__)
def print_run_time(func):
def wrapper(self, *args, **kwargs):
start_time = time.time()
ret = func(self, *args, **kwargs)
LOGGING.debug("%s() run time is %.2f s." % (func.__name__, time.time() - start_time))
return ret
return wrapper
class TemplateMatching(object):
"""模板匹配."""
from urlparse import urljoin
from airtest import aircv
from airtest.core.device import Device
from airtest.core.ios.constant import CAP_METHOD, TOUCH_METHOD, IME_METHOD
from airtest.core.ios.rotation import XYTransformer, RotationWatcher
from airtest.core.ios.fake_minitouch import fakeMiniTouch
from airtest.core.ios.instruct_helper import InstructHelper
from airtest.utils.logger import get_logger
# roatations of ios
from wda import LANDSCAPE, PORTRAIT, LANDSCAPE_RIGHT, PORTRAIT_UPSIDEDOWN
from wda import WDAError
logger = get_logger(__name__)
DEFAULT_ADDR = "http://localhost:8100/"
# retry when saved session failed
def retry_session(func):
def wrapper(self, *args, **kwargs):
try:
return func(self, *args, **kwargs)
except WDAError as err:
# 6 : Session does not exist
if err.status == 6:
self._fetchNewSession()
return func(self, *args, **kwargs)
else:
raise err
return wrapper
# -*- coding: utf-8 -*-
import subprocess
import time
import sys
import random
from airtest.core.error import AirtestError
from airtest.utils.snippet import reg_cleanup, on_method_ready, get_std_encoding
from airtest.utils.logger import get_logger
from airtest.utils.retry import retries
LOGGING = get_logger(__name__)
class InstructHelper(object):
"""
ForwardHelper class
or help run other Instruction
"""
proxy_process = 'iproxy'
def __init__(self):
self.subprocessHandle = []
reg_cleanup(self.teardown)
@on_method_ready('start')
def get_ready(self):
import threading
from six import PY3, text_type, binary_type
from six.moves import reduce
from airtest.core.android.constant import (DEFAULT_ADB_PATH, IP_PATTERN,
SDK_VERISON_NEW)
from airtest.core.error import (AdbError, AdbShellError, AirtestError,
DeviceConnectionError)
from airtest.utils.compat import decode_path
from airtest.utils.logger import get_logger
from airtest.utils.nbsp import NonBlockingStreamReader
from airtest.utils.retry import retries
from airtest.utils.snippet import get_std_encoding, reg_cleanup, split_cmd
LOGGING = get_logger(__name__)
class ADB(object):
"""adb client object class"""
_instances = []
status_device = "device"
status_offline = "offline"
SHELL_ENCODING = "utf-8"
def __init__(self, serialno=None, adb_path=None, server_addr=None):
self.serialno = serialno
self.adb_path = adb_path or self.builtin_adb_path()
self._set_cmd_options(server_addr)
self.connect()
self._sdk_version = None
import os
import re
import json
import struct
import threading
import six
import socket
from functools import wraps
from airtest.core.android.constant import STFLIB, ORI_METHOD
from airtest.utils.logger import get_logger
from airtest.utils.nbsp import NonBlockingStreamReader
from airtest.utils.safesocket import SafeSocket
from airtest.utils.snippet import reg_cleanup, on_method_ready, ready_method
LOGGING = get_logger(__name__)
def retry_when_socket_error(func):
@wraps(func)
def wrapper(inst, *args, **kwargs):
try:
return func(inst, *args, **kwargs)
except socket.error:
inst.frame_gen = None
return func(inst, *args, **kwargs)
return wrapper
class Minicap(object):
"""super fast android screenshot method from stf minicap.
# -*- coding: utf-8 -*-
import threading
import traceback
import time
from airtest.core.error import AirtestError
from airtest.utils.snippet import reg_cleanup, on_method_ready
from airtest.utils.logger import get_logger
from wda import LANDSCAPE, PORTRAIT, LANDSCAPE_RIGHT, PORTRAIT_UPSIDEDOWN
from wda import WDAError
LOGGING = get_logger(__name__)
class RotationWatcher(object):
"""
RotationWatcher class
"""
def __init__(self, iosHandle):
self.iosHandle = iosHandle
self.session = iosHandle.session
self.ow_callback = []
self.roundProcess = None
self._stopEvent = threading.Event()
self.last_result = None
reg_cleanup(self.teardown)
# coding=utf-8
import subprocess
import os
import re
import struct
import logging
from airtest.utils.logger import get_logger
from airtest.utils.nbsp import NonBlockingStreamReader
from airtest.utils.safesocket import SafeSocket
LOGGING = get_logger(__name__)
class MinicapIOS(object):
"""https://github.com/openstf/ios-minicap"""
CAPTIMEOUT = None
def __init__(self, udid=None, port=12345):
super(MinicapIOS, self).__init__()
self.udid = udid or list_devices()[0]
print(repr(self.udid))
self.port = port
self.resolution = "320x568"
self.executable = os.path.join(os.path.dirname(__file__), "ios_minicap")
self.server_proc = None
# _*_ coding:UTF-8 _*_
import time
from threading import Thread, Event
from six.moves import queue
from .logger import get_logger
LOGGING = get_logger(__name__)
class NonBlockingStreamReader:
def __init__(self, stream, raise_EOF=False, print_output=True, print_new_line=True, name=None):
'''
stream: the stream to read from.
Usually a process' stdout or stderr.
raise_EOF: if True, raise an UnexpectedEndOfStream
when stream is EOF before kill
print_output: if True, print when readline
'''
self._s = stream
self._q = queue.Queue()
self._lastline = None
self.name = name or id(self)
# -*- coding: utf-8 -*-
import threading
import traceback
from airtest.core.error import AirtestError
from airtest.utils.snippet import reg_cleanup, is_exiting, on_method_ready
from airtest.utils.logger import get_logger
from airtest.core.android.constant import ROTATIONWATCHER_APK, ROTATIONWATCHER_PACKAGE
LOGGING = get_logger(__name__)
class RotationWatcher(object):
"""
RotationWatcher class
"""
def __init__(self, adb):
self.adb = adb
self.ow_proc = None
self.ow_callback = []
self._t = None
self.current_orientation = None
reg_cleanup(self.teardown)
@on_method_ready('start')