Merge branch 'backend_dev' of gitlab2.kylin.com:kylin-desktop/update-manager-group/kylin-system-updater into backend_dev
This commit is contained in:
commit
827fcf3cec
|
@ -63,7 +63,6 @@ class UpdateMsgCollector():
|
|||
# 获取本地tid
|
||||
self.sender.GetLocalTid()
|
||||
PackageInfo["tid"] = str(self.sender.localtid)
|
||||
logging.info("Get local tid:(%s).",self.sender.localtid)
|
||||
|
||||
json_PackageInfo = self.convertor.dictConvertJson(PackageInfo)
|
||||
|
||||
|
|
|
@ -164,7 +164,7 @@ class Sqlite3Server(object):
|
|||
UpdateInfos.update({"errorCode":str(error_string+" "+error_desc)})
|
||||
json_file = json.dumps(UpdateInfos.copy())
|
||||
UpdateInfos.clear()
|
||||
self.window_main.collector.UpdateMsg("UpdateInfos", json_file)
|
||||
# self.window_main.collector.UpdateMsg("UpdateInfos", json_file)
|
||||
#安装信息install-infos
|
||||
InstallInfos.update({"packageName":str(pkgname)})
|
||||
if pkgname in self.window_main.update_list.local_upgrade_data.versoin_pkgs['groups_upgrade'].keys():
|
||||
|
@ -175,7 +175,7 @@ class Sqlite3Server(object):
|
|||
InstallInfos.update({"status":status})
|
||||
InstallInfos.update({"errorCode":str(error_string+" "+error_desc)})
|
||||
json_file = json.dumps(InstallInfos.copy())
|
||||
self.window_main.collector.UpdateMsg("InstallInfos", json_file)
|
||||
# self.window_main.collector.UpdateMsg("InstallInfos", json_file)
|
||||
elif pkg_list:
|
||||
# 单包更新 # 获取单包数据插入数据库
|
||||
pkgname = pkg_list.pop(0)
|
||||
|
@ -213,7 +213,7 @@ class Sqlite3Server(object):
|
|||
UpdateInfos.update({"errorCode":str(error_string+" "+error_desc)})
|
||||
json_file = json.dumps(UpdateInfos.copy())
|
||||
UpdateInfos.clear()
|
||||
self.window_main.collector.UpdateMsg("UpdateInfos", json_file)
|
||||
# self.window_main.collector.UpdateMsg("UpdateInfos", json_file)
|
||||
#安装信息install-infos
|
||||
InstallInfos.update({"packageName":str(pkgname)})
|
||||
if pkgname in self.window_main.update_list.local_upgrade_data.versoin_pkgs['single_upgrade'].keys():
|
||||
|
@ -224,7 +224,7 @@ class Sqlite3Server(object):
|
|||
InstallInfos.update({"status":status})
|
||||
InstallInfos.update({"errorCode":str(error_string+" "+error_desc)})
|
||||
json_file = json.dumps(InstallInfos.copy())
|
||||
self.window_main.collector.UpdateMsg("InstallInfos", json_file)
|
||||
# self.window_main.collector.UpdateMsg("InstallInfos", json_file)
|
||||
|
||||
try:
|
||||
self.insert_into_updateinfo(pkgname, pkgversion, pkgdescription, timestr, status, "1", errstr)
|
||||
|
@ -257,7 +257,7 @@ class Sqlite3Server(object):
|
|||
UpdateInfos.update({"errorCode":str(error_string+" "+error_desc)})
|
||||
json_file = json.dumps(UpdateInfos.copy())
|
||||
UpdateInfos.clear()
|
||||
self.window_main.collector.UpdateMsg("UpdateInfos", json_file)
|
||||
# self.window_main.collector.UpdateMsg("UpdateInfos", json_file)
|
||||
#安装信息install-infos
|
||||
InstallInfos.update({"packageName":str(pkg.name)})
|
||||
if pkg.name in self.window_main.update_list.local_upgrade_data.versoin_pkgs['groups_upgrade'].keys():
|
||||
|
@ -268,7 +268,7 @@ class Sqlite3Server(object):
|
|||
InstallInfos.update({"status":status})
|
||||
InstallInfos.update({"errorCode":str(error_string+" "+error_desc)})
|
||||
json_file = json.dumps(InstallInfos.copy())
|
||||
self.window_main.collector.UpdateMsg("InstallInfos", json_file)
|
||||
# self.window_main.collector.UpdateMsg("InstallInfos", json_file)
|
||||
|
||||
try:
|
||||
self.insert_into_updateinfo(str(i), pkgversion, pkgdescription, timestr, status, "1", errstr)
|
||||
|
@ -289,7 +289,7 @@ class Sqlite3Server(object):
|
|||
UpdateInfos.update({"errorCode":str(error_string+" "+error_desc)})
|
||||
json_file = json.dumps(UpdateInfos.copy())
|
||||
UpdateInfos.clear()
|
||||
self.window_main.collector.UpdateMsg("UpdateInfos", json_file)
|
||||
# self.window_main.collector.UpdateMsg("UpdateInfos", json_file)
|
||||
#安装信息install-infos
|
||||
InstallInfos.update({"packageName":str(i)})
|
||||
if i in self.window_main.update_list.local_upgrade_data.versoin_pkgs['groups_upgrade'].keys():
|
||||
|
@ -300,7 +300,7 @@ class Sqlite3Server(object):
|
|||
InstallInfos.update({"status":status})
|
||||
InstallInfos.update({"errorCode":str(error_string+" "+error_desc)})
|
||||
json_file = json.dumps(InstallInfos.copy())
|
||||
self.window_main.collector.UpdateMsg("InstallInfos", json_file)
|
||||
# self.window_main.collector.UpdateMsg("InstallInfos", json_file)
|
||||
try:
|
||||
self.insert_into_updateinfo(str(i), pkgversion, pkgdescription, timestr, status, "1", errstr)
|
||||
group_list = []
|
||||
|
@ -328,7 +328,7 @@ class Sqlite3Server(object):
|
|||
UpdateInfos.update({"errorCode":str(error_string+" "+error_desc)})
|
||||
json_file = json.dumps(UpdateInfos.copy())
|
||||
UpdateInfos.clear()
|
||||
self.window_main.collector.UpdateMsg("UpdateInfos", json_file)
|
||||
# self.window_main.collector.UpdateMsg("UpdateInfos", json_file)
|
||||
#安装信息install-infos
|
||||
InstallInfos.update({"packageName":str(pkg.name)})
|
||||
if pkg.name in self.window_main.update_list.local_upgrade_data.versoin_pkgs['groups_upgrade'].keys():
|
||||
|
@ -339,7 +339,7 @@ class Sqlite3Server(object):
|
|||
InstallInfos.update({"status":status})
|
||||
InstallInfos.update({"errorCode":str(error_string+" "+error_desc)})
|
||||
json_file = json.dumps(InstallInfos.copy())
|
||||
self.window_main.collector.UpdateMsg("InstallInfos", json_file)
|
||||
# self.window_main.collector.UpdateMsg("InstallInfos", json_file)
|
||||
try:
|
||||
self.insert_into_updateinfo(str(i), pkgversion, pkgdescription, timestr, status, "1", errstr)
|
||||
# 数据库文件被删除或者新增字段导致需要重新初始化数据库再写入
|
||||
|
|
|
@ -103,11 +103,11 @@ class UpdateList():
|
|||
|
||||
if not os.path.exists(OUTPUT_CONFIG_PATH):
|
||||
os.makedirs(OUTPUT_CONFIG_PATH)
|
||||
logging.info('making the configuration file is complete...')
|
||||
logging.info('making the ConfigPath(%s) is complete...',OUTPUT_CONFIG_PATH)
|
||||
else:
|
||||
shutil.rmtree(OUTPUT_CONFIG_PATH)
|
||||
os.makedirs(OUTPUT_CONFIG_PATH)
|
||||
logging.info('Emptying the configuration file is complete...')
|
||||
logging.info('Emptying the ConfigPath(%s) is complete...',OUTPUT_CONFIG_PATH)
|
||||
except Exception as e:
|
||||
logging.error(str(e))
|
||||
|
||||
|
@ -276,7 +276,7 @@ class UpdateList():
|
|||
return [],[]
|
||||
|
||||
#输出白名单的配置
|
||||
def _make_white_config(self,cache,upgrade_data):
|
||||
def _make_autoupgrade_config(self,cache,upgrade_data):
|
||||
try:
|
||||
pkgs_install,pkgs_upgrade = self._make_pkgs_list(cache,upgrade_data.upgrade_groups_pkgs,upgrade_data.upgrade_groups,upgrade_data.single_pkgs)
|
||||
|
||||
|
@ -288,7 +288,7 @@ class UpdateList():
|
|||
pkgs_upgrade_str=pkgs_upgrade_str[:-1]
|
||||
|
||||
self.parent.configs.setValue("AutoUpgrade","upgradelist",pkgs_upgrade_str,True)
|
||||
logging.info("Generate Configfile to complete...")
|
||||
logging.info("Generate AutoUpgrade Configfile to Complete and Upgradable Number:%d...",len(pkgs_upgrade + pkgs_install))
|
||||
except Exception as e:
|
||||
logging.error(e)
|
||||
|
||||
|
@ -508,7 +508,7 @@ class UpdateList():
|
|||
#分组的包的JSON
|
||||
self._make_groups_upgrade(cache,group_important_list,[pkg.name for pkg in pkgs_upgrade])
|
||||
|
||||
self._make_white_config(cache,self.local_upgrade_data)
|
||||
self._make_autoupgrade_config(cache,self.local_upgrade_data)
|
||||
#是否存在可升级的组
|
||||
if self.local_upgrade_data.upgrade_groups or self.local_upgrade_data.single_pkgs:
|
||||
return True,header,desc
|
||||
|
|
|
@ -3,7 +3,9 @@
|
|||
import os
|
||||
import subprocess
|
||||
from apt import Cache
|
||||
import apt_pkg
|
||||
import sys
|
||||
import time
|
||||
import shutil
|
||||
import dbus
|
||||
import logging
|
||||
|
@ -20,10 +22,8 @@ from .Core.Database import Sqlite3Server
|
|||
from .Core.loop import mainloop
|
||||
from .Core.DataAcquisition import UpdateMsgCollector
|
||||
|
||||
import time
|
||||
from gettext import gettext as _
|
||||
from SystemUpdater.backend import DownloadBackend as downb
|
||||
import apt_pkg
|
||||
from SystemUpdater.Core.UpdaterConfigParser import UpgradeConfig
|
||||
from SystemUpdater.Core.utils import get_broken_details,get_lis_from_cache
|
||||
from SystemUpdater.Core.DpkgInstallProgress import LogInstallProgress
|
||||
|
@ -32,6 +32,8 @@ class UpdateManager():
|
|||
SELF_PKG_NAME = 'kylin-system-updater'
|
||||
GROUPS_PKG_NAME = 'kylin-update-desktop-config'
|
||||
INSTALL_ALONE_PROGRESS = "alone"
|
||||
SOURCE_PARTS_PATH = "/etc/apt/"
|
||||
SOURCE_FILE_NAME = "sources.list"
|
||||
|
||||
def __init__(self,options):
|
||||
self.options = options
|
||||
|
@ -56,6 +58,9 @@ class UpdateManager():
|
|||
#数据采集器
|
||||
self.collector = UpdateMsgCollector(self)
|
||||
|
||||
#后台aptdaemon的语言环境
|
||||
self.aptdaemonLang = os.environ["LANGUAGE"]
|
||||
|
||||
|
||||
#检查是否需要重新启动aptdeamon 目前需要重启的有限速功能
|
||||
def restart_aptdeamon(self):
|
||||
|
@ -115,6 +120,28 @@ class UpdateManager():
|
|||
except Exception as e:
|
||||
logging.error(str(e))
|
||||
|
||||
#读取source.list 内容
|
||||
def _read_source_list(self):
|
||||
try:
|
||||
source_file_content = ''
|
||||
source_file_path = os.path.join(self.SOURCE_PARTS_PATH,self.SOURCE_FILE_NAME)
|
||||
with open(source_file_path) as source_file:
|
||||
source_file_content = source_file.read()
|
||||
return source_file_content
|
||||
except Exception as e:
|
||||
logging.error(str(e))
|
||||
return ''
|
||||
|
||||
#判断是否为光盘源
|
||||
def _is_disc_source(self):
|
||||
logging.info("Check: Whether to use CD-ROM source updates Successfully...")
|
||||
source_file_content = self._read_source_list()
|
||||
if "deb file:" in source_file_content:
|
||||
logging.info("Current use of CD-ROM source without network check...")
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
#进行更新的操作
|
||||
def start_update(self):
|
||||
_success = True
|
||||
|
@ -125,12 +152,23 @@ class UpdateManager():
|
|||
#每次更新之前 重新读取配置文件 刷新参数
|
||||
self.configs.reReadConfigFiles()
|
||||
|
||||
#进行检查网络
|
||||
self.dbusController.UpdateDetectStatusChanged(5,_("Checking network connection"))
|
||||
_success,header,desc = self.dbusController.check_connectivity()
|
||||
if _success == False:
|
||||
self.dbusController.DistUpdateDetectFinished(_success,[],header,desc)
|
||||
return
|
||||
#光盘源的话
|
||||
if self._is_disc_source() == True:
|
||||
logging.info("Turn off NetworkCheck and CloseFiter and UpdateSource...")
|
||||
#关闭网络检查
|
||||
self.options.no_check_network = True
|
||||
#当判断为光盘源时 关闭源过滤
|
||||
self.options.close_filter = True
|
||||
#关闭 更新源模板
|
||||
self.options.no_update_source = True
|
||||
|
||||
if self.options.no_check_network is False:
|
||||
#进行检查网络
|
||||
self.dbusController.UpdateDetectStatusChanged(5,_("Checking network connection"))
|
||||
_success,header,desc = self.dbusController.check_connectivity()
|
||||
if _success == False:
|
||||
self.dbusController.DistUpdateDetectFinished(_success,[],header,desc)
|
||||
return
|
||||
|
||||
#从服务器端更新摸板
|
||||
if self.options.no_update_source is False:
|
||||
|
@ -431,9 +469,7 @@ class UpdateManager():
|
|||
def _setup_dbus(self):
|
||||
# check if there is another g-a-i already and if not setup one
|
||||
# listening on dbus
|
||||
|
||||
bus = dbus.SystemBus()
|
||||
|
||||
try:
|
||||
bus_name = dbus.service.BusName(UPDATER_DBUS_SERVICE,
|
||||
bus,
|
||||
|
@ -445,15 +481,32 @@ class UpdateManager():
|
|||
logging.critical("Another daemon is already running")
|
||||
sys.exit(1)
|
||||
logging.warning("Replacing already running daemon")
|
||||
|
||||
retry_reboot_times = 0
|
||||
the_other_guy = bus.get_object(UPDATER_DBUS_SERVICE,
|
||||
UPDATER_DBUS_PATH)
|
||||
the_other_guy.Quit(dbus_interface=UPDATER_DBUS_INTERFACE,
|
||||
timeout=300)
|
||||
time.sleep(1)
|
||||
bus_name = dbus.service.BusName(UPDATER_DBUS_SERVICE,
|
||||
bus,
|
||||
do_not_queue=True)
|
||||
return UpdateManagerDbusController(self, bus_name)
|
||||
while True:
|
||||
retry_reboot_times = retry_reboot_times + 1
|
||||
#当重试次数超过5次时退出程序
|
||||
if retry_reboot_times > 5:
|
||||
logging.critical("Reboot backend is Failed...")
|
||||
sys.exit(1)
|
||||
try:
|
||||
bus_name = dbus.service.BusName(UPDATER_DBUS_SERVICE,
|
||||
bus,
|
||||
do_not_queue=True)
|
||||
logging.warning("Replacing already running daemon to Success...")
|
||||
return UpdateManagerDbusController(self, bus_name)
|
||||
except dbus.exceptions.NameExistsException:
|
||||
the_other_guy = bus.get_object(UPDATER_DBUS_SERVICE,
|
||||
UPDATER_DBUS_PATH)
|
||||
the_other_guy.Quit(dbus_interface=UPDATER_DBUS_INTERFACE,
|
||||
timeout=300)
|
||||
logging.error("Dbus has not withdrawn and retry reboot times:%d...",retry_reboot_times)
|
||||
time.sleep(1)
|
||||
|
||||
# 是否查找本地依赖
|
||||
def _attempt_depends(self,deb_cache, deb_path,_check_local_dep,_auto_satisfy, _install):
|
||||
|
|
|
@ -9,9 +9,8 @@ from gettext import gettext as _
|
|||
from .backend import InstallBackend
|
||||
from .Core.loop import mainloop
|
||||
from .Core.utils import humanize_size
|
||||
from SystemUpdater.Core.utils import (
|
||||
unLockedEnableShutdown,
|
||||
)
|
||||
from SystemUpdater.Core.utils import unLockedEnableShutdown
|
||||
import locale
|
||||
|
||||
UPDATER_DBUS_INTERFACE = 'com.kylin.systemupgrade.interface'
|
||||
UPDATER_DBUS_PATH = '/com/kylin/systemupgrade'
|
||||
|
@ -42,8 +41,6 @@ COLORMETHOR_PREFIX = FRONT_COLOR_SEQ % CYAN
|
|||
class UpdateManagerDbusController(dbus.service.Object):
|
||||
""" this is a helper to provide the UpdateManagerIFace """
|
||||
|
||||
UPDATER_DBUS_INTERFACE = 'com.kylin.systemupgrade.interface'
|
||||
|
||||
def __init__(self, parent, bus_name,
|
||||
object_path=UPDATER_DBUS_PATH):
|
||||
dbus.service.Object.__init__(self, bus_name, object_path)
|
||||
|
@ -149,17 +146,13 @@ class UpdateManagerDbusController(dbus.service.Object):
|
|||
@dbus.service.method(UPDATER_DBUS_INTERFACE,in_signature='s',out_signature='i')
|
||||
def GetBackendStatus(self,user_lang):
|
||||
try:
|
||||
# if user_lang not in os.environ["LANG"]:
|
||||
# 如果系统不是中文也不是英文 就默认中文
|
||||
# if user_lang != "en" and user_lang != "zh_CN:en":
|
||||
# logging.error("%s",user_lang)
|
||||
# user_lang = "zh_CN:en"
|
||||
|
||||
# logging.warning("The system language is switched %s to %s",os.environ["LANGUAGE"],user_lang)
|
||||
# os.environ["LANGUAGE"] = user_lang
|
||||
|
||||
(lang, encoding) = locale._parse_localename(str(user_lang))
|
||||
#处于更新和升级中的话 不进行更新
|
||||
logging.info(COLORMETHOR_PREFIX+'method'+COLORLOG_SUFFIX+' GetBackendStatus ...')
|
||||
if lang != os.environ["LANGUAGE"]:
|
||||
logging.warning("The system language is switched %s to %s",os.environ["LANGUAGE"],lang)
|
||||
os.environ["LANGUAGE"] = lang
|
||||
|
||||
return self.parent.is_working
|
||||
except Exception:
|
||||
return False
|
||||
|
@ -338,12 +331,12 @@ class UpdateManagerDbusController(dbus.service.Object):
|
|||
@dbus.service.method(UPDATER_DBUS_INTERFACE, in_signature='ss', sender_keyword='sender')
|
||||
def InsertInstallState(self, item, value, sender=None):
|
||||
try:
|
||||
logging.info(COLORMETHOR_PREFIX+'method'+COLORLOG_SUFFIX+' InsertInstallState, options:%s,value:%s' % (item, value))
|
||||
logging.info(COLORMETHOR_PREFIX+'method'+COLORLOG_SUFFIX+' InsertInstallState, options:%s,value:%s' % (item, value))
|
||||
self.parent.sqlite3_server.insert_into_display(item, value)
|
||||
logging.info("Database inserted successfully,options:%s,value:%s" % (item, value))
|
||||
logging.info("Database inserted successfully,options:%s,value:%s" % (item, value))
|
||||
return True
|
||||
except Exception as e:
|
||||
logging.error("Database insert failed,options:%s,value:%s" % (item, value))
|
||||
logging.error("Database insert failed,options:%s,value:%s" % (item, value))
|
||||
return False
|
||||
|
||||
# # download certain package and its dependencies
|
||||
|
|
|
@ -1,5 +1,16 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import aptdaemon.client as client
|
||||
import aptdaemon.errors as errors
|
||||
import aptdaemon.enums as enums
|
||||
from aptdaemon.enums import (
|
||||
EXIT_SUCCESS,
|
||||
EXIT_FAILED,
|
||||
EXIT_CANCELLED,
|
||||
get_error_description_from_enum,
|
||||
get_error_string_from_enum,
|
||||
get_status_string_from_enum
|
||||
)
|
||||
from defer import inline_callbacks
|
||||
from SystemUpdater.backend import InstallBackend
|
||||
import logging
|
||||
|
@ -7,6 +18,8 @@ from gettext import gettext as _
|
|||
from SystemUpdater.Core.utils import humanize_size
|
||||
import dbus,time
|
||||
from gi.repository import GLib
|
||||
import os
|
||||
from importlib import reload
|
||||
|
||||
# 超时检测 秒单位
|
||||
UPDATER_IDLE_CHECK_INTERVAL = 10
|
||||
|
@ -22,23 +35,13 @@ class InstallBackendAptdaemon(InstallBackend):
|
|||
def __init__(self, window_main, action):
|
||||
InstallBackend.__init__(self, window_main, action)
|
||||
self.window_main = window_main
|
||||
|
||||
from aptdaemon import client
|
||||
from aptdaemon import errors
|
||||
from aptdaemon.enums import (EXIT_SUCCESS,
|
||||
EXIT_FAILED,
|
||||
EXIT_CANCELLED,
|
||||
get_error_description_from_enum,
|
||||
get_error_string_from_enum,
|
||||
get_status_string_from_enum
|
||||
)
|
||||
self.errors = errors
|
||||
self.EXIT_SUCCESS = EXIT_SUCCESS
|
||||
self.EXIT_FAILED = EXIT_FAILED
|
||||
self.EXIT_CANCELLED = EXIT_CANCELLED
|
||||
self.get_error_description_from_enum = get_error_description_from_enum
|
||||
self.get_error_string_from_enum = get_error_string_from_enum
|
||||
self.get_status_string_from_enum = get_status_string_from_enum
|
||||
#切换aptdaemon的语言 重新导入模块就可以进行切换
|
||||
if os.environ["LANGUAGE"] != self.window_main.aptdaemonLang:
|
||||
logging.warning("Aptdeamon language is switched %s to %s",self.window_main.aptdaemonLang,os.environ["LANGUAGE"])
|
||||
self.window_main.aptdaemonLang = os.environ["LANGUAGE"]
|
||||
reload(client)
|
||||
reload(errors)
|
||||
reload(enums)
|
||||
|
||||
#客户端连接aptdeamon的dbus接口
|
||||
self.client = client.AptClient()
|
||||
|
@ -116,7 +119,7 @@ class InstallBackendAptdaemon(InstallBackend):
|
|||
# 注册回调函数 接收更新的状态
|
||||
yield self._show_transaction(trans, self.ACTION_UPDATE,
|
||||
_("Checking for updates…"), False)
|
||||
except self.errors.NotAuthorizedError:
|
||||
except errors.NotAuthorizedError:
|
||||
self._action_done(self.ACTION_UPDATE,
|
||||
authorized=False, success=False,
|
||||
error_string='', error_desc='')
|
||||
|
@ -138,11 +141,11 @@ class InstallBackendAptdaemon(InstallBackend):
|
|||
|
||||
yield self._show_transaction(trans, self.ACTION_INSTALL,
|
||||
_("Installing updates…"), True)
|
||||
except self.errors.NotAuthorizedError:
|
||||
except errors.NotAuthorizedError:
|
||||
self._action_done(self.ACTION_INSTALL,
|
||||
authorized=False, success=False,
|
||||
error_string='', error_desc='')
|
||||
except self.errors.TransactionFailed as e:
|
||||
except errors.TransactionFailed as e:
|
||||
self.trans_failed_msg = str(e)
|
||||
except dbus.DBusException as e:
|
||||
if e.get_dbus_name() != "org.freedesktop.DBus.Error.NoReply":
|
||||
|
@ -164,7 +167,7 @@ class InstallBackendAptdaemon(InstallBackend):
|
|||
# 注册回调函数 接收更新的状态
|
||||
yield self._show_transaction(trans, self.ACTION_INSTALL_DEB,
|
||||
_("Installing deb packages…"), False)
|
||||
except self.errors.NotAuthorizedError:
|
||||
except errors.NotAuthorizedError:
|
||||
self._action_done(self.ACTION_INSTALL_DEB,
|
||||
authorized=False, success=False,
|
||||
error_string='', error_desc='')
|
||||
|
@ -184,7 +187,7 @@ class InstallBackendAptdaemon(InstallBackend):
|
|||
# 注册回调函数 接收更新的状态
|
||||
yield self._show_transaction(trans, self.ACTION_FIX_BROKEN,
|
||||
_("Installing deb packages…"), False)
|
||||
except self.errors.NotAuthorizedError:
|
||||
except errors.NotAuthorizedError:
|
||||
self._action_done(self.ACTION_FIX_BROKEN,
|
||||
authorized=False, success=False,
|
||||
error_string='', error_desc='')
|
||||
|
@ -203,7 +206,7 @@ class InstallBackendAptdaemon(InstallBackend):
|
|||
# 注册回调函数 接收更新的状态
|
||||
yield self._show_transaction(trans, self.ACTION_FIX_INCOMPLETE,
|
||||
_("fix incomplete install"), False)
|
||||
except self.errors.NotAuthorizedError:
|
||||
except errors.NotAuthorizedError:
|
||||
self._action_done(self.ACTION_FIX_INCOMPLETE,
|
||||
authorized=False, success=False,
|
||||
error_string='', error_desc='')
|
||||
|
@ -222,7 +225,7 @@ class InstallBackendAptdaemon(InstallBackend):
|
|||
# 注册回调函数 接收更新的状态
|
||||
yield self._show_transaction(trans, self.ACTION_CLEAN,
|
||||
_("Remove all downloaded files."), False)
|
||||
except self.errors.NotAuthorizedError:
|
||||
except errors.NotAuthorizedError:
|
||||
self._action_done(self.ACTION_CLEAN,
|
||||
authorized=False, success=False,
|
||||
error_string='', error_desc='')
|
||||
|
@ -241,7 +244,7 @@ class InstallBackendAptdaemon(InstallBackend):
|
|||
# 注册回调函数 接收更新的状态
|
||||
yield self._show_transaction(trans, self.ACTION_DOWNLOADONLY,
|
||||
_("Downloading deb packages…"), False)
|
||||
except self.errors.NotAuthorizedError:
|
||||
except errors.NotAuthorizedError:
|
||||
self._action_done(self.ACTION_DOWNLOADONLY,
|
||||
authorized=False, success=False,
|
||||
error_string='', error_desc='')
|
||||
|
@ -260,7 +263,7 @@ class InstallBackendAptdaemon(InstallBackend):
|
|||
# 注册回调函数 接收更新的状态
|
||||
yield self._show_transaction(trans, self.ACTION_REMOVE_PACKAGES,
|
||||
_("Installing deb packages…"), False)
|
||||
except self.errors.NotAuthorizedError:
|
||||
except errors.NotAuthorizedError:
|
||||
self._action_done(self.ACTION_REMOVE_PACKAGES,
|
||||
authorized=False, success=False,
|
||||
error_string='', error_desc='')
|
||||
|
@ -290,7 +293,7 @@ class InstallBackendAptdaemon(InstallBackend):
|
|||
#同步状态回调
|
||||
def _on_status_changed(self, trans, status,action):
|
||||
#转化词条
|
||||
self.trans_status = self.get_status_string_from_enum(status)
|
||||
self.trans_status = get_status_string_from_enum(status)
|
||||
self._dist_status_changed(action,self.now_upgrade.upgrade_groups+self.now_upgrade.single_pkgs,\
|
||||
self.trans_progress,self.trans_status,self.details)
|
||||
|
||||
|
@ -360,7 +363,7 @@ class InstallBackendAptdaemon(InstallBackend):
|
|||
|
||||
#增加记录当产生错误的时候 详细信息
|
||||
def _on_error_changed(self, trans,error_code, error_details):
|
||||
# error_string = self.get_error_string_from_enum(error_code)
|
||||
# error_string = get_error_string_from_enum(error_code)
|
||||
self.trans_error_details = str(error_details)
|
||||
logging.error(str(error_details))
|
||||
|
||||
|
@ -377,7 +380,7 @@ class InstallBackendAptdaemon(InstallBackend):
|
|||
trans.connect("progress-details-changed", self._on_progress_download_changed)
|
||||
trans.connect("status-details-changed", self._on_details_changed)
|
||||
trans.connect("error", self._on_error_changed)
|
||||
# yield trans.set_debconf_frontend("ukui")
|
||||
# yield trans.set_locale(os.environ["LANGUAGE"] + ".UTF-8")
|
||||
yield trans.run()
|
||||
|
||||
def _on_finished(self, trans, status, action):
|
||||
|
@ -386,29 +389,29 @@ class InstallBackendAptdaemon(InstallBackend):
|
|||
|
||||
#退出
|
||||
self.on_install_stage = False
|
||||
if status == self.EXIT_FAILED:
|
||||
error_string = self.get_error_string_from_enum(trans.error.code)
|
||||
error_desc = self.get_error_description_from_enum(trans.error.code)
|
||||
if status == EXIT_FAILED:
|
||||
error_string = get_error_string_from_enum(trans.error.code)
|
||||
error_desc = get_error_description_from_enum(trans.error.code)
|
||||
if self.trans_failed_msg:
|
||||
error_desc = error_desc + "\n" + self.trans_failed_msg
|
||||
#取消下载
|
||||
elif status == self.EXIT_CANCELLED:
|
||||
elif status == EXIT_CANCELLED:
|
||||
error_string = _("Failed to fetch")
|
||||
error_desc = _("_Cancel Upgrade")
|
||||
elif status == self.EXIT_SUCCESS and action == self.ACTION_INSTALL:
|
||||
elif status == EXIT_SUCCESS and action == self.ACTION_INSTALL:
|
||||
error_string = _("System upgrade is complete.")
|
||||
elif status == self.EXIT_SUCCESS and action == self.ACTION_REMOVE_PACKAGES:
|
||||
elif status == EXIT_SUCCESS and action == self.ACTION_REMOVE_PACKAGES:
|
||||
error_string = _("Uninstallation completed")
|
||||
|
||||
is_success = (status == self.EXIT_SUCCESS)
|
||||
is_success = (status == EXIT_SUCCESS)
|
||||
try:
|
||||
self._action_done(action,
|
||||
is_cancelled=(status == self.EXIT_CANCELLED), success=is_success,
|
||||
is_cancelled=(status == EXIT_CANCELLED), success=is_success,
|
||||
error_string=error_string, error_desc=error_desc)
|
||||
except TypeError:
|
||||
# this module used to be be lazily imported and in older code
|
||||
# trans_failed= is not accepted
|
||||
# TODO: this workaround can be dropped in Ubuntu 20.10
|
||||
self._action_done(action,
|
||||
is_cancelled=(status == self.EXIT_CANCELLED), success=is_success,
|
||||
is_cancelled=(status == EXIT_CANCELLED), success=is_success,
|
||||
error_string=error_string, error_desc=error_desc)
|
||||
|
|
|
@ -1,76 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- Mode: Python; indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
|
||||
# (c) 2005-2007 Canonical, GPL
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
from gettext import gettext as _
|
||||
import apt
|
||||
import logging
|
||||
import fcntl
|
||||
import apt_pkg
|
||||
from SystemUpdater.backend import InstallBackend
|
||||
|
||||
class InstallBackendDpkg(InstallBackend):
|
||||
pass
|
||||
|
||||
|
||||
# class InstallBackendSynaptic(InstallBackend):
|
||||
# """ Install backend based on synaptic """
|
||||
|
||||
# def update(self):
|
||||
# opt = ["--update-at-startup"]
|
||||
# tempf = None
|
||||
# self._run_synaptic(self.ACTION_UPDATE, opt, tempf)
|
||||
|
||||
# def commit(self, pkgs_install, pkgs_upgrade, pkgs_remove,
|
||||
# close_on_done=False):
|
||||
# # close when update was successful (its ok to use a Synaptic::
|
||||
# # option here, it will not get auto-saved, because synaptic does
|
||||
# # not save options in non-interactive mode)
|
||||
# opt = []
|
||||
# if close_on_done:
|
||||
# opt.append("-o")
|
||||
# opt.append("Synaptic::closeZvt=true")
|
||||
# # custom progress strings
|
||||
# opt.append("--progress-str")
|
||||
# opt.append("%s" % _("Please wait, this can take some time."))
|
||||
# opt.append("--finish-str")
|
||||
# opt.append("%s" % _("Update is complete"))
|
||||
# tempf = tempfile.NamedTemporaryFile(mode="w+")
|
||||
# for pkg_name in pkgs_install + pkgs_upgrade:
|
||||
# tempf.write("%s\tinstall\n" % pkg_name)
|
||||
# for pkg_name in pkgs_remove:
|
||||
# tempf.write("%s\tdeinstall\n" % pkg_name)
|
||||
# opt.append("--set-selections-file")
|
||||
# opt.append("%s" % tempf.name)
|
||||
# tempf.flush()
|
||||
# self._run_synaptic(self.ACTION_INSTALL, opt, tempf)
|
||||
|
||||
# def _run_synaptic(self, action, opt, tempf):
|
||||
# """Execute synaptic."""
|
||||
# win = self.window_main.get_window()
|
||||
# try:
|
||||
# xid = win.get_xid()
|
||||
# except AttributeError:
|
||||
# xid = 0
|
||||
# cmd = ["/usr/bin/pkexec", "/usr/sbin/synaptic", "--hide-main-window",
|
||||
# "--non-interactive", "--parent-window-id",
|
||||
# "%s" % xid]
|
||||
# cmd.extend(opt)
|
||||
# flags = GObject.SPAWN_DO_NOT_REAP_CHILD
|
||||
# (pid, stdin, stdout, stderr) = GObject.spawn_async(cmd, flags=flags)
|
||||
# # Keep a reference to the data tuple passed to
|
||||
# # GObject.child_watch_add to avoid attempts to destroy it without a
|
||||
# # thread context: https://bugs.launchpad.net/bugs/724687
|
||||
# self.child_data = (action, tempf)
|
||||
# GObject.child_watch_add(pid, self._on_synaptic_exit, self.child_data)
|
||||
|
||||
# def _on_synaptic_exit(self, pid, condition, data):
|
||||
# action, tempf = data
|
||||
# if tempf:
|
||||
# tempf.close()
|
||||
# self._action_done(action,
|
||||
# authorized=True,
|
||||
# success=os.WEXITSTATUS(condition) == 0,
|
||||
# error_string=None, error_desc=None)
|
|
@ -42,17 +42,20 @@ if __name__ == "__main__":
|
|||
help=_("Do not check for updates source when updating"))
|
||||
parser.add_option ("--no-update", action="store_true",
|
||||
dest="no_update", default=False,
|
||||
help=_("Do not check for updates when starting"))
|
||||
help="Do not check for updates when starting")
|
||||
parser.add_option("-c", "--close-filter",
|
||||
default=False,
|
||||
action="store_true", dest="close_filter",
|
||||
help=_("Quit and close allowed_origin"))
|
||||
help=_("Quit and close allowed origin"))
|
||||
parser.add_option("--no-check-network",
|
||||
default=False,
|
||||
action="store_true", dest="no_check_network",
|
||||
help=_("Quit and close check network"))
|
||||
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
if os.getuid() != 0:
|
||||
print(_("You need to be root to run this application"))
|
||||
|
||||
sys.exit(1)
|
||||
|
||||
# set debconf to NON_INTERACTIVE
|
||||
|
@ -60,6 +63,16 @@ if __name__ == "__main__":
|
|||
os.environ["TERM"] = "xterm"
|
||||
os.environ["PATH"] = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
||||
|
||||
#当不存在语言变量时 默认显示中文
|
||||
if not "LANGUAGE" in os.environ:
|
||||
os.environ["LANGUAGE"] = "zh_CN"
|
||||
|
||||
#做一些规范处理
|
||||
if os.environ["LANGUAGE"] == "en":
|
||||
os.environ["LANGUAGE"] = "en_US"
|
||||
if os.environ["LANGUAGE"] == "zh_CN:en":
|
||||
os.environ["LANGUAGE"] = "zh_CN"
|
||||
|
||||
# ensure that we are not killed when the terminal goes away e.g. on
|
||||
# shutdown
|
||||
signal.signal(signal.SIGHUP, signal.SIG_IGN)
|
||||
|
@ -69,18 +82,8 @@ if __name__ == "__main__":
|
|||
logging.basicConfig(format=FORMAT,level=logging.DEBUG,datefmt='%m-%d,%H:%M:%S')
|
||||
else:
|
||||
logging.basicConfig(format=FORMAT,level=logging.DEBUG,datefmt='%m-%d,%H:%M:%S',filename = logfile(),filemode = 'a')
|
||||
|
||||
#目前 多用户的语言切换还未做好 不启用
|
||||
# if sys.getfilesystemencoding() == "ascii" and not "LANG" in os.environ:
|
||||
# logging.info('start setting environ["LANG"] ...')
|
||||
# os.environ["LANG"] = "C.UTF-8"
|
||||
# os.execv(sys.argv[0], sys.argv)
|
||||
|
||||
# if not "LANGUAGE" in os.environ:
|
||||
# os.environ["LANGUAGE"] = "zh_CN.UTF-8"
|
||||
|
||||
# logging.info('kylin-system-updater(lang:%s) starting ...',os.environ["LANGUAGE"])
|
||||
logging.info('kylin-system-updater starting ...')
|
||||
logging.info('kylin-system-updater(lang:%s) starting ...',os.environ["LANGUAGE"])
|
||||
|
||||
app = UpdateManager(options)
|
||||
|
||||
|
|
Loading…
Reference in New Issue