From 56b1554c1e215b376c606ea8252dbea445ed4509 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 15 Oct 2020 10:23:27 +0530 Subject: [PATCH] Remove the last use of win32process --- src/calibre/debug.py | 10 ++++------ src/calibre/utils/windows/winutil.cpp | 8 ++++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/calibre/debug.py b/src/calibre/debug.py index 58825d09e0..412b42facf 100644 --- a/src/calibre/debug.py +++ b/src/calibre/debug.py @@ -180,19 +180,17 @@ def print_basic_debug_info(out=None): out = sys.stdout out = functools.partial(prints, file=out) import platform + from contextlib import suppress from calibre.constants import (__appname__, get_version, isportable, ismacos, - isfrozen, is64bit) + isfrozen, is64bit, plugins) from calibre.utils.localization import set_translators out(__appname__, get_version(), 'Portable' if isportable else '', 'embedded-python:', isfrozen, 'is64bit:', is64bit) out(platform.platform(), platform.system(), platform.architecture()) if iswindows and not is64bit: - try: - import win32process - if win32process.IsWow64Process(): + with suppress(Exception): + if plugins['winutil'][0].is_wow64_process(): out('32bit process running on 64bit windows') - except: - pass out(platform.system_alias(platform.system(), platform.release(), platform.version())) out('Python', platform.python_version()) diff --git a/src/calibre/utils/windows/winutil.cpp b/src/calibre/utils/windows/winutil.cpp index a2be0c01ea..e1e8d6f658 100644 --- a/src/calibre/utils/windows/winutil.cpp +++ b/src/calibre/utils/windows/winutil.cpp @@ -835,6 +835,13 @@ run_cmdline(PyObject *self, PyObject *args) { Py_RETURN_NONE; } +static PyObject* +is_wow64_process(PyObject *self, PyObject *args) { + BOOL ans; + if (!IsWow64Process(GetCurrentProcess(), &ans)) return PyErr_SetFromWindowsErr(0); + return Py_BuildValue("O", ans ? Py_True : Py_False); +} + // Icon loading {{{ #pragma pack( push ) #pragma pack( 2 ) @@ -969,6 +976,7 @@ static const char winutil_doc[] = "Defines utility methods to interface with win #define M(name, args) { #name, name, args, ""} static PyMethodDef winutil_methods[] = { M(run_cmdline, METH_VARARGS), + M(is_wow64_process, METH_NOARGS), M(get_dll_directory, METH_NOARGS), M(create_mutex, METH_VARARGS), M(get_async_key_state, METH_VARARGS),