1 Star 0 Fork 21

twtlpl/pacemaker_1

forked from src-openEuler/pacemaker 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backport-Feature-python-Add-a-python-wrapper-for-crm_exit_str.patch 3.29 KB
一键复制 编辑 原始数据 按行查看 历史
From 8dbd0816c84b075b02e21f733376343ec60290a6 Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Mon, 3 Jun 2024 09:28:06 -0400
Subject: [PATCH 022/150] Feature: python: Add a python wrapper for
crm_exit_str.
We also need a new function to find libcrmcommon.so (and potentially,
other libraries in the future) in case we are running from the source
tree instead of on an installed system. This allows anything that
imports pacemaker.exitstatus to still function.
---
python/pacemaker/Makefile.am | 3 ++-
python/pacemaker/_library.py | 38 ++++++++++++++++++++++++++++++++++
python/pacemaker/exitstatus.py | 6 ++++++
3 files changed, 46 insertions(+), 1 deletion(-)
create mode 100644 python/pacemaker/_library.py
diff --git a/python/pacemaker/Makefile.am b/python/pacemaker/Makefile.am
index df9cc46eef..99a137ad78 100644
--- a/python/pacemaker/Makefile.am
+++ b/python/pacemaker/Makefile.am
@@ -1,5 +1,5 @@
#
-# Copyright 2023 the Pacemaker project contributors
+# Copyright 2023-2024 the Pacemaker project contributors
#
# The version control history for this file may have further details.
#
@@ -10,6 +10,7 @@
MAINTAINERCLEANFILES = Makefile.in
pkgpython_PYTHON = __init__.py \
+ _library.py \
exitstatus.py
nodist_pkgpython_PYTHON = buildoptions.py
diff --git a/python/pacemaker/_library.py b/python/pacemaker/_library.py
new file mode 100644
index 0000000000..cd6bc4ef44
--- /dev/null
+++ b/python/pacemaker/_library.py
@@ -0,0 +1,38 @@
+"""A module providing private library management code."""
+
+__all__ = ["_libcrmcommon"]
+__copyright__ = "Copyright 2024 the Pacemaker project contributors"
+__license__ = "GNU Lesser General Public License version 2.1 or later (LGPLv2.1+)"
+
+import ctypes
+from ctypes.util import find_library
+from glob import glob
+import os
+
+from pacemaker.buildoptions import BuildOptions
+
+
+def load_library(basename):
+ """Find and load the library with the given base name."""
+ path = find_library(basename)
+
+ # If the library was not found anywhere in the default locations, also search
+ # for it in the build directory
+ if path is None:
+ # pylint: disable=protected-access
+ for d in glob("%s/lib/*/.libs" % BuildOptions._BUILD_DIR):
+ path = "%s/lib%s.so" % (d, basename)
+
+ if os.path.exists(path):
+ break
+
+ path = None
+
+ if path is None:
+ raise FileNotFoundError(basename)
+
+ return ctypes.cdll.LoadLibrary(path)
+
+
+_libcrmcommon = load_library("crmcommon")
+_libcrmcommon.crm_exit_str.restype = ctypes.c_char_p
diff --git a/python/pacemaker/exitstatus.py b/python/pacemaker/exitstatus.py
index 7294d518e7..03f7d2c8e2 100644
--- a/python/pacemaker/exitstatus.py
+++ b/python/pacemaker/exitstatus.py
@@ -6,6 +6,8 @@ __license__ = "GNU Lesser General Public License version 2.1 or later (LGPLv2.1+
from enum import IntEnum, unique
+from pacemaker._library import _libcrmcommon
+
# These values must be kept in sync with include/crm/common/results.h
@unique
@@ -60,3 +62,7 @@ class ExitStatus(IntEnum):
DEGRADED_PROMOTED = 191
NONE = 193
MAX = 255
+
+ def __str__(self):
+ """Given an ExitStatus, return the matching error string."""
+ return _libcrmcommon.crm_exit_str(self.value).decode()
--
2.33.1.windows.1
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/twtlpl/pacemaker_1.git
git@gitee.com:twtlpl/pacemaker_1.git
twtlpl
pacemaker_1
pacemaker_1
master

搜索帮助