代码拉取完成,页面将自动刷新
同步操作将从 src-openEuler/pacemaker 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。