代码解耦,优化静态变量
This commit is contained in:
parent
cd629267c4
commit
6992a1950c
|
@ -11,21 +11,11 @@ import datetime
|
|||
from gettext import gettext as _
|
||||
|
||||
import apt_pkg
|
||||
|
||||
from ..backend import InstallBackend
|
||||
DB_FILE = os.path.join("/var/cache/kylin-system-updater/kylin-system-updater.db")
|
||||
INSTALLED_LIST = [{"item": "errorcode", "type": "int", "default": "0"}]
|
||||
DISPALY_LIST = []
|
||||
|
||||
MODE_DEFAULT_STATUS = -1
|
||||
#部分升级
|
||||
MODE_UPGRADE_PARTIAL = 0
|
||||
#全部升级
|
||||
MODE_UPGRADE_ALL = 1
|
||||
#系统全盘升级
|
||||
MODE_UPGRADE_SYSTEM = 2
|
||||
#后端内部安装包使用
|
||||
MODE_UPGRADE_SINGLE = 3
|
||||
|
||||
class Sqlite3Server(object):
|
||||
def __init__(self, window_main):
|
||||
self.connect = None
|
||||
|
@ -158,7 +148,7 @@ class Sqlite3Server(object):
|
|||
status = 'failed'
|
||||
|
||||
# 判断更新方式
|
||||
if mode == MODE_UPGRADE_PARTIAL: # 部分更新
|
||||
if mode == InstallBackend.MODE_UPGRADE_PARTIAL: # 部分更新
|
||||
pkg_adj = ""
|
||||
# 判断更新包为单包或更新组
|
||||
if pkg_group:
|
||||
|
@ -205,7 +195,7 @@ class Sqlite3Server(object):
|
|||
self.insert_into_updateinfo(pkgname, pkgversion, pkgdescription, timestr, status, "1", errstr)
|
||||
# FIXME: 这里也需要, 发送插入数据库成功的信号
|
||||
self.window_main.dbusController.UpdateSqlitSingle(pkgname, timestr)
|
||||
elif mode == MODE_UPGRADE_ALL: # 系统升级
|
||||
elif mode == InstallBackend.MODE_UPGRADE_ALL: # 系统升级
|
||||
# # insert signal deb first
|
||||
for i in pkg_list:
|
||||
try:
|
||||
|
@ -239,7 +229,7 @@ class Sqlite3Server(object):
|
|||
self.init_sqlit()
|
||||
self.insert_into_updateinfo(str(i), pkgversion, pkgdescription, timestr, status, "1", errstr)
|
||||
self.window_main.dbusController.UpdateSqlitSingle(str(i), timestr)
|
||||
elif mode == MODE_UPGRADE_SYSTEM: # 全盘升级
|
||||
elif mode == InstallBackend.MODE_UPGRADE_SYSTEM: # 全盘升级
|
||||
pkgs_install,pkgs_upgrade,pkgs_remove = self.refreshpkglist()
|
||||
pkg_list = list(set(pkgs_upgrade).union(set(pkgs_install)))
|
||||
for i in pkg_list:
|
||||
|
|
|
@ -22,7 +22,6 @@ from .Core.loop import mainloop
|
|||
import time
|
||||
from gettext import gettext as _
|
||||
from SystemUpdater.backend import DownloadBackend as downb
|
||||
from SystemUpdater.Core.Database import MODE_UPGRADE_SINGLE
|
||||
import apt_pkg
|
||||
from SystemUpdater.Core.UpdaterConfigParser import UpgradeConfig
|
||||
|
||||
|
@ -208,7 +207,7 @@ class UpdateManager():
|
|||
logging.info("Self-Updater(%s) start upgrading...",self.SELF_PKG_NAME)
|
||||
pkg_json.mark_upgrade()
|
||||
|
||||
self.start_install(MODE_UPGRADE_SINGLE,True)
|
||||
self.start_install(InstallBackend.MODE_UPGRADE_SINGLE,True)
|
||||
#直接退出 进行安装程序
|
||||
_success = False
|
||||
header = self.INSTALL_ALONE_PROGRESS
|
||||
|
@ -246,7 +245,7 @@ class UpdateManager():
|
|||
logging.info("groups JSON ConfigPkgs(%s) start upgrading...",self.GROUPS_PKG_NAME)
|
||||
pkg_json.mark_upgrade()
|
||||
|
||||
self.start_install(MODE_UPGRADE_SINGLE,True)
|
||||
self.start_install(InstallBackend.MODE_UPGRADE_SINGLE,True)
|
||||
#直接退出
|
||||
_success = False
|
||||
header = self.INSTALL_ALONE_PROGRESS
|
||||
|
@ -256,7 +255,7 @@ class UpdateManager():
|
|||
else:
|
||||
logging.info("groups JSON ConfigPkgs(%s) start new installing...",self.GROUPS_PKG_NAME)
|
||||
pkg_json.mark_install()
|
||||
self.start_install(MODE_UPGRADE_SINGLE,True)
|
||||
self.start_install(InstallBackend.MODE_UPGRADE_SINGLE,True)
|
||||
#直接退出
|
||||
_success = False
|
||||
header = self.INSTALL_ALONE_PROGRESS
|
||||
|
|
|
@ -11,7 +11,6 @@ from .Core.utils import humanize_size
|
|||
from SystemUpdater.Core.utils import (
|
||||
unLockedEnableShutdown,
|
||||
)
|
||||
from SystemUpdater.Core.Database import MODE_UPGRADE_PARTIAL,MODE_UPGRADE_ALL,MODE_UPGRADE_SYSTEM
|
||||
|
||||
UPDATER_DBUS_INTERFACE = 'com.kylin.systemupgrade.interface'
|
||||
UPDATER_DBUS_PATH = '/com/kylin/systemupgrade'
|
||||
|
@ -211,7 +210,7 @@ class UpdateManagerDbusController(dbus.service.Object):
|
|||
return False,'In the process of updating or Upgrading...'
|
||||
else:
|
||||
logging.info(COLORMETHOR_PREFIX+'method'+COLORLOG_SUFFIX+' DistUpgradeAll and is_install:%r...',is_install)
|
||||
self.parent.start_install(MODE_UPGRADE_ALL,is_install)
|
||||
self.parent.start_install(InstallBackend.MODE_UPGRADE_ALL,is_install)
|
||||
return True,'success'
|
||||
except Exception as e:
|
||||
return False,str(e)
|
||||
|
@ -237,7 +236,7 @@ class UpdateManagerDbusController(dbus.service.Object):
|
|||
new_upgrade_list = list(set(partial_upgrade_list) & set(local_upgrade_groups + local_single_pkgs))
|
||||
|
||||
if new_upgrade_list:
|
||||
self.parent.start_install(MODE_UPGRADE_PARTIAL,is_install,partial_upgrade_list)
|
||||
self.parent.start_install(InstallBackend.MODE_UPGRADE_PARTIAL,is_install,partial_upgrade_list)
|
||||
return True,'dbus upgrading'
|
||||
else:
|
||||
logging.warning('input upgrade list(%s) not in local upgrade_list(%s)',partial_upgrade_list,local_upgrade_groups+local_single_pkgs)
|
||||
|
@ -290,7 +289,7 @@ class UpdateManagerDbusController(dbus.service.Object):
|
|||
return False,'In the process of updating or Upgrading...'
|
||||
else:
|
||||
logging.info(COLORMETHOR_PREFIX+'method'+COLORLOG_SUFFIX+' DistUpgradeSystem and is_install:%r...',is_install)
|
||||
self.parent.start_install(MODE_UPGRADE_SYSTEM,is_install)
|
||||
self.parent.start_install(InstallBackend.MODE_UPGRADE_SYSTEM,is_install)
|
||||
return True,'success'
|
||||
except Exception as e:
|
||||
logging.error(False, str(e))
|
||||
|
|
|
@ -15,7 +15,6 @@ from SystemUpdater.Core.utils import (
|
|||
check_free_space
|
||||
)
|
||||
import time
|
||||
from ..Core.Database import MODE_DEFAULT_STATUS,MODE_UPGRADE_PARTIAL,MODE_UPGRADE_ALL,MODE_UPGRADE_SYSTEM,MODE_UPGRADE_SINGLE
|
||||
|
||||
class NowUpgradePara:
|
||||
"""
|
||||
|
@ -23,9 +22,9 @@ class NowUpgradePara:
|
|||
run
|
||||
"""
|
||||
def __init__(self,
|
||||
upgrade_groups=[],
|
||||
upgrade_mode=MODE_DEFAULT_STATUS,
|
||||
single_pkgs=[],
|
||||
upgrade_groups,
|
||||
upgrade_mode,
|
||||
single_pkgs,
|
||||
):
|
||||
#组列表中包含的包
|
||||
self.upgrade_groups = upgrade_groups
|
||||
|
@ -47,27 +46,39 @@ class InstallBackend():
|
|||
ACTION_FIX_INCOMPLETE = 7
|
||||
ACTION_CLEAN = 8
|
||||
|
||||
#ACTION_INSTALL 的子类
|
||||
MODE_DEFAULT_STATUS = -1
|
||||
#部分升级
|
||||
MODE_UPGRADE_PARTIAL = 0
|
||||
#全部升级
|
||||
MODE_UPGRADE_ALL = 1
|
||||
#系统全盘升级
|
||||
MODE_UPGRADE_SYSTEM = 2
|
||||
#后端内部安装包使用
|
||||
MODE_UPGRADE_SINGLE = 3
|
||||
|
||||
def __init__(self, window_main, action):
|
||||
self.window_main = window_main
|
||||
self.cache = window_main.cache
|
||||
self.action = action
|
||||
|
||||
#对所有的操作进行枷锁 当执行完毕后返回到_action_done 进行解锁,除了计算依赖模式 不进入_action_done 单独解锁
|
||||
self.window_main.is_working = action
|
||||
|
||||
#更新的时候此对象还未生成
|
||||
if self.window_main.update_list != None:
|
||||
#本地维护的升级列表和需要升级的包
|
||||
self.upgrade_data = window_main.update_list.local_upgrade_data
|
||||
#要拿到升级列表必须调用_make_upgrade_list
|
||||
self.now_upgrade = NowUpgradePara([],MODE_DEFAULT_STATUS,[])
|
||||
self.now_upgrade = NowUpgradePara([],self.MODE_DEFAULT_STATUS,[])
|
||||
|
||||
def start(self,_upgrade_mode = MODE_DEFAULT_STATUS,partial_upgrade_list = []):
|
||||
#对所有的操作进行枷锁 当执行完毕后返回到_action_done 进行解锁,除了计算依赖模式 不进入_action_done 单独解锁
|
||||
self.window_main.is_working = self.action
|
||||
|
||||
#安装升级包 首先必须调用ACTION_CHECK_RESOLVER 计算依赖解决方便 标记cache 进行升级
|
||||
if self.action == self.ACTION_INSTALL:
|
||||
self.now_upgrade.upgrade_mode = _upgrade_mode
|
||||
|
||||
if _upgrade_mode != MODE_UPGRADE_SINGLE:
|
||||
if _upgrade_mode != self.MODE_UPGRADE_SINGLE:
|
||||
#拿到升级列表
|
||||
self.now_upgrade.upgrade_groups,self.now_upgrade.single_pkgs = self._make_groups_list(self.upgrade_data,_upgrade_mode,partial_upgrade_list)
|
||||
|
||||
|
@ -87,7 +98,7 @@ class InstallBackend():
|
|||
if _success == False:
|
||||
header = _("Disk space is insufficient, please clean the disk and then upgrade")
|
||||
#当单包安装检查内存不够的时候,报错到控制面板 单包安装属于更新才使用的所以直接赋值为更新 再进行之后的报错处理
|
||||
if self.now_upgrade.upgrade_mode == MODE_UPGRADE_SINGLE:
|
||||
if self.now_upgrade.upgrade_mode == self.MODE_UPGRADE_SINGLE:
|
||||
self.action = self.ACTION_UPDATE
|
||||
|
||||
self._action_done(self.action,True,False,header,desc)
|
||||
|
@ -105,7 +116,7 @@ class InstallBackend():
|
|||
#检查依赖之前 判断是否需要重启aptdeamon
|
||||
self.window_main.restart_aptdeamon()
|
||||
time.sleep(0.5)
|
||||
if _upgrade_mode != MODE_UPGRADE_SYSTEM:
|
||||
if _upgrade_mode != self.MODE_UPGRADE_SYSTEM:
|
||||
#获取要升级的组列表
|
||||
self.now_upgrade.upgrade_groups,self.now_upgrade.single_pkgs = self._make_groups_list(self.upgrade_data,_upgrade_mode,partial_upgrade_list)
|
||||
#获取要升级和安装的包列表
|
||||
|
@ -141,7 +152,7 @@ class InstallBackend():
|
|||
raw_description.append(getattr(pkg_obj.candidate, "summary", ''))
|
||||
#解锁忙碌
|
||||
self.window_main.is_working = self.ACTION_DEFUALT_STATUS
|
||||
if _upgrade_mode != MODE_UPGRADE_SYSTEM:
|
||||
if _upgrade_mode != self.MODE_UPGRADE_SYSTEM:
|
||||
self.window_main.dbusController.UpdateDependResloveStatus(_success,is_remove_pkgs,pkgs_remove,raw_description,delete_desc,header,desc)
|
||||
else:
|
||||
self.window_main.dbusController.DistupgradeDependResloveStatus(_success,is_remove_pkgs,pkgs_remove,raw_description,header,desc)
|
||||
|
@ -210,7 +221,7 @@ class InstallBackend():
|
|||
pkgs_remove = []
|
||||
|
||||
#全盘升级不做任何的调整 修复bug,出现调整版本,报错不需要更新升级退出
|
||||
if upgrade_mode == MODE_UPGRADE_SYSTEM:
|
||||
if upgrade_mode == self.MODE_UPGRADE_SYSTEM:
|
||||
adjust_pkgs = []
|
||||
else:
|
||||
#获取调整包列表 去掉版本号
|
||||
|
@ -243,7 +254,7 @@ class InstallBackend():
|
|||
pkg_list = []
|
||||
|
||||
#可选升级
|
||||
if _upgrade_mode == MODE_UPGRADE_PARTIAL:
|
||||
if _upgrade_mode == self.MODE_UPGRADE_PARTIAL:
|
||||
for i in partial_upgrade_list:
|
||||
#组升级方式
|
||||
if i in upgrade_data.upgrade_groups:
|
||||
|
@ -255,7 +266,7 @@ class InstallBackend():
|
|||
logging.warning("this package(%s) not in selected list",i)
|
||||
|
||||
#全部升级列表
|
||||
elif _upgrade_mode == MODE_UPGRADE_ALL:
|
||||
elif _upgrade_mode == self.MODE_UPGRADE_ALL:
|
||||
groups_list = upgrade_data.upgrade_groups
|
||||
pkg_list = upgrade_data.single_pkgs
|
||||
|
||||
|
@ -459,7 +470,7 @@ class InstallBackend():
|
|||
error_string, error_desc)
|
||||
if success:
|
||||
#当组列表为空时 表示现在的单独进行安装某些包或卸载,不发信号到控制面板
|
||||
if self.now_upgrade.upgrade_mode != MODE_UPGRADE_SINGLE:
|
||||
if self.now_upgrade.upgrade_mode != self.MODE_UPGRADE_SINGLE:
|
||||
#升级完成后从升级列表删除
|
||||
for groups in self.now_upgrade.upgrade_groups:
|
||||
self.upgrade_data.upgrade_groups.remove(groups)
|
||||
|
@ -476,7 +487,7 @@ class InstallBackend():
|
|||
self.window_main.start_available()
|
||||
return
|
||||
#当更新过程中安装配置包时 失败时发送错误信号
|
||||
elif success == False and self.now_upgrade.upgrade_mode == MODE_UPGRADE_SINGLE:
|
||||
elif success == False and self.now_upgrade.upgrade_mode == self.MODE_UPGRADE_SINGLE:
|
||||
self.window_main.dbusController.UpdateDetectFinished(success,upgrade_content,error_string+','+error_desc,error_desc)
|
||||
|
||||
if error_string != '' or error_desc != '':
|
||||
|
|
Loading…
Reference in New Issue