-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to distro package for os recognition.
- Loading branch information
1 parent
fc5e710
commit 9e8823e
Showing
6 changed files
with
67 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
""" | ||
This module provides a function (isDistro) that helps us identify the os | ||
of the system and configure the system accordingly. | ||
""" | ||
|
||
import distro | ||
from typing import Union | ||
|
||
|
||
def isDistro(oses: Union[str, list], version: str = None) -> bool: | ||
cur_id = distro.id().lower() | ||
cur_name = distro.name().lower() | ||
|
||
if isinstance(oses, str): | ||
results = (oses in cur_id) or (oses in cur_name) | ||
else: | ||
results = False | ||
for item in oses: | ||
if not isinstance(item, str): | ||
continue | ||
item = item.lower() | ||
results = results or (item in cur_id) or (item in cur_name) | ||
|
||
if results is False: | ||
return False | ||
|
||
if version: | ||
cur_major = int(distro.major_version()) | ||
cur_minor = int(distro.minor_version()) if distro.minor_version() else 0 | ||
|
||
if version[0] in ('<', '=', '>'): | ||
if version[1] == '=': | ||
op = version[:2] | ||
version = version[2:] | ||
else: | ||
op = version[0] if version[0] != '=' else '==' | ||
version = version[1:] | ||
else: | ||
op = '==' | ||
|
||
parts = version.split('.') | ||
major = int(parts[0]) | ||
minor = int(parts[1]) if len(parts) > 1 else 0 | ||
|
||
if major == cur_major: | ||
return eval("{0} {1} {2}".format(cur_minor, op, minor)) | ||
else: | ||
return eval("{0} {1} {2}".format(cur_major, op, major)) | ||
|
||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ pytest>=7 | |
schema>=0.7 | ||
python_freeipa>=1.0 | ||
pexpect>=4 | ||
distro>=1.5.0 |