1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-19 00:17:51 +02:00

refactor - create is_compatible function

This commit is contained in:
Kelly Brazil
2022-05-23 13:52:08 -07:00
parent c21c334b73
commit 9f4ba80000

View File

@ -97,6 +97,20 @@ def error_message(message_lines: List[str]) -> None:
_safe_print(message, file=sys.stderr) _safe_print(message, file=sys.stderr)
def is_compatible(compatible: List) -> bool:
"""
Returns True if the parser is compatible with the running OS platform.
"""
platform_found = False
for platform in compatible:
if sys.platform.startswith(platform):
platform_found = True
break
return platform_found
def compatibility(mod_name: str, compatible: List, quiet: bool = False) -> None: def compatibility(mod_name: str, compatible: List, quiet: bool = False) -> None:
""" """
Checks for the parser's compatibility with the running OS Checks for the parser's compatibility with the running OS
@ -116,21 +130,13 @@ def compatibility(mod_name: str, compatible: List, quiet: bool = False) -> None:
None - just prints output to STDERR None - just prints output to STDERR
""" """
if not quiet: if not quiet and not is_compatible(compatible):
platform_found = False mod = mod_name.split('.')[-1]
compat_list = ', '.join(compatible)
for platform in compatible: warning_message([
if sys.platform.startswith(platform): f'{mod} parser is not compatible with your OS ({sys.platform}).',
platform_found = True f'Compatible platforms: {compat_list}'
break ])
if not platform_found:
mod = mod_name.split('.')[-1]
compat_list = ', '.join(compatible)
warning_message([
f'{mod} parser is not compatible with your OS ({sys.platform}).',
f'Compatible platforms: {compat_list}'
])
def has_data(data: str) -> bool: def has_data(data: str) -> bool: