From: Tom Hromatka Date: Fri, 29 Apr 2022 16:52:25 +0000 (-0600) Subject: python: Make Cgroup.mount_points() more pythonic X-Git-Tag: v3.0~88 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5ed84ad3eb8f9af1a070c60defbce3fb3f16d247;p=thirdparty%2Flibcgroup.git python: Make Cgroup.mount_points() more pythonic Rename cgroup_list_mount_points() to mount_points() and convert it to an @staticmethod. Signed-off-by: Tom Hromatka Reviewed-by: Kamalesh Babulal --- diff --git a/src/python/libcgroup.pyx b/src/python/libcgroup.pyx index e3e27d26..f1d361d9 100644 --- a/src/python/libcgroup.pyx +++ b/src/python/libcgroup.pyx @@ -51,11 +51,15 @@ cdef class Cgroup: cdef public: object name, controllers, version - def __cinit__(self, name, version): + @staticmethod + def cgroup_init(): ret = cgroup.cgroup_init() if ret != 0: raise RuntimeError("Failed to initialize libcgroup: {}".format(ret)) + def __cinit__(self, name, version): + Cgroup.cgroup_init() + self._cgp = cgroup.cgroup_new_cgroup(c_str(name)) if self._cgp == NULL: raise RuntimeError("Failed to create cgroup {}".format(name)) @@ -277,18 +281,24 @@ cdef class Cgroup: if ret != 0: raise RuntimeError("Failed to create cgroup: {}".format(ret)) - def cgroup_list_mount_points(self, version): + @staticmethod + def mount_points(version): """List cgroup mount points of the specified version Arguments: version - It specifies the cgroup version + Return: + The cgroup mount points in a list + Description: Parse the /proc/mounts and list the cgroup mount points matching the version """ cdef char **a + Cgroup.cgroup_init() + mount_points = [] ret = cgroup.cgroup_list_mount_points(version, &a) if ret is not 0: