加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
compare_source.py 9.30 KB
一键复制 编辑 原始数据 按行查看 历史
沈亚峰 提交于 2024-06-21 15:20 . initial commit
#!/bin/python3
import apt
import sys
import os
import time
class SourceAnalyser:
def __init__(self,site1,site2) -> None:
pass
self.system_upgrade_only =[]
self.security_upgrade_only=[]
self.system_candidate=[]
self.security_candidate=[]
self.site1=site1
self.site2=site2
self.package_class={'system_info':['distro'],\
'database':['ecpg','pgtypes','pq','ctdb'],\
'audio':['faad','barcode','vlc','sql'],\
'network_service':['dropbear','freerdp','backport','strongswan'],\
'wayland':['wayland'],\
'glib':['glib','gtk','gir'],\
'lib':['lib'],\
'qt':['qt'],\
'python':['python'],\
'golang':['golang'],\
'linux':['linux'],\
'gpu':['gpu''nvidia'],\
'app':['app','deepin'],\
'debug':['afl','dbgsym','gdb'],\
'compiler':['gcc','g++','bcc','bin86','elks'],\
'atm':['atm','br2684ctl'],\
'windows':['bisheng','crossover'],\
'printer_driver':['cnrdrvcups','eplq-cups','printer'],\
'disk_manager':['com.deepin.diskmanager'],\
'input_method':['sogoupinyin'],\
'desktop_envirionment':['dcc','dde','dt','downloader','fonts','lastore','uos','desktop','dbus','dpkg','xdg'],\
'deb':['dcmc'],\
'driver':['dcp','lanxum'],\
'file':['dlnfs','filearmor'],\
}
self.package_class_count={'system_info':0,\
'database':0,\
'audio':0,\
'network_service':0,\
'wayland':0,\
'glib':0,\
'lib':0,\
'qt':0,\
'python':0,\
'golang':0,\
'linux':0,\
'gpu':0,\
'app':0,\
'debug':0,\
'compiler':0,\
'atm':0,\
'windows':0,\
'printer_driver':0,\
'disk_manager':0,\
'input_method':0,\
'desktop_envirionment':0,\
'deb':0,\
'driver':0,\
'file':0,\
}
def compare_source(self):
cache = apt.Cache()
system_upgrade_flag = False
security_upgrade_flag = False
system_upgrade_count = 0
security_upgrade_count =0
for pkg in cache:
system_upgrade_count = 0
security_upgrade_count =0
for version in pkg.versions:
for origin in version.origins:
if origin.site ==self.site1:
system_upgrade_count+=1
if origin.site ==self.site2:
security_upgrade_count+=1
candidate = pkg.candidate
system_upgrade_flag = False
security_upgrade_flag = False
for origin in candidate.origins:
if origin.site ==self.site1:
system_upgrade_flag=True
if origin.site ==self.site2:
security_upgrade_flag=True
if system_upgrade_count>0 and security_upgrade_count==0:
self.system_upgrade_only.append((pkg.name,pkg.candidate.version,pkg.candidate.description))
elif security_upgrade_count>0 and system_upgrade_count==0:
self.security_upgrade_only.append((pkg.name,pkg.candidate.version,pkg.candidate.description))
elif system_upgrade_flag and not security_upgrade_flag:
self.system_candidate.append((pkg.name,pkg.candidate.version,pkg.candidate.description))
elif security_upgrade_flag and not system_upgrade_flag:
self.security_candidate.append((pkg.name,pkg.candidate.version,pkg.candidate.description))
print("system only:%d"%(len(self.system_upgrade_only)))
print("security only:%d"%(len(self.security_upgrade_only)))
print("system candidate:%d"%(len(self.system_candidate)))
print("security candidate:%d"%(len(self.security_candidate)))
def classify_packages(self):
for pkg in self.system_upgrade_only:
for key in self.package_class.keys():
for item in self.package_class[key]:
if item in pkg[0]:
self.package_class_count[key]=self.package_class_count[key]+1
print("system upgrade only:")
print(self.package_class_count)
self.clear_class_count()
for pkg in self.security_upgrade_only:
for key in self.package_class.keys():
for item in self.package_class[key]:
if item in pkg[0]:
self.package_class_count[key]=self.package_class_count[key]+1
print("system upgrade only:")
print(self.package_class_count)
self.clear_class_count()
for pkg in self.system_candidate:
for key in self.package_class.keys():
for item in self.package_class[key]:
if item in pkg[0]:
self.package_class_count[key]=self.package_class_count[key]+1
print("system candidate:")
print(self.package_class_count)
self.clear_class_count()
for pkg in self.security_candidate:
for key in self.package_class.keys():
for item in self.package_class[key]:
if item in pkg[0]:
self.package_class_count[key]=self.package_class_count[key]+1
print("security candidate:")
print(self.package_class_count)
self.clear_class_count()
def clear_class_count(self):
for key in self.package_class_count:
self.package_class_count[key]=0
def compare_source():
cache = apt.Cache()
system_upgrade_flag = False
security_upgrade_flag = False
system_upgrade_count = 0
security_upgrade_count =0
system_upgrade_only =[]
security_upgrade_only=[]
system_candidate=[]
security_candidate=[]
for pkg in cache:
system_upgrade_count = 0
security_upgrade_count =0
for version in pkg.versions:
for origin in version.origins:
if origin.site =="professional-packages.chinauos.com":
system_upgrade_count+=1
if origin.site =="professional-security.chinauos.com":
security_upgrade_count+=1
candidate = pkg.candidate
system_upgrade_flag = False
security_upgrade_flag = False
for origin in candidate.origins:
if origin.site =="professional-packages.chinauos.com":
system_upgrade_flag=True
if origin.site =="professional-security.chinauos.com":
security_upgrade_flag=True
if system_upgrade_count>0 and security_upgrade_count==0:
system_upgrade_only.append((pkg.name,pkg.candidate.version,pkg.candidate.description))
elif security_upgrade_count>0 and system_upgrade_count==0:
security_upgrade_only.append((pkg.name,pkg.candidate.version,pkg.candidate.description))
elif system_upgrade_flag and not security_upgrade_flag:
system_candidate.append((pkg.name,pkg.candidate.version,pkg.candidate.description))
elif security_upgrade_flag and not system_upgrade_flag:
security_candidate.append((pkg.name,pkg.candidate.version,pkg.candidate.description))
# print("system package:%d security package:%d"%(system_upgrade_num,security_upgrade_num))
# print("security different package num:%d"%(security_upgrade_diff_num))
print("system only:%d"%(len(system_upgrade_only)))
for pkg in system_upgrade_only:
print(pkg)
print("security only:%d"%(len(security_upgrade_only)))
for pkg in security_upgrade_only:
print(pkg)
print("system candidate:%d"%(len(system_candidate)))
for pkg in system_candidate:
print(pkg)
print("security candidate:%d"%(len(security_candidate)))
for pkg in security_candidate:
print(pkg)
def print_time():
# 获取当前时间戳
timestamp = time.time()
# 将时间戳转换为本地时间的元组
local_time = time.localtime(timestamp)
# 格式化日期和时间
formatted_time = time.strftime("%Y-%m-%d %H:%M:%S", local_time)
print(formatted_time)
if __name__ == "__main__":
print_time()
# compare_source()
sourceanalyser = SourceAnalyser("professional-packages.chinauos.com","professional-security.chinauos.com")
sourceanalyser.compare_source()
sourceanalyser.classify_packages()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化