Bug 543825 remove __import__ from automation.py r=ted

This commit is contained in:
Joel Maher 2010-03-13 11:20:27 -08:00
Родитель 19adc71579
Коммит 5157e45805
1 изменённых файлов: 22 добавлений и 20 удалений

Просмотреть файл

@ -74,6 +74,13 @@ _IS_CYGWIN = False
#expand _IS_DEBUG_BUILD = __IS_DEBUG_BUILD__
#expand _CRASHREPORTER = __CRASHREPORTER__ == 1
if _IS_WIN32:
import ctypes, ctypes.wintypes, time, msvcrt
else:
import errno
#################
# PROFILE SETUP #
#################
@ -466,7 +473,7 @@ user_pref("camino.use_system_proxy_settings", false); // Camino-only, harmless t
if env == None:
env = dict(os.environ)
ldLibraryPath = os.path.abspath(os.path.join(self.SCRIPT_DIR, xrePath))
ldLibraryPath = os.path.abspath(os.path.join(SCRIPT_DIR, xrePath))
if self.UNIXISH or self.IS_MAC:
envVar = "LD_LIBRARY_PATH"
if self.IS_MAC:
@ -490,10 +497,6 @@ user_pref("camino.use_system_proxy_settings", false); // Camino-only, harmless t
return env
if IS_WIN32:
ctypes = __import__('ctypes')
wintypes = __import__('ctypes.wintypes')
time = __import__('time')
msvcrt = __import__('msvcrt')
PeekNamedPipe = ctypes.windll.kernel32.PeekNamedPipe
GetLastError = ctypes.windll.kernel32.GetLastError
@ -507,11 +510,11 @@ user_pref("camino.use_system_proxy_settings", false); // Camino-only, harmless t
if timeout is None:
# shortcut to allow callers to pass in "None" for no timeout.
return (f.readline(), False)
x = self.msvcrt.get_osfhandle(f.fileno())
l = self.ctypes.c_long()
done = self.time.time() + timeout
while self.time.time() < done:
if self.PeekNamedPipe(x, None, 0, None, self.ctypes.byref(l), None) == 0:
x = msvcrt.get_osfhandle(f.fileno())
l = ctypes.c_long()
done = time.time() + timeout
while time.time() < done:
if self.PeekNamedPipe(x, None, 0, None, ctypes.byref(l), None) == 0:
err = self.GetLastError()
if err == 38 or err == 109: # ERROR_HANDLE_EOF || ERROR_BROKEN_PIPE
return ('', False)
@ -521,18 +524,18 @@ user_pref("camino.use_system_proxy_settings", false); // Camino-only, harmless t
# we're assuming that the output is line-buffered,
# which is not unreasonable
return (f.readline(), False)
self.time.sleep(0.01)
time.sleep(0.01)
return ('', True)
def isPidAlive(self, pid):
STILL_ACTIVE = 259
PROCESS_QUERY_LIMITED_INFORMATION = 0x1000
pHandle = self.ctypes.windll.kernel32.OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, 0, pid)
pHandle = ctypes.windll.kernel32.OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, 0, pid)
if not pHandle:
return False
pExitCode = ctypes.wintypes.DWORD()
self.ctypes.windll.kernel32.GetExitCodeProcess(pHandle, self.ctypes.byref(pExitCode))
self.ctypes.windll.kernel32.CloseHandle(pHandle)
ctypes.windll.kernel32.GetExitCodeProcess(pHandle, self.ctypes.byref(pExitCode))
ctypes.windll.kernel32.CloseHandle(pHandle)
if (pExitCode.value == STILL_ACTIVE):
return True
else:
@ -540,14 +543,13 @@ user_pref("camino.use_system_proxy_settings", false); // Camino-only, harmless t
def killPid(self, pid):
PROCESS_TERMINATE = 0x0001
pHandle = self.ctypes.windll.kernel32.OpenProcess(PROCESS_TERMINATE, 0, pid)
pHandle = ctypes.windll.kernel32.OpenProcess(PROCESS_TERMINATE, 0, pid)
if not pHandle:
return
success = self.ctypes.windll.kernel32.TerminateProcess(pHandle, 1)
self.ctypes.windll.kernel32.CloseHandle(pHandle)
success = ctypes.windll.kernel32.TerminateProcess(pHandle, 1)
ctypes.windll.kernel32.CloseHandle(pHandle)
else:
errno = __import__('errno')
def readWithTimeout(self, f, timeout):
"""Try to read a line of output from the file object |f|. If no output
@ -575,7 +577,7 @@ user_pref("camino.use_system_proxy_settings", false); // Camino-only, harmless t
except OSError, err:
# Catch the errors we might expect from os.kill/os.waitpid,
# and re-raise any others
if err.errno == self.errno.ESRCH or err.errno == self.errno.ECHILD:
if err.errno == errno.ESRCH or err.errno == errno.ECHILD:
return False
raise
@ -761,7 +763,7 @@ user_pref("camino.use_system_proxy_settings", false); // Camino-only, harmless t
# Do a final check for zombie child processes.
self.checkForZombies(processLog)
self.automationutils.checkForCrashes(os.path.join(profileDir, "minidumps"), symbolsPath)
automationutils.checkForCrashes(os.path.join(profileDir, "minidumps"), symbolsPath)
if os.path.exists(processLog):
os.unlink(processLog)