msl.loadlib.utils module
Common functions used by the MSL-LoadLib package.
- msl.loadlib.utils.is_pythonnet_installed()[source]
Checks if Python for .NET is installed.
- Returns:
bool
– Whether Python for .NET is installed.
Note
For help getting Python for .NET installed on a non-Windows operating system look at the prerequisites, the Mono project and the Python for .NET documentation.
- msl.loadlib.utils.is_comtypes_installed()[source]
Checks if comtypes is installed.
New in version 0.5.
- msl.loadlib.utils.check_dot_net_config(py_exe_path)[source]
Check if the useLegacyV2RuntimeActivationPolicy property is enabled.
By default, Python for .NET works with .NET 4.0+ and therefore it cannot automatically load a shared library that was compiled with .NET <4.0. This method ensures that the useLegacyV2RuntimeActivationPolicy property exists in the <python-executable>.config file and that it is enabled.
This link provides an overview explaining why the useLegacyV2RuntimeActivationPolicy property is required.
The <python-executable>.config file should look like
<?xml version="1.0" encoding="utf-8" ?> <configuration> <startup useLegacyV2RuntimeActivationPolicy="true"> <supportedRuntime version="v4.0" /> <supportedRuntime version="v2.0.50727" /> </startup> </configuration>
- msl.loadlib.utils.is_port_in_use(port)[source]
Checks whether the TCP port is in use.
Changed in version 0.10.0: Only check TCP ports (instead of both TCP and UDP ports). Uses the
ss
command instead ofnetstat
on Linux.Changed in version 0.7.0: Renamed from port_in_use and added support for macOS.
- msl.loadlib.utils.wait_for_server(host, port, timeout)[source]
Wait for the 32-bit server to start.
- Parameters:
- Raises:
ConnectionTimeoutError – If a timeout occurred.
- msl.loadlib.utils.get_com_info(*additional_keys)[source]
Reads the registry for the COM libraries that are available.
This function is only supported on Windows.
New in version 0.5.
- Parameters:
*additional_keys (
str
, optional) – The Program ID (ProgID) key is returned automatically. You can include additional keys (e.g., Version, InprocHandler32, ToolboxBitmap32, VersionIndependentProgID, …) if you also want this additional information to be returned for each Class ID.- Returns:
dict
– The keys are the Class ID’s and each value is adict
of the information that was requested.
Examples
>>> from msl.loadlib import utils >>> info = utils.get_com_info() >>> info = utils.get_com_info('Version', 'ToolboxBitmap32')
- msl.loadlib.utils.generate_com_wrapper(lib, out_dir=None)[source]
Generate a Python wrapper module around a COM library.
For more information see Accessing type libraries.
New in version 0.9.
- Parameters:
lib –
Can be any of the following
a
LoadLibrary
objectthe ProgID or CLSID of a registered COM library as a
str
a COM pointer instance
an ITypeLib COM pointer instance
a path to a library file (.tlb, .exe or .dll) as a
str
a
tuple
orlist
specifying the GUID of a library, a major and a minor version number, plus optionally an LCID number, e.g., (guid, major, minor, lcid=0)an object with
_reg_libid_
and_reg_version_
attributes
out_dir (
str
, optional) – The output directory to save the wrapper to. If not specified then saves it to the../site-packages/comtypes/gen
directory.
- Returns:
The wrapper module that was generated.