From c4d791a17af3605251921ad9e9d6ebca03ba7ae0 Mon Sep 17 00:00:00 2001 From: bitranox Date: Fri, 24 Sep 2021 16:39:13 +0200 Subject: [PATCH 1/3] refractor --- lib_platform/lib_platform_cli.py | 2 +- tests/local_testscripts/testing_tools.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_platform/lib_platform_cli.py b/lib_platform/lib_platform_cli.py index 708afd6..60ee1b3 100644 --- a/lib_platform/lib_platform_cli.py +++ b/lib_platform/lib_platform_cli.py @@ -33,7 +33,7 @@ def info() -> None: @click.group(help=__init__conf__.title, context_settings=CLICK_CONTEXT_SETTINGS) @click.version_option(version=__init__conf__.version, prog_name=__init__conf__.shell_command, - message='{} version %(version)s'.format(__init__conf__.shell_command)) + message=f'{__init__conf__.shell_command} version {__init__conf__.version}') @click.option('--traceback/--no-traceback', is_flag=True, type=bool, default=None, help='return traceback information on cli') def cli_main(traceback: Optional[bool] = None) -> None: if traceback is not None: diff --git a/tests/local_testscripts/testing_tools.py b/tests/local_testscripts/testing_tools.py index d52171f..918e4a4 100644 --- a/tests/local_testscripts/testing_tools.py +++ b/tests/local_testscripts/testing_tools.py @@ -35,7 +35,7 @@ def append_subdirs_to_mypy_paths(root_directory: str) -> str: """ path_root_directory = pathlib.Path(root_directory).resolve() if not path_root_directory.is_dir(): - logger.warning('add mypy paths : the given root directory "{}" does not exist'.format(path_root_directory)) + logger.warning(f'add mypy paths : the given root directory "{path_root_directory}" does not exist') return '' l_subdirs = [str(path_root_directory / _dir) for _dir in next(os.walk(path_root_directory))[1]] str_current_mypy_paths = get_env_data(env_variable='MYPYPATH') From 125d1b160b693942a1384b2decc66b800cc6ac5c Mon Sep 17 00:00:00 2001 From: bitranox Date: Wed, 9 Nov 2022 12:36:57 +0100 Subject: [PATCH 2/3] fix get hostname, if something is tinkering with the loopback interface on Windows - for instance 'Solid Works 3DExperience' --- lib_platform/lib_platform.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/lib_platform/lib_platform.py b/lib_platform/lib_platform.py index cb88832..56b6c07 100644 --- a/lib_platform/lib_platform.py +++ b/lib_platform/lib_platform.py @@ -17,10 +17,9 @@ def get_hostname() -> str: >>> result = get_hostname() >>> assert len(result) > 1 - """ - if get_is_platform_windows_wine(): # for wine get hostname not via IP Adress - would give name of the host + if get_is_platform_windows_wine(): # for wine get hostname not via IP Adress - that would give name of the linux host # noinspection PyBroadException try: result_wine_reg = lib_registry.Registry().get_value(key=r'HKLM\System\CurrentControlSet\Control\ComputerName', value_name='ComputerName') @@ -34,7 +33,7 @@ def get_hostname() -> str: _hostname = result_wine_env elif get_is_platform_windows(): - _hostname = socket.getfqdn() + _hostname = _get_fqdn_by_hostname() else: # this one failed on the first call sometimes - use now getfqdn() supports both IPv4 and IPv6. - and sometimes give WRONG HOSTNAME # _hostname = socket.gethostbyaddr(socket.gethostname())[0] @@ -49,6 +48,22 @@ def get_hostname() -> str: return str(_hostname) +def _get_fqdn_by_hostname() -> str: + """ + Returns fqdn by hostname + if You use just socket.getfqdn(), it will return 'dslauncher.3ds.com' if Solid Works 3DExperience is installed. + this is because they tinker with the loopback address + therefore we get hostname --> ip adress --> fqdn + + >>> assert _get_fqdn_by_hostname() + + """ + _hostname_short = socket.gethostname() + _ip_address = socket.gethostbyname(_hostname_short) + _fqdn = socket.getfqdn(name=_ip_address) + return _fqdn + + def get_hostname_short() -> str: """ Returns hostname lowercase without domain part From a0889f15b9c3ebfc8bf77832f32c3865c823c25a Mon Sep 17 00:00:00 2001 From: bitranox Date: Wed, 9 Nov 2022 12:42:13 +0100 Subject: [PATCH 3/3] fix get hostname, if something is tinkering with the loopback interface on Windows - for instance 'Solid Works 3DExperience' --- CHANGES.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 1b1541d..bd1dd62 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,11 @@ Changelog - new MINOR version for added functionality in a backwards compatible manner - new PATCH version for backwards compatible bug fixes +v1.2.8 +-------- +2022-11-09: + - fix get hostname on Windows + v1.2.7 -------- 2020-10-09: service release