Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "openeuler" support to os_detect.py #260

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/rospkg/os_detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,25 @@ def get_codename(self):
return ""
raise OsNotDetected('called in incorrect OS')

class OpenEuler(OsDetector):
"""
Detect OpenEuler OS.
"""
def __init__(self, release_file="/etc/openEuler-release"):
self._release_info = read_os_release()
self._release_file = release_file
def is_os(self):
return os.path.exists(self._release_file)
def get_version(self):
if (self.is_os() and "VERSION_ID" in self._release_info):
return self._release_info["VERSION_ID"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind updating this to prevent the KeyError from raising if the release file doesn't contain VERSION_ID?

I don't have any strong feelings about how to handle the lack of VERSION_ID, but a KeyError isn't very actionable. I think either returning an empty string or raising OsNotDetected would probably be appropriate.

raise OsNotDetected("called in incorrect OS")
def get_codename(self):
if self.is_os():
return ""
raise OsNotDetected('called in incorrect OS')



class OpenSuse(OsDetector):
"""
Expand Down Expand Up @@ -655,6 +674,7 @@ def get_codename(self):
OS_MANJARO = 'manjaro'
OS_CENTOS = 'centos'
OS_EULEROS = 'euleros'
OS_OPENEULER = 'openeuler'
OS_CYGWIN = 'cygwin'
OS_DEBIAN = 'debian'
OS_ELEMENTARY = 'elementary'
Expand Down Expand Up @@ -695,6 +715,7 @@ def get_codename(self):
OsDetect.register_default(OS_MANJARO, Manjaro())
OsDetect.register_default(OS_CENTOS, FdoDetect("centos"))
OsDetect.register_default(OS_EULEROS, FdoDetect("euleros"))
OsDetect.register_default(OS_OPENEULER, OpenEuler())
OsDetect.register_default(OS_CYGWIN, Cygwin())
OsDetect.register_default(OS_DEBIAN, Debian())
OsDetect.register_default(OS_ELEMENTARY, LsbDetect("elementary"))
Expand Down