Skip to content

Commit

Permalink
Merge pull request #9 from bitranox/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
bitranox authored Nov 9, 2022
2 parents fa1344d + a0889f1 commit 05ba385
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 18 additions & 3 deletions lib_platform/lib_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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]
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib_platform/lib_platform_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/local_testscripts/testing_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 05ba385

Please sign in to comment.