mirror of
https://github.com/clearml/wexpect-venv
synced 2025-04-30 02:41:02 +00:00
[CLN] make wexpect subdir
This commit is contained in:
parent
f1654bc8df
commit
578dd872dc
@ -4,6 +4,11 @@ from .legacy_wexpect import TIMEOUT
|
|||||||
from .legacy_wexpect import spawn
|
from .legacy_wexpect import spawn
|
||||||
from .legacy_wexpect import run
|
from .legacy_wexpect import run
|
||||||
from .legacy_wexpect import split_command_line
|
from .legacy_wexpect import split_command_line
|
||||||
|
from .legacy_wexpect import join_args
|
||||||
|
from .legacy_wexpect import ConsoleReader
|
||||||
from .legacy_wexpect import __version__
|
from .legacy_wexpect import __version__
|
||||||
|
from .legacy_wexpect import searcher_string
|
||||||
|
from .legacy_wexpect import searcher_re
|
||||||
|
|
||||||
__all__ = ['ExceptionPexpect', 'EOF', 'TIMEOUT', 'spawn', 'run', 'split_command_line', '__version__']
|
__all__ = ['ExceptionPexpect', 'EOF', 'TIMEOUT', 'spawn', 'run', 'split_command_line',
|
||||||
|
'__version__', 'ConsoleReader', 'join_args', 'searcher_string', 'searcher_re']
|
||||||
|
@ -122,11 +122,12 @@ __all__ = ['ExceptionPexpect', 'EOF', 'TIMEOUT', 'spawn', 'run', 'which',
|
|||||||
# Create logger: We write logs only to file. Printing out logs are dangerous, because of the deep
|
# Create logger: We write logs only to file. Printing out logs are dangerous, because of the deep
|
||||||
# console manipulation.
|
# console manipulation.
|
||||||
#
|
#
|
||||||
|
pid=os.getpid()
|
||||||
logger = logging.getLogger('wexpect')
|
logger = logging.getLogger('wexpect')
|
||||||
try:
|
try:
|
||||||
logger_level = os.environ['WEXPECT_LOGGER_LEVEL']
|
logger_level = os.environ['WEXPECT_LOGGER_LEVEL']
|
||||||
logger.setLevel(logger_level)
|
logger.setLevel(logger_level)
|
||||||
fh = logging.FileHandler('wexpect.log', 'w', 'utf-8')
|
fh = logging.FileHandler(f'wexpect_{pid}.log', 'w', 'utf-8')
|
||||||
formatter = logging.Formatter('%(asctime)s - %(filename)s::%(funcName)s - %(levelname)s - %(message)s')
|
formatter = logging.Formatter('%(asctime)s - %(filename)s::%(funcName)s - %(levelname)s - %(message)s')
|
||||||
fh.setFormatter(formatter)
|
fh.setFormatter(formatter)
|
||||||
logger.addHandler(fh)
|
logger.addHandler(fh)
|
||||||
@ -1121,16 +1122,22 @@ class Wtty:
|
|||||||
ts = time.time()
|
ts = time.time()
|
||||||
self.startChild(args, env)
|
self.startChild(args, env)
|
||||||
|
|
||||||
|
logger.info(f"Fetch child's process and pid...")
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
logger.info(f"0")
|
||||||
msg = win32gui.GetMessage(0, 0, 0)
|
msg = win32gui.GetMessage(0, 0, 0)
|
||||||
|
logger.info(f"0b")
|
||||||
childPid = msg[1][2]
|
childPid = msg[1][2]
|
||||||
# Sometimes win32gui.GetMessage returns a bogus PID, so keep calling it
|
# Sometimes win32gui.GetMessage returns a bogus PID, so keep calling it
|
||||||
# until we can successfully connect to the child or timeout is
|
# until we can successfully connect to the child or timeout is
|
||||||
# reached
|
# reached
|
||||||
if childPid:
|
if childPid:
|
||||||
try:
|
try:
|
||||||
|
logger.info(f"1")
|
||||||
self.__childProcess = win32api.OpenProcess(
|
self.__childProcess = win32api.OpenProcess(
|
||||||
win32con.PROCESS_TERMINATE | win32con.PROCESS_QUERY_INFORMATION, False, childPid)
|
win32con.PROCESS_TERMINATE | win32con.PROCESS_QUERY_INFORMATION, False, childPid)
|
||||||
|
logger.info(f"2")
|
||||||
self.__conProcess = win32api.OpenProcess(
|
self.__conProcess = win32api.OpenProcess(
|
||||||
win32con.PROCESS_TERMINATE | win32con.PROCESS_QUERY_INFORMATION, False, self.conpid)
|
win32con.PROCESS_TERMINATE | win32con.PROCESS_QUERY_INFORMATION, False, self.conpid)
|
||||||
except pywintypes.error as e:
|
except pywintypes.error as e:
|
||||||
@ -1141,6 +1148,8 @@ class Wtty:
|
|||||||
break
|
break
|
||||||
time.sleep(.05)
|
time.sleep(.05)
|
||||||
|
|
||||||
|
logger.info(f"Child's pid: {self.pid}")
|
||||||
|
|
||||||
if not self.__childProcess:
|
if not self.__childProcess:
|
||||||
raise ExceptionPexpect ('The process ' + args[0] + ' could not be started.')
|
raise ExceptionPexpect ('The process ' + args[0] + ' could not be started.')
|
||||||
|
|
||||||
@ -1170,6 +1179,7 @@ class Wtty:
|
|||||||
si.wShowWindow = win32con.SW_HIDE
|
si.wShowWindow = win32con.SW_HIDE
|
||||||
# Determine the directory of wexpect.py or, if we are running 'frozen'
|
# Determine the directory of wexpect.py or, if we are running 'frozen'
|
||||||
# (eg. py2exe deployment), of the packed executable
|
# (eg. py2exe deployment), of the packed executable
|
||||||
|
|
||||||
dirname = os.path.dirname(sys.executable
|
dirname = os.path.dirname(sys.executable
|
||||||
if getattr(sys, 'frozen', False) else
|
if getattr(sys, 'frozen', False) else
|
||||||
os.path.abspath(__file__))
|
os.path.abspath(__file__))
|
||||||
@ -1178,7 +1188,7 @@ class Wtty:
|
|||||||
else:
|
else:
|
||||||
logdir = dirname
|
logdir = dirname
|
||||||
logdir = os.path.basename(logdir)
|
logdir = os.path.basename(logdir)
|
||||||
spath = [dirname]
|
spath = [os.path.dirname(dirname)]
|
||||||
pyargs = ['-c']
|
pyargs = ['-c']
|
||||||
if getattr(sys, 'frozen', False):
|
if getattr(sys, 'frozen', False):
|
||||||
# If we are running 'frozen', add library.zip and lib\library.zip
|
# If we are running 'frozen', add library.zip and lib\library.zip
|
||||||
@ -1201,18 +1211,27 @@ class Wtty:
|
|||||||
# as the packed executable.
|
# as the packed executable.
|
||||||
# py2exe: The python executable can be included via setup script by
|
# py2exe: The python executable can be included via setup script by
|
||||||
# adding it to 'data_files'
|
# adding it to 'data_files'
|
||||||
commandLine = '"%s" %s "%s"' % (os.path.join(dirname, 'python.exe')
|
|
||||||
if getattr(sys, 'frozen', False) else
|
if getattr(sys, 'frozen', False):
|
||||||
os.path.join(os.path.dirname(sys.executable), 'python.exe'),
|
python_executable = os.path.join(dirname, 'python.exe')
|
||||||
|
else:
|
||||||
|
python_executable = os.path.join(os.path.dirname(sys.executable), 'python.exe')
|
||||||
|
|
||||||
|
commandLine = '"%s" %s "%s"' % (python_executable,
|
||||||
' '.join(pyargs),
|
' '.join(pyargs),
|
||||||
"import sys; sys.path = %r + sys.path;"
|
f"import sys; sys.path = {spath} + sys.path;"
|
||||||
"args = %r; import wexpect;"
|
f"args = {args}; import wexpect;"
|
||||||
"wexpect.ConsoleReader(wexpect.join_args(args), %i, %i, cp=%i, logdir=%r)" % (spath, args, pid, tid, cp, logdir))
|
f"wexpect.ConsoleReader(wexpect.join_args(args), {pid}, {tid}, cp={cp}, logdir={logdir})"
|
||||||
|
)
|
||||||
|
|
||||||
|
logger.info(f'CreateProcess: {commandLine}')
|
||||||
|
|
||||||
self.__oproc, _, self.conpid, self.__otid = win32process.CreateProcess(None, commandLine, None, None, False,
|
self.__oproc, x, self.conpid, self.__otid = win32process.CreateProcess(None, commandLine, None, None, False,
|
||||||
win32process.CREATE_NEW_CONSOLE, env, None, si)
|
win32process.CREATE_NEW_CONSOLE, env, None, si)
|
||||||
|
logger.info(f'self.__oproc: {self.__oproc}')
|
||||||
|
logger.info(f'x: {x}')
|
||||||
|
logger.info(f'self.conpid: {self.conpid}')
|
||||||
|
logger.info(f'self.__otid: {self.__otid}')
|
||||||
|
|
||||||
def switchTo(self, attatched=True):
|
def switchTo(self, attatched=True):
|
||||||
"""Releases from the current console and attatches
|
"""Releases from the current console and attatches
|
||||||
|
Loading…
Reference in New Issue
Block a user