fix the problem of using hplip in python3.9

(cherry picked from commit 1c31c1b3a664313e9f7d3259836dd73054b72444)
This commit is contained in:
lanruo 2023-08-21 16:10:39 +08:00 committed by openeuler-sync-bot
parent a0a4b8fe77
commit 7b05961c74
2 changed files with 94 additions and 1 deletions

View File

@ -0,0 +1,88 @@
From 3d0c21042808eda903270365aaf45446f81c30c8 Mon Sep 17 00:00:00 2001
From: yangchenguang <yangchenguang@kylinsec.com.cn>
Date: Thu, 13 Apr 2023 10:51:46 +0800
Subject: [PATCH] fix(*): the problem of using hplip in python3.9
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 修复在线安装hp打印机驱动时报错
Signed-off-by: yangchenguang <yangchenguang@kylinsec.com.cn>
---
base/password.py | 15 +++++++++++++--
installer/core_install.py | 25 ++++++++++++++++++++++---
2 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/base/password.py b/base/password.py
index c634f88..61c5b7e 100644
--- a/base/password.py
+++ b/base/password.py
@@ -56,6 +56,7 @@ AUTH_TYPES = {'mepis': 'su',
'boss': 'su',
'lfs': 'su',
'manjarolinux': 'sudo',
+ 'kylinsec': 'su',
}
@@ -76,8 +77,18 @@ def showPasswordPrompt(prompt):
def get_distro_name():
os_name = None
try:
- import platform
- os_name = platform.dist()[0]
+ _release_filename = re.compile(r'(\w+)[-_](release|version)', re.ASCII)
+ supported_dists = (
+ 'fedora', 'redhat', 'kylinsec', 'KylinSec'
+ )
+ for file in os.listdir("/etc"):
+ m = _release_filename.match(file)
+ if m is not None:
+ _distname, dummy = m.groups()
+ if _distname in supported_dists:
+ os_name = _distname
+ break
+
except ImportError:
os_name = None
diff --git a/installer/core_install.py b/installer/core_install.py
index 2b6046d..6b9a1ec 100644
--- a/installer/core_install.py
+++ b/installer/core_install.py
@@ -611,9 +611,28 @@ class CoreInstall(object):
# Getting distro information using platform module
try:
- import platform
- name = platform.dist()[0].lower()
- ver = platform.dist()[1]
+ _release_filename = re.compile(r'(\w+)[-_](release|version)', re.ASCII)
+ _lsb_release_version = re.compile(r'(.+)'
+ r' release '
+ r'([\d.]+)'
+ r'[^(]*(?:\((.+)\))?', re.ASCII)
+ supported_dists = (
+ 'fedora', 'redhat', 'kylinsec', 'KylinSec', 'system'
+ )
+ for file in os.listdir("/etc"):
+ m = _release_filename.match(file)
+ if m is not None:
+ _distname, dummy = m.groups()
+ if _distname in supported_dists:
+ name = _distname.lower()
+ break
+
+ with open(os.path.join("/etc/", file), r, encoding='utf-8', errors='surrogateescape') as f:
+ firstline = r.readline()
+ n = _lsb_release_version.match(firstline)
+ if n is not None:
+ ver = tuple(n.group())[1]
+
if not name:
found = False
log.debug("Not able to detect distro")
--
2.33.0

View File

@ -1,7 +1,7 @@
Name: hplip
Summary: HP Linux Imaging and Printing Project
Version: 3.18.6
Release: 11
Release: 12
License: GPLv2+ and MIT and BSD and IJG and Public Domain and GPLv2+ with exceptions and ISC
Url: https://developers.hp.com/hp-linux-imaging-and-printing
Source0: https://sourceforge.net/projects/%{name}/files/%{name}/%{version}/%{name}-%{version}.tar.gz/download?use_mirror=ufpr#/%{name}-%{version}.tar.gz
@ -37,6 +37,7 @@ Patch31: hplip-use-binary-str.patch
Patch32: hplip-colorlaserjet-mfp-m278-m281.patch
Patch33: hplip-error-print.patch
Patch34: hplip-hpfax-importerror-print.patch
Patch35: fix-the-problem-of-using-hplip-in-python3.9.patch
Requires: python3-pillow python3-gobject cups python3-dbus systemd %{_bindir}/gpg
Requires: python3-qt5 wget python3-gobject python3-reportlab sane-backends python3
@ -128,6 +129,7 @@ rm prnt/hpcups/ErnieFilter.{cpp,h} prnt/hpijs/ernieplatform.h
%patch32 -p1 -b .colorlaserjet-mfp-m278-m281
%patch33 -p1 -b .error-print-fix
%patch34 -p1 -b .hpfax-import-error-print
%patch35 -p1
sed -i.duplex-constraints \
-e 's,\(UIConstraints.* \*Duplex\),//\1,' \
@ -274,6 +276,9 @@ install -d ${RPM_BUILD_ROOT}%{_datadir}/hplip/prnt/plugins
%exclude %{python3_sitearch}/*.la
%changelog
* Thu Apr 13 2023 yangchenguang <yangchenguang@kylinsec.com.cn> - 3.18.6-12
- fix the problem of using hplip in python3.9
* Tue Sep 15 2020 Ge Wang <wangge20@huawei.com> - 3.18.6-11
- Modify Source0 Url