调整代码结构

This commit is contained in:
wangsong 2021-09-07 16:01:32 +08:00
parent df38199677
commit c767f9b2fd
2 changed files with 727 additions and 79 deletions

View File

@ -223,6 +223,9 @@ class UpdateList():
#FIXME: 最好将这个常量通过配置文件读
self.GROUPS_JSON_PKG = 'kylin-update-desktop-config'
self.input_config_path = '/home/x/share/outconfig'
self.output_config_path = '/home/x/share/inconfig'
# a stable machine uniq id
try:
with open(self.UNIQ_MACHINE_ID_FILE) as f:
@ -488,6 +491,87 @@ class UpdateList():
return app_groups + pkg_groups
def _make_json(self,cache,pkgs_install, pkgs_upgrade, pkgs_remove):
try:
files = os.listdir(self.input_config_path) #获得文件夹中所有文件的名称列表
for file in files:
#判是否是目录以及是否以JSON结尾
if not os.path.isdir(file) and file.endswith('.json'):
with open(self.input_config_path+"/"+file,'r') as f:
data = json.load(f)
output_json = {}
install_pkgs_list = data['install_list']
upgrade_pkgs_list = data['upgrade_list']
hold_pkgs_list = data['hold_list']
remove_pkgs_list = data['remove_list']
#生成需要升级的包的JSON内容
#进行交集 查找两个列表同时存在的
upgrade_intersection_pkgs = list(set(pkgs_upgrade) & set(upgrade_pkgs_list))
#在总升级列表中移除这些包
for pkg in upgrade_intersection_pkgs:
pkgs_upgrade.remove(pkg)
size = 0
total_size = 0
upgrade_pkgs_json = {}
for pkg_name in upgrade_intersection_pkgs:
try:
pkg = cache[pkg_name]
#获取下载大小
size = getattr(pkg.candidate, "size", 0)
total_size = total_size + size
upgrade_pkgs_json.update({pkg_name:{"size":size}})
except Exception as e:
pass
upgrade_pkgs_json.update({"total_size":humanize_size(total_size)})
#生成安装的软件列表
install_pkgs_json = {}
total_size = 0
for pkg_name in install_pkgs_list:
try:
#会存在不在cache的包直接抛出异常
pkg = cache[pkg_name]
#如果这个包已经安装则不计算在内
if pkg.is_installed:
continue
#获取下载大小
size = getattr(pkg.candidate, "size", 0)
total_size = total_size + size
install_pkgs_json.update({pkg_name:{"size":size}})
except Exception as e:
pass
# logging.DEBUG(e)
install_pkgs_json.update({"total_size":humanize_size(total_size)})
#添加一些基础信息
output_json.update({"package":data['package']})
output_json.update({"version":data['version']})
output_json.update({"name":data['name']})
output_json.update({"description":data['description']})
output_json.update({"icon":data['icon']})
#添加升级的内容
output_json.update({"upgrade_list":upgrade_pkgs_json})
output_json.update({"install_list":install_pkgs_json})
output_json.update({"hold_list":hold_pkgs_list})
output_json.update({"remove_list":remove_pkgs_list})
with open( self.output_config_path + '/' + data['package'] + '_output.json', 'w', encoding='utf-8') as f:
json.dump(output_json, f, ensure_ascii=False, indent=4)
else:
pass
except Exception as e:
logging.error(e)
def update(self, cache,start_install_alone, eventloop_callback=None):
self.held_back = []
@ -528,81 +612,13 @@ class UpdateList():
except Exception as e:
logging.error(e)
self._make_json(cache,self.pkgs_install,self.pkgs_upgrade,self.pkgs_remove)
#FIXME: 目前此功能不使用 但是以此按应用进行分组是更好的展示升级列表的方式
# self.update_groups = self._make_groups(cache, self.pkgs_upgrade,
# eventloop_callback)
path = '/home/x/share/config'
try:
files = os.listdir(path) #获得文件夹中所有文件的名称列表
for file in files:
#判是否是目录以及是否以JSON结尾
if not os.path.isdir(file) and file.endswith('.json'):
with open(path+"/"+file,'r') as f:
data = json.load(f)
output_json = {}
install_pkgs_list = data['install_list']
upgrade_pkgs_list = data['upgrade_list']
hold_pkgs_list = data['hold_list']
remove_pkgs_list = data['remove_list']
#进行交集 查找两个列表同时存在的
upgrade_intersection_pkgs = list(set(self.pkgs_upgrade) & set(upgrade_pkgs_list))
#在总升级列表中移除这些包
for pkg in upgrade_intersection_pkgs:
self.pkgs_upgrade.remove(pkg)
#生成需要升级的包的JSON内容
size = 0
total_size = 0
upgrade_pkgs_json = {}
for pkg_name in upgrade_intersection_pkgs:
try:
pkg = cache[pkg_name]
#获取下载大小
size = getattr(pkg.candidate, "size", 0)
total_size = total_size + size
upgrade_pkgs_json.update({pkg_name:{"size":size}})
except Exception as e:
pass
upgrade_pkgs_json.update({"total_size":humanize_size(total_size)})
#生成安装的软件列表
install_pkgs_json = {}
total_size = 0
for pkg_name in install_pkgs_list:
try:
#会存在不在cache的包直接抛出异常
pkg = cache[pkg_name]
#如果这个包已经安装则不计算在内
if pkg.is_installed:
continue
#获取下载大小
size = getattr(pkg.candidate, "size", 0)
total_size = total_size + size
install_pkgs_json.update({pkg_name:{"size":size}})
except Exception as e:
pass
# logging.DEBUG(e)
install_pkgs_json.update({"total_size":humanize_size(total_size)})
output_json.update({"upgrade_list":upgrade_pkgs_json})
output_json.update({"install_list":install_pkgs_json})
output_json.update({"hold_list":hold_pkgs_list})
output_json.update({"remove_list":remove_pkgs_list})
# # FIXME: 配置文件防止位置需要确定
with open('pkgs.json', 'w', encoding='utf-8') as f:
json.dump(output_json, f, ensure_ascii=False, indent=4)
else:
pass
except Exception as e:
logging.error(e)
# fu = filter.UpdateListFilterCache("/")
@ -621,11 +637,4 @@ class UpdateList():
# blacklist_filter_pkgs = fu.is_pkgname_in_blacklist(whitelist_filter_upgrade_pkgs)
# print("blacklist_filter_pkgs: %s"%" ".join([i.name for i in blacklist_filter_pkgs]))
#支持输出json文件 包含新安装 and 升级 and 移除
# pkgs_json = {"install": self.pkgs_install, "upgrade": self.pkgs_upgrade,"remove": self.pkgs_remove}
# # FIXME: 配置文件防止位置需要确定
# with open('pkgs.json', 'w', encoding='utf-8') as f:
# json.dump(pkgs_json, f, ensure_ascii=False, indent=4)

View File

@ -0,0 +1,639 @@
{
"package": "kylin-update-desktop-system",
"version": "sp1-2021-0722",
"name": {
"zh_CN": "系统更新",
"en_US": "Kylin OS"
},
"description": {
"zh_CN": "银河麒麟v10SP1-系统更新包",
"en_US": "Galaxy Kylin v10SP1-System Update Package"
},
"icon": "/usr/share/kylin-update-desktop-config/icon/kylin-update-desktop-system.png",
"upgrade_list": {
"grub-common": {
"size": 3084208
},
"xfsprogs": {
"size": 886390
},
"util-linux": {
"size": 1046758
},
"kolourpaint": {
"size": 5790636
},
"pluma": {
"size": 405906
},
"librockey": {
"size": 58602
},
"ukui-biometric-manager": {
"size": 2476096
},
"selinux-policy-doc": {
"size": 485830
},
"libaudit-common": {
"size": 15354
},
"selinux-utils": {
"size": 141240
},
"libaudit1": {
"size": 53986
},
"plymouth-label": {
"size": 44578
},
"xwayland": {
"size": 936348
},
"box-utils": {
"size": 18088
},
"bsdutils": {
"size": 123768
},
"kylin-burner": {
"size": 2541704
},
"youker-assistant": {
"size": 7551220
},
"fcitx-frontend-all": {
"size": 16976
},
"network-manager-gnome": {
"size": 942872
},
"box-manager": {
"size": 4073712
},
"filezilla": {
"size": 1654772
},
"base-files": {
"size": 90568
},
"pulseaudio-utils": {
"size": 133142
},
"atril": {
"size": 171452
},
"apparmor": {
"size": 521072
},
"apt": {
"size": 1392384
},
"engrampa": {
"size": 338760
},
"kylin-display-switch": {
"size": 131944
},
"usbutils": {
"size": 76876
},
"grub2-common": {
"size": 571940
},
"system-config-printer-common": {
"size": 652884
},
"system-config-printer": {
"size": 91776
},
"apt-utils": {
"size": 423290
},
"transmission-qt": {
"size": 625100
},
"selinux-policy-ukmls": {
"size": 3296272
},
"libsemanage1": {
"size": 93292
},
"ukui-system-monitor": {
"size": 800714
},
"mount": {
"size": 177532
},
"install-info": {
"size": 148720
},
"ukui-session-manager": {
"size": 2070590
},
"kylin-service-support": {
"size": 2083424
},
"neokylin-indexhtml": {
"size": 498936
},
"kylin-software-center": {
"size": 167874954
},
"systemd-sysv": {
"size": 144368
},
"biometric-driver-aratek-trustfinger-common": {
"size": 106212
},
"engrampa-common": {
"size": 850768
},
"firefox-esr": {
"size": 48794152
},
"tar": {
"size": 768440
},
"libsemanage-common": {
"size": 23202
},
"kylin-usb-creator": {
"size": 523816
},
"mate-terminal-common": {
"size": 1041956
},
"selinux-policy-common": {
"size": 53264
},
"kylin-verify": {
"size": 9292
},
"initramfs-tools-bin": {
"size": 102784
},
"peony-open-terminal": {
"size": 20376
},
"openssh-client": {
"size": 716784
},
"xserver-xorg-legacy": {
"size": 132364
},
"kylin-ipmsg": {
"size": 837492
},
"kylin-nm": {
"size": 478464
},
"kmod": {
"size": 91156
},
"openssh-server": {
"size": 354186
},
"security-switch": {
"size": 32616
},
"hplip": {
"size": 34621954
},
"rfkill": {
"size": 87232
},
"libavahi-core7": {
"size": 111592
},
"libsecurity1": {
"size": 7766
},
"dmidecode": {
"size": 52228
},
"adduser": {
"size": 242724
},
"xserver-xorg-core": {
"size": 1332528
},
"libgtk-3-bin": {
"size": 125584
},
"udev": {
"size": 1449088
},
"kylin-activation": {
"size": 196932
},
"fcitx-config-gtk": {
"size": 37916
},
"kylin-screenshot": {
"size": 440884
},
"apparmor-utils": {
"size": 119536
},
"aptdaemon": {
"size": 302256
},
"procps": {
"size": 265300
},
"iagno": {
"size": 583048
},
"login": {
"size": 515628
},
"peony-share": {
"size": 35232
},
"kylin-verify-gui": {
"size": 328588
},
"binutils": {
"size": 73070
},
"bluez-cups": {
"size": 76298
},
"ubuntu-minimal": {
"size": 48624
},
"cups-filters": {
"size": 827002
},
"selinux-policy-targeted": {
"size": 3200980
},
"initramfs-tools-core": {
"size": 52942
},
"ntfs-3g": {
"size": 384172
},
"ukui-settings-daemon": {
"size": 155480
},
"linux-libc-dev": {
"size": 1265636
},
"info": {
"size": 288360
},
"wget": {
"size": 924772
},
"plymouth": {
"size": 153068
},
"pluma-common": {
"size": 1895006
},
"vino": {
"size": 373148
},
"libfontembed1": {
"size": 125330
},
"tzdata": {
"size": 372648
},
"ukui-settings-daemon-common": {
"size": 304484
},
"kylin-update-manager": {
"size": 40964
},
"locales": {
"size": 4098488
},
"systemd": {
"size": 3684260
},
"biometric-driver-aratek-trustfinger": {
"size": 19716
},
"selinux-policy-ukmcs": {
"size": 3221456
},
"kylin-sso-client": {
"size": 637900
},
"ukui-media": {
"size": 353076
},
"onboard-data": {
"size": 3810422
},
"python3-cupshelpers": {
"size": 46674
},
"cups-browsed": {
"size": 202074
},
"onboard": {
"size": 353084
},
"sqlite3": {
"size": 905672
},
"cups-filters-core-drivers": {
"size": 247216
},
"peony": {
"size": 304824
},
"kylin-music": {
"size": 682520
},
"initramfs-tools": {
"size": 11104
},
"parchives": {
"size": 20064
},
"kylin-video": {
"size": 2292200
},
"biometric-driver-r301": {
"size": 23344
},
"avahi-utils": {
"size": 61658
},
"ukui-kwin": {
"size": 11680
},
"bind9-dnsutils": {
"size": 165840
},
"remmina": {
"size": 160664
},
"dash": {
"size": 105164
},
"libavahi-ui-gtk3-0": {
"size": 55936
},
"fcitx": {
"size": 18458
},
"kylin-user-guide": {
"size": 86100
},
"libavahi-common3": {
"size": 58640
},
"indicator-china-weather": {
"size": 1252172
},
"ukui-sidebar": {
"size": 8411864
},
"ksc-defender": {
"size": 5441934
},
"libbox1": {
"size": 25828
},
"kylin-recorder": {
"size": 173444
},
"peony-extensions": {
"size": 7036
},
"ukui-greeter": {
"size": 813024
},
"pulseaudio": {
"size": 1096072
},
"biometric-driver-community-multidevice": {
"size": 32768
},
"ukui-panel": {
"size": 679392
},
"system-config-printer-udev": {
"size": 32880
},
"libchkuid": {
"size": 8626
},
"kylin-installer": {
"size": 314868
},
"ukui-media-common": {
"size": 106012
},
"perl": {
"size": 291036
},
"dpkg": {
"size": 2226538
},
"bash": {
"size": 1355600
},
"gparted-common": {
"size": 1120278
},
"biometric-utils": {
"size": 22264
},
"passwd": {
"size": 831724
},
"tigervnc-standalone-server": {
"size": 956164
},
"sane-utils": {
"size": 219880
},
"g++": {
"size": 3468
},
"linux-firmware": {
"size": 103851672
},
"ukui-touchegg": {
"size": 144172
},
"libpam-biometric": {
"size": 431916
},
"avahi-daemon": {
"size": 96044
},
"python3-audit": {
"size": 63442
},
"yhkylin-backup-tools": {
"size": 5699388
},
"onboard-common": {
"size": 550532
},
"linux-generic": {
"size": 21408
},
"auditd": {
"size": 198672
},
"ukui-about": {
"size": 70232
},
"uidmap": {
"size": 84864
},
"ukui-polkit": {
"size": 83828
},
"kylin-camera": {
"size": 141540
},
"rsync": {
"size": 317404
},
"gcc": {
"size": 7100
},
"kylin-log-viewer": {
"size": 3034664
},
"gnome-mines": {
"size": 228884
},
"ukui-screensaver": {
"size": 270000
},
"kylin-xinput-calibrator": {
"size": 33312
},
"ukui-menu": {
"size": 492366
},
"biometric-auth": {
"size": 34760
},
"kylin-scanner": {
"size": 674700
},
"libavahi-common-data": {
"size": 127848
},
"pulseaudio-module-bluetooth": {
"size": 135468
},
"atril-common": {
"size": 913992
},
"aptdaemon-data": {
"size": 202252
},
"ukui-control-center": {
"size": 11872172
},
"libavahi-client3": {
"size": 62414
},
"gnome-tetravex": {
"size": 998928
},
"tigervnc-common": {
"size": 73078
},
"ubuntukylin-default-settings": {
"size": 18576
},
"libavahi-glib1": {
"size": 45456
},
"mate-terminal": {
"size": 134508
},
"firefox-esr-locale-zh-hans": {
"size": 614886
},
"network-manager-pptp-gnome": {
"size": 30632
},
"apparmor-profiles": {
"size": 100828
},
"ubuntukylin-wallpapers": {
"size": 1677368
},
"libbiometric0": {
"size": 64184
},
"avahi-autoipd": {
"size": 59540
},
"linux-tools-common": {
"size": 373894
},
"kylin-software-properties": {
"size": 144680
},
"libcupsfilters1": {
"size": 184928
},
"ukui-window-switch": {
"size": 3732848
},
"selinux-policy-dev": {
"size": 492480
},
"ffmpeg": {
"size": 1454714
},
"biometric-driver-a210": {
"size": 40124
},
"remmina-common": {
"size": 367828
},
"libkylin-activation": {
"size": 95310
},
"kylin-printer": {
"size": 137974
},
"kylin-background-upgrade": {
"size": 68812
},
"lightdm": {
"size": 168362
},
"xserver-common": {
"size": 126994
},
"cutecom": {
"size": 94670
},
"perl-base": {
"size": 1454468
},
"gparted": {
"size": 360158
},
"total_size": "511.1 MB"
},
"install_list": {
"kylin-photo-viewer": {
"size": 4406216
},
"makedev": {
"size": 41998
},
"total_size": "4.4 MB"
},
"hold_list": [],
"remove_list": []
}