修复回退界面卡住问题
This commit is contained in:
parent
5472804efc
commit
fc86834f6a
|
@ -20,66 +20,8 @@
|
|||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
# USA
|
||||
|
||||
import gi
|
||||
gi.require_version('OSTree', '1.0')
|
||||
from gi.repository import OSTree
|
||||
import logging
|
||||
|
||||
LOCAL_SUMMARY_DATA = "/var/ostree-summary"
|
||||
|
||||
class MyCache():
|
||||
def __init__(self):
|
||||
# sysroot
|
||||
self.sysroot = OSTree.Sysroot.new_default()
|
||||
self.sysroot.set_mount_namespace_in_use()
|
||||
self.sysroot.initialize()
|
||||
self.sysroot.load()
|
||||
|
||||
self.deployment = self.sysroot.get_booted_deployment()
|
||||
|
||||
self.cur_checksum = self.deployment.get_csum()
|
||||
|
||||
self.osname = self.deployment.get_osname()
|
||||
|
||||
oringin_f = self.deployment.get_origin()
|
||||
refspec = oringin_f.get_string("origin","refspec")
|
||||
ret,self.origin_remote,self.origin_ref = OSTree.parse_refspec(refspec)
|
||||
|
||||
self.new_revision = self.cur_checksum
|
||||
self.available_refs = self.origin_ref
|
||||
|
||||
def _initDepCache(self):
|
||||
self._depcache.read_pinfile()
|
||||
self._depcache.init()
|
||||
|
||||
def clear(self):
|
||||
self._initDepCache()
|
||||
|
||||
def list_refs(self):
|
||||
repo = self.sysroot.repo()
|
||||
|
||||
ret,all_refs = repo.list_refs(None,None)
|
||||
|
||||
refs = list(all_refs.keys())
|
||||
|
||||
return refs
|
||||
|
||||
def rollback_deployment(self):
|
||||
repo = self.sysroot.repo()
|
||||
out_pending,out_rollback = self.sysroot.query_deployments_for(self.osname)
|
||||
|
||||
if out_rollback:
|
||||
rollback_checksum = self.deployment.get_csum()
|
||||
|
||||
ret,metadata = repo.load_variant(OSTree.ObjectType.COMMIT,rollback_checksum)
|
||||
|
||||
n_metadata = metadata[0]
|
||||
|
||||
return n_metadata
|
||||
else:
|
||||
return ""
|
||||
|
||||
def get_metadata(self,checksum):
|
||||
repo = self.sysroot.repo()
|
||||
ret,metadata = repo.load_variant(OSTree.ObjectType.COMMIT,checksum)
|
||||
return metadata[0]
|
||||
self.cur_refs = ""
|
||||
self.rollback_deployment = []
|
||||
|
|
@ -11,7 +11,7 @@ from gettext import gettext as _
|
|||
from dbus.mainloop.glib import DBusGMainLoop
|
||||
DBusGMainLoop(set_as_default=True)
|
||||
from .Core.Database import Sqlite3Server
|
||||
from .backend.BackendOstreeNext import UpdateBackend,DownloadBackend,DeployBackend,RollbackBackend
|
||||
from .backend.BackendOstreeNext import UpdateBackend,DownloadBackend,DeployBackend,RollbackBackend,LoadCacheBackend
|
||||
from .UpdateManagerDbus import UpdateManagerDbusController,UPDATER_DBUS_INTERFACE,UPDATER_DBUS_PATH,UPDATER_DBUS_SERVICE
|
||||
from SystemUpdater.Core.UpdaterConfigParser import UpgradeConfig
|
||||
from .Core.MyCache import MyCache
|
||||
|
@ -25,17 +25,16 @@ class UpdateManager():
|
|||
def __init__(self,options):
|
||||
try:
|
||||
self.options = options
|
||||
|
||||
#FIXME: 如何解决值的保存
|
||||
# self.cache = MyCache()
|
||||
|
||||
self.cache = MyCache()
|
||||
self.trans = UpdatesAvailable(self)
|
||||
|
||||
self.sqlite3_server = Sqlite3Server(self)
|
||||
self.configs_uncover = UpgradeConfig(defaults_dir="system-updater-defaults.conf")
|
||||
self.bus = dbus.SystemBus()
|
||||
self.dbus_send = self._setup_dbus(self.bus)
|
||||
|
||||
|
||||
cache_backend = LoadCacheBackend(self,self.options.sysroot,self.options.os)
|
||||
cache_backend.run(self.cache)
|
||||
except Exception as e:
|
||||
logging.error(e)
|
||||
|
||||
|
|
|
@ -104,7 +104,7 @@ class UpdateManagerDbusController(dbus.service.Object):
|
|||
object_path=UPDATER_DBUS_PATH):
|
||||
dbus.service.Object.__init__(self, bus_name, object_path)
|
||||
self.parent = parent
|
||||
# self.cache = parent.cache
|
||||
self.cache = parent.cache
|
||||
self.bus = bus
|
||||
self.prohibit_list = []
|
||||
|
||||
|
@ -130,31 +130,6 @@ class UpdateManagerDbusController(dbus.service.Object):
|
|||
mainloop.quit()
|
||||
logging.debug("Exit")
|
||||
|
||||
|
||||
#获取后端现在的状态
|
||||
@dbus.service.method(UPDATER_DBUS_INTERFACE,in_signature='s',out_signature='i',sender_keyword='sender')
|
||||
def GetBackendStatus(self,user_lang,sender=None):
|
||||
try:
|
||||
sender_name = get_proc_from_dbus_name(sender)
|
||||
logging.info(COLORMETHOR_PREFIX+'Method'+COLORLOG_SUFFIX+' GetBackendStatus and user_lang = %s sender_name:%s status:%d...',str(user_lang),sender_name,self.now_working)
|
||||
return self.now_working
|
||||
except Exception as e:
|
||||
logging.error(str(e))
|
||||
return self.now_working
|
||||
|
||||
#更新的dbus
|
||||
@dbus.service.method(UPDATER_DBUS_INTERFACE,out_signature='s',sender_keyword='sender')
|
||||
def CheckPopupOnPoweroffInstalled(self,sender=None):
|
||||
try:
|
||||
sender_name = get_proc_from_dbus_name(sender)
|
||||
|
||||
logging.info(COLORMETHOR_PREFIX+'Method'+COLORLOG_SUFFIX+' ChcekPopupOnPoweroffInstalled sender:%s...',sender_name)
|
||||
return "none"
|
||||
except Exception as e:
|
||||
logging.error(str(e))
|
||||
return "none"
|
||||
|
||||
|
||||
# =============================== 检查更新 =============================== */
|
||||
|
||||
@dbus.service.method(UPDATER_DBUS_INTERFACE,out_signature='is',sender_keyword='sender')
|
||||
|
@ -280,6 +255,21 @@ class UpdateManagerDbusController(dbus.service.Object):
|
|||
logging.error(str(e))
|
||||
return self.RETURN_UNKNOWN_CODE,str(e)
|
||||
|
||||
def RollbackSysFinishedNext(self, success, version_name,error_code):
|
||||
self.RollbackSysFinished(success,version_name,error_code,get_error_description_from_enum(error_code))
|
||||
|
||||
@dbus.service.signal(UPDATER_DBUS_INTERFACE,signature='bsss')
|
||||
def RollbackSysFinished(self, success, version_name,error_code='',error_desc=''):
|
||||
self.now_working = self.ACTION_DEFUALT_STATUS
|
||||
logging.info(COLORLOG_PREFIX + "Emitting" + COLORLOG_SUFFIX +" RollbackSysFinished success = %r , upgrade_group = %s, error_code = %s , error_desc = %s ",\
|
||||
success,version_name, error_code,error_desc)
|
||||
|
||||
# =============================== 其他 =============================== */
|
||||
#重启和注销请求信号
|
||||
@dbus.service.signal(UPDATER_DBUS_INTERFACE,signature='s')
|
||||
def RebootLogoutRequired(self,required_status=''):
|
||||
logging.info(COLORLOG_PREFIX + "Emitting"+ COLORLOG_SUFFIX + " RebootLogoutRequired required_status = %s",required_status)\
|
||||
|
||||
#向数据库display表中插入数据
|
||||
@dbus.service.method(UPDATER_DBUS_INTERFACE, in_signature='ss', out_signature='is', sender_keyword='sender')
|
||||
def InsertInstallState(self, item, value, sender=None):
|
||||
|
@ -293,19 +283,43 @@ class UpdateManagerDbusController(dbus.service.Object):
|
|||
logging.error("Database insert to display failed,options:%s,value:%s" % (item, value))
|
||||
return self.RETURN_UNKNOWN_CODE,str(e)
|
||||
|
||||
def RollbackSysFinishedNext(self, success, version_name,error_code):
|
||||
self.RollbackSysFinished(success,version_name,error_code,get_error_description_from_enum(error_code))
|
||||
#获取后端现在的状态
|
||||
@dbus.service.method(UPDATER_DBUS_INTERFACE,in_signature='s',out_signature='i',sender_keyword='sender')
|
||||
def GetBackendStatus(self,user_lang,sender=None):
|
||||
try:
|
||||
sender_name = get_proc_from_dbus_name(sender)
|
||||
logging.info(COLORMETHOR_PREFIX+'Method'+COLORLOG_SUFFIX+' GetBackendStatus and user_lang = %s sender_name:%s status:%d...',str(user_lang),sender_name,self.now_working)
|
||||
return self.now_working
|
||||
except Exception as e:
|
||||
logging.error(str(e))
|
||||
return self.now_working
|
||||
|
||||
@dbus.service.signal(UPDATER_DBUS_INTERFACE,signature='bsss')
|
||||
def RollbackSysFinished(self, success, version_name,error_code='',error_desc=''):
|
||||
self.now_working = self.ACTION_DEFUALT_STATUS
|
||||
logging.info(COLORLOG_PREFIX + "Emitting" + COLORLOG_SUFFIX +" RollbackSysFinished success = %r , upgrade_group = %s, error_code = %s , error_desc = %s ",\
|
||||
success,version_name, error_code,error_desc)
|
||||
#更新的dbus
|
||||
@dbus.service.method(UPDATER_DBUS_INTERFACE,out_signature='s',sender_keyword='sender')
|
||||
def CheckPopupOnPoweroffInstalled(self,sender=None):
|
||||
try:
|
||||
sender_name = get_proc_from_dbus_name(sender)
|
||||
|
||||
#重启和注销请求信号
|
||||
@dbus.service.signal(UPDATER_DBUS_INTERFACE,signature='s')
|
||||
def RebootLogoutRequired(self,required_status=''):
|
||||
logging.info(COLORLOG_PREFIX + "Emitting"+ COLORLOG_SUFFIX + " RebootLogoutRequired required_status = %s",required_status)\
|
||||
logging.info(COLORMETHOR_PREFIX+'Method'+COLORLOG_SUFFIX+' ChcekPopupOnPoweroffInstalled sender:%s...',sender_name)
|
||||
return "none"
|
||||
except Exception as e:
|
||||
logging.error(str(e))
|
||||
return "none"
|
||||
|
||||
# 获取系统版本号
|
||||
@dbus.service.method(UPDATER_DBUS_INTERFACE, out_signature='ss',sender_keyword='sender')
|
||||
def GetSystemUpdateVersion(self,sender=None):
|
||||
sender_name = get_proc_from_dbus_name(sender)
|
||||
try:
|
||||
os_version = self.parent.sqlite3_server.ucconfigs.getWithDefault("SYSTEM","os_version",'',True)
|
||||
update_version = self.parent.sqlite3_server.ucconfigs.getWithDefault("SYSTEM","update_version",'',True)
|
||||
except Exception as e:
|
||||
logging.error(str(e))
|
||||
return str(e),''
|
||||
# logging.info(COLORMETHOR_PREFIX+'Method'+COLORLOG_SUFFIX+ \
|
||||
# ' GetSystemUpdateVersion sender:%s os_version:%s release_id:%s', \
|
||||
# sender_name,os_version, update_version)
|
||||
return os_version,update_version
|
||||
|
||||
WRITABLE_PROPERTIES = ()
|
||||
|
||||
|
@ -433,8 +447,8 @@ class UpdateManagerDbusController(dbus.service.Object):
|
|||
"""Helper get the properties of a D-Bus interface."""
|
||||
if iface == UPDATER_DBUS_INTERFACE:
|
||||
return {
|
||||
"CurentOriginRefs": dbus.String(""),
|
||||
"RollbackDeployment":dbus.String(""),
|
||||
"CurentOriginRefs": dbus.String(self.cache.cur_refs),
|
||||
"RollbackDeployment":dbus.Array(self.cache.rollback_deployment, signature='s'),
|
||||
}
|
||||
else:
|
||||
return {}
|
||||
|
|
|
@ -9,7 +9,7 @@ from SystemUpdater.Core.errors import *
|
|||
from SystemUpdater.Core.enums import *
|
||||
from gettext import gettext as _
|
||||
|
||||
RETRY_LIMIT = 3
|
||||
RETRY_LIMIT = 5
|
||||
ORIGIN_REMOTE_NAME = "openkylin"
|
||||
|
||||
class BackendBaseOstree(GObject.GObject):
|
||||
|
@ -28,6 +28,7 @@ class BackendBaseOstree(GObject.GObject):
|
|||
|
||||
def __init__(self,parent,sysroot_path=None,osname=None):
|
||||
GObject.GObject.__init__(self)
|
||||
self._async_progress = None
|
||||
if sysroot_path:
|
||||
sysroot_path = Gio.File.new_for_path(sysroot_path)
|
||||
self.test_mode = True
|
||||
|
@ -46,7 +47,6 @@ class BackendBaseOstree(GObject.GObject):
|
|||
self.merge_deployment = self.sysroot.get_merge_deployment(self.osname)
|
||||
if not self.merge_deployment:
|
||||
pass
|
||||
|
||||
self.origin = self.merge_deployment.get_origin()
|
||||
|
||||
# 异常情况下origin文件origin_remote为空 默认强制openkylin
|
||||
|
@ -56,16 +56,15 @@ class BackendBaseOstree(GObject.GObject):
|
|||
origin_refspec = ORIGIN_REMOTE_NAME+":"+origin_ref
|
||||
self.origin.set_string("origin","refspec",origin_refspec)
|
||||
|
||||
self._async_progress = OSTree.AsyncProgress.new()
|
||||
self._async_progress.connect("changed",self._on_async_progress)
|
||||
|
||||
def run(self,trans):
|
||||
def run(self,trans=None):
|
||||
logging.info("Processing transaction")
|
||||
GLib.idle_add(self._run_transaction_idle,trans)
|
||||
|
||||
def _run_transaction_idle(self,trans):
|
||||
"""Run the transaction"""
|
||||
try:
|
||||
self._async_progress = OSTree.AsyncProgress.new()
|
||||
self._async_progress.connect("changed",self._on_async_progress)
|
||||
self._try_lock()
|
||||
self._run_transaction(self.sysroot,trans)
|
||||
except GLib.Error as error:
|
||||
|
@ -350,4 +349,32 @@ class RollbackBackend(BackendBaseOstree):
|
|||
refspec = new_deployments.get_string("origin","refspec")
|
||||
ret,origin_remote,origin_ref = OSTree.parse_refspec(refspec)
|
||||
|
||||
trans.available_refs = origin_ref
|
||||
trans.available_refs = origin_ref
|
||||
|
||||
class LoadCacheBackend(BackendBaseOstree):
|
||||
def __init__(self,parent,sysroot_path=None,osname=None):
|
||||
"""Initialize a new AptWorker instance."""
|
||||
BackendBaseOstree.__init__(self,parent,sysroot_path,osname)
|
||||
|
||||
def _run_transaction(self, sysroot,trans):
|
||||
trans.cur_refs = self._get_refs()
|
||||
trans.rollback_deployment = self._rollback_deployment(sysroot,self.osname)
|
||||
|
||||
def _get_refs(self):
|
||||
refspec = self.origin.get_string("origin","refspec")
|
||||
ret,origin_remote,origin_ref = OSTree.parse_refspec(refspec)
|
||||
if origin_ref == None:
|
||||
origin_ref = ''
|
||||
return origin_ref
|
||||
|
||||
def _rollback_deployment(self,sysroot,osname):
|
||||
out_pending,out_rollback = sysroot.query_deployments_for(osname)
|
||||
|
||||
if out_rollback:
|
||||
rollback_origin = out_rollback.get_origin()
|
||||
refspec = rollback_origin.get_string("origin","refspec")
|
||||
ret,origin_remote,origin_ref = OSTree.parse_refspec(refspec)
|
||||
|
||||
return [origin_ref]
|
||||
else:
|
||||
return []
|
|
@ -4,6 +4,7 @@ SystemUpdater/backend/__init__.py
|
|||
SystemUpdater/UpdateManager.py
|
||||
SystemUpdater/Core/MyCache.py
|
||||
SystemUpdater/Core/UpdateList.py
|
||||
SystemUpdater/Core/OriginFilter.py
|
||||
SystemUpdater/Core/Database.py
|
||||
SystemUpdater/UpdateManagerDbus.py
|
||||
SystemUpdater/Core/enums.py
|
||||
|
|
Loading…
Reference in New Issue