-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
142 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import os | ||
import xml.etree.ElementTree as ET | ||
|
||
def get_src_rpm_list_by_primary_xml(xml_file: str, repo_base: str): | ||
rpm_arr = [] | ||
# 检查元数据文件 | ||
if os.path.exists(xml_file): | ||
if not os.path.isfile(xml_file): | ||
print(f"[error] primary xml file is not file: {xml_file}") | ||
return None | ||
else: | ||
print(f"[error] primary xml file is not exist: {xml_file}") | ||
return None | ||
|
||
if not xml_file.endswith('-primary.xml') : | ||
print(f"[error] list file is not endswith -primary.xml: {xml_file}") | ||
return None | ||
|
||
# 解下xmL文件 | ||
tree = ET.parse(xml_file) | ||
root = tree.getroot() | ||
for package in root.findall('{http://linux.duke.edu/metadata/common}package'): | ||
# 处理xml文件中单个package | ||
name = package.find('{http://linux.duke.edu/metadata/common}name').text.strip() | ||
version = package.find('{http://linux.duke.edu/metadata/common}version').get('ver').strip() | ||
location_href = package.find('{http://linux.duke.edu/metadata/common}location').get('href').strip() | ||
|
||
repo_addr = repo_base + '/' + location_href | ||
record_tmp = repo_addr + ' ' + name + ' ' + version | ||
if record_tmp not in rpm_arr: | ||
rpm_arr.append(record_tmp) | ||
return rpm_arr | ||
|
||
|
||
def get_rpm_binary_List_by_primary_xml(xml_path: str, arch_type: str): | ||
rpm_arr = [] | ||
|
||
# 检查元数据文件 | ||
if os.path.exists(xml_path): | ||
if not os.path.isdir(xml_path): | ||
print(f"[error] xml dir path is not dir: {xml_path}") | ||
return None | ||
else: | ||
print(f"[error] xml dir path is not exist: {xml_path}") | ||
return None | ||
|
||
for file_name in os.listdir(xml_path): | ||
if not file_name.endswith('-primary.xml') : | ||
continue | ||
|
||
# 解下xmL文件 | ||
file_path = os.path.join(xml_path, file_name) | ||
tree = ET.parse(file_path) | ||
root = tree.getroot() | ||
for package in root.findall('{http://linux.duke.edu/metadata/common}package'): | ||
# 处理xml文件中单个package | ||
name = package.find('{http://linux.duke.edu/metadata/common}name').text.strip() | ||
version = package.find('{http://linux.duke.edu/metadata/common}version').get('ver').strip() | ||
arch = package.find('{http://linux.duke.edu/metadata/common}arch').text.strip() | ||
|
||
if arch in [arch_type, 'noarch']: | ||
record_tmp = name + ' ' + version + ' ' + arch | ||
if record_tmp not in rpm_arr: | ||
rpm_arr.append(record_tmp) | ||
return rpm_arr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
easypackages/watch_update_source/utils/getRpmSourceList.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import os | ||
import re | ||
import sys | ||
import argparse | ||
|
||
sys.path.append('../') | ||
from lib import lib_py_rpm | ||
|
||
''' | ||
功能描述: | ||
根据指定的源码包元数据文件,并解析出源码包列表 | ||
参数: | ||
lf: 结果清单文件(路径 + 文件名) | ||
xf: 元数据文件路径(primary.xml, 路径 + 文件名) | ||
repo: 仓库基地址 | ||
输出: | ||
结果清单文件: | ||
文 件 名: (输入指定) | ||
文件内容: (源码包仓库地址 源码包名 源码包版本) | ||
repo_addr rpm_name rpm_version | ||
样 例: | ||
https://dl.fedoraproject.org/pub/epel/testing/next/9/Everything/source/tree/repodata/Packages/r/rust-cargo-util-0.2.14-1.el9.next.src.rpm rust-cargo-util 0.2.14 | ||
https://dl.fedoraproject.org/pub/epel/testing/next/9/Everything/source/tree/repodata/Packages/r/rust-crates-io-0.40.4-1.el9.next.src.rpm rust-crates-io 0.40. | ||
''' | ||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser(usage=""" 获取源码包列表 """) | ||
parser.add_argument('-lf', type=str, required=True, help="结果文件") | ||
parser.add_argument('-xf', type=str, required=True, help="元数据文件") | ||
parser.add_argument('-repo', type=str, required=True, help="源码包远端地址") | ||
args = parser.parse_args() | ||
list_file = str(args.lf) | ||
primary_xml = str(args.xf) | ||
repo_base = str(args.repo) | ||
|
||
# 检查list文件 | ||
if os.path.exists(list_file): | ||
if not os.path.isfile(list_file): | ||
print(f"list file is not file: {list_file}") | ||
sys.exit(1) | ||
|
||
res = lib_py_rpm.get_src_rpm_list_by_primary_xml(primary_xml, repo_base) | ||
if res is None: | ||
print("FAIL NOW") | ||
sys.exit(1) | ||
|
||
with open(list_file, 'a') as file: | ||
for record in res: | ||
file.write(record + "\n") | ||
|
||
print("SUCCESS NOW") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters