fix: address CUPS runtime review findings and add regression tests
This commit is contained in:
@@ -216,6 +216,47 @@ def install_deb(filepath):
|
||||
|
||||
return results
|
||||
|
||||
def install_deb_bundle(filepaths):
|
||||
"""先检查包元数据,仅安装本机架构和架构无关的 DEB。"""
|
||||
host = run_command(['dpkg', '--print-architecture'])
|
||||
architecture = host['stdout'].strip()
|
||||
if not host['success'] or not architecture:
|
||||
return [('检测系统架构', {
|
||||
**host, 'success': False, 'returncode': host['returncode'] or 1,
|
||||
'stderr': host['stderr'] or '无法检测 dpkg 系统架构,未安装任何驱动包'
|
||||
})]
|
||||
|
||||
results = []
|
||||
compatible = []
|
||||
# 完成全部检查后再安装,避免读取损坏的包时已经修改了系统。
|
||||
for filepath in filepaths:
|
||||
metadata = run_command(['dpkg-deb', '--field', str(filepath), 'Architecture'])
|
||||
package_architecture = metadata['stdout'].strip()
|
||||
if not metadata['success'] or not package_architecture:
|
||||
results.append((f'检查 DEB 架构: {Path(filepath).name}', {
|
||||
**metadata, 'success': False, 'returncode': metadata['returncode'] or 1,
|
||||
'stderr': metadata['stderr'] or '无法读取包的 Architecture 字段,未安装任何驱动包'
|
||||
}))
|
||||
return results
|
||||
if package_architecture in (architecture, 'all'):
|
||||
compatible.append(str(filepath))
|
||||
else:
|
||||
results.append(('跳过其他架构 DEB', {
|
||||
'success': True, 'returncode': 0, 'stderr': '',
|
||||
'stdout': f'{Path(filepath).name}: {package_architecture},当前系统为 {architecture}'
|
||||
}))
|
||||
|
||||
if not compatible:
|
||||
results.append(('选择兼容 DEB', {
|
||||
'success': False, 'returncode': 1, 'stdout': '',
|
||||
'stderr': f'未找到适用于 {architecture} 或 all 架构的驱动包'
|
||||
}))
|
||||
return results
|
||||
|
||||
for filepath in compatible:
|
||||
results.extend(install_deb(filepath))
|
||||
return results
|
||||
|
||||
def install_ppd(filepath):
|
||||
"""安装 .ppd 文件"""
|
||||
results = []
|
||||
@@ -266,9 +307,7 @@ def install_extracted_dir(extract_dir):
|
||||
|
||||
deb_files = find_files_by_suffix(extract_dir, ('.deb',))
|
||||
if deb_files:
|
||||
for deb_file in deb_files:
|
||||
results.extend(install_deb(str(deb_file)))
|
||||
return results
|
||||
return install_deb_bundle(deb_files)
|
||||
|
||||
rpm_files = find_files_by_suffix(extract_dir, ('.rpm',))
|
||||
if rpm_files:
|
||||
@@ -424,7 +463,7 @@ def install_script(filepath):
|
||||
def install_driver(filepath, file_type):
|
||||
"""根据文件类型安装驱动"""
|
||||
if file_type == 'deb':
|
||||
return install_deb(filepath)
|
||||
return install_deb_bundle([filepath])
|
||||
elif file_type == 'ppd':
|
||||
return install_ppd(filepath)
|
||||
elif file_type in ('tar.gz', 'tar', 'tgz'):
|
||||
|
||||
Reference in New Issue
Block a user