Skip to content

Commit

Permalink
move SUBPROCESS_FLAG into compat.py
Browse files Browse the repository at this point in the history
(cherry picked from commit da224ef)
  • Loading branch information
yimelia committed Jan 17, 2020
1 parent 7efc380 commit fa3cc11
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 34 deletions.
6 changes: 3 additions & 3 deletions airtest/core/android/adb.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
from six.moves import reduce

from airtest.core.android.constant import (DEFAULT_ADB_PATH, IP_PATTERN,
SDK_VERISON_ANDROID7, SUBPROCESS_FLAG)
SDK_VERISON_ANDROID7)
from airtest.core.error import (AdbError, AdbShellError, AirtestError,
DeviceConnectionError, AdbTimeoutExpired)
from airtest.utils.compat import decode_path, raisefrom, proc_communicate_timeout
DeviceConnectionError)
from airtest.utils.compat import decode_path, raisefrom, proc_communicate_timeout, SUBPROCESS_FLAG
from airtest.utils.logger import get_logger
from airtest.utils.nbsp import NonBlockingStreamReader
from airtest.utils.retry import retries
Expand Down
13 changes: 0 additions & 13 deletions airtest/core/android/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,6 @@
IP_PATTERN = re.compile(r'(\d+\.){3}\d+')


if sys.platform.startswith("win"):
# Don't display the Windows GPF dialog if the invoked program dies.
try:
SUBPROCESS_FLAG = subprocess.CREATE_NO_WINDOW # in Python 3.7+
except AttributeError:
import ctypes
SEM_NOGPFAULTERRORBOX = 0x0002 # From MSDN
ctypes.windll.kernel32.SetErrorMode(SEM_NOGPFAULTERRORBOX) # win32con.CREATE_NO_WINDOW?
SUBPROCESS_FLAG = 0x8000000
else:
SUBPROCESS_FLAG = 0


class CAP_METHOD(object):
MINICAP = "MINICAP"
MINICAP_STREAM = "MINICAP_STREAM"
Expand Down
16 changes: 0 additions & 16 deletions airtest/core/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,6 @@ class AdbShellError(AdbError):
pass


class AdbTimeoutExpired(Exception):
"""
This exception is raised when the timeout expires while waiting for ADB command.
"""
def __init__(self, stdout, stderr, exp=None):
self.stdout = stdout
self.stderr = stderr
self.exp = exp

def __str__(self):
if self.exp:
return self.exp.__str__() + "\n stdout[%s] stderr[%s]" % (self.stdout, self.stderr)
else:
return "stdout[%s] stderr[%s]" % (self.stdout, self.stderr)


class DeviceConnectionError(BaseError):
"""
device connection error
Expand Down
4 changes: 3 additions & 1 deletion airtest/core/ios/instruct_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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
from airtest.utils.compat import SUBPROCESS_FLAG

LOGGING = get_logger(__name__)

Expand Down Expand Up @@ -54,7 +55,8 @@ def do_proxy(self, local_port, remote_port):
cmds,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
stderr=subprocess.PIPE,
creationflags=SUBPROCESS_FLAG
)
# something like port binding fail
time.sleep(0.5)
Expand Down
4 changes: 3 additions & 1 deletion airtest/core/ios/minicap.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from airtest.utils.logger import get_logger
from airtest.utils.nbsp import NonBlockingStreamReader
from airtest.utils.safesocket import SafeSocket
from airtest.utils.compat import SUBPROCESS_FLAG

LOGGING = get_logger(__name__)

Expand All @@ -27,7 +28,8 @@ def __init__(self, udid=None, port=12345):

def setup(self):
cmd = [self.executable, "--udid", self.udid, "--port", str(self.port), "--resolution", self.resolution]
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE)
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
stdin=subprocess.PIPE, creationflags=SUBPROCESS_FLAG)
nbsp = NonBlockingStreamReader(proc.stdout, print_output=True, name="minicap_sever")
while True:
line = nbsp.readline(timeout=10.0)
Expand Down
13 changes: 13 additions & 0 deletions airtest/utils/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ def decode_path(path):
return path.decode(sys.getfilesystemencoding()) if path else path


if sys.platform.startswith("win"):
# Don't display the Windows GPF dialog if the invoked program dies.
try:
SUBPROCESS_FLAG = subprocess.CREATE_NO_WINDOW # in Python 3.7+
except AttributeError:
import ctypes
SEM_NOGPFAULTERRORBOX = 0x0002 # From MSDN
ctypes.windll.kernel32.SetErrorMode(SEM_NOGPFAULTERRORBOX) # win32con.CREATE_NO_WINDOW?
SUBPROCESS_FLAG = 0x8000000
else:
SUBPROCESS_FLAG = 0


def script_dir_name(script_path):
"""get script dir for old & new cli api compatibility"""
script_path = decode_path(script_path)
Expand Down

0 comments on commit fa3cc11

Please sign in to comment.