Merge branch 'backend_manual' into 'backend_uu'
Backend manual See merge request kylinos-src/update-manager-group/kylin-system-updater!511
This commit is contained in:
commit
41df9b2a46
|
@ -310,7 +310,7 @@ class MessageSend():
|
|||
except AttributeError:
|
||||
logging.error("Call UploadMessage: Attribute Error.")
|
||||
self.Send_finally(retval, retid, PackageInfo, UploadMessage, encodeMsg)
|
||||
|
||||
|
||||
def Send_finally(self, retval, retid, json_PackageInfo, json_UploadMessage, encodeMsg):
|
||||
# 根据发送结果进行处理
|
||||
result = ''
|
||||
|
@ -349,13 +349,6 @@ class MessageSend():
|
|||
def GetLocalTid(self, key):
|
||||
# 试图获取本地tid
|
||||
try:
|
||||
# if os.path.exists(LOCALTIDDIR+LOCALTIDFILE):
|
||||
# with open(LOCALTIDDIR+LOCALTIDFILE, "r") as f:
|
||||
# self.localtid = f.readline()
|
||||
# # print(self.localtid)
|
||||
# else:
|
||||
# self.localtid = ""
|
||||
|
||||
# 存放至数据库
|
||||
tid = self.collector.updateManager.sqlite3_server.select_from_tid("tid",key)
|
||||
if tid == "None" or tid == None:
|
||||
|
|
|
@ -17,41 +17,53 @@ from SystemUpdater.Core.utils import get_config_patch
|
|||
|
||||
import apt_pkg
|
||||
from ..backend import InstallBackend
|
||||
|
||||
DB_FILE = os.path.join("/var/cache/kylin-system-updater/kylin-system-updater.db")
|
||||
UMDB_FILE = os.path.join("/var/cache/kylin-system-updater/kylin-system-updater.db")
|
||||
# UMDB_FILE = os.path.join("/var/cache/kylin-system-updater/kylin-system-updater.db")
|
||||
INSTALLED_LIST = [{"item": "errorcode", "type": "int", "default": "0"}]
|
||||
DISPALY_LIST = []
|
||||
|
||||
class Sqlite3Server(object):
|
||||
def __init__(self, window_main):
|
||||
def __init__(self, updateManager):
|
||||
self.connect = None
|
||||
self.window_main = window_main
|
||||
self.window_main = updateManager
|
||||
self.config_path = get_config_patch()
|
||||
logging.info(_("Init Sqlite3Server..."))
|
||||
self.init_sqlit()
|
||||
|
||||
# uncoverable配置文件
|
||||
self.ucconfigs = UpgradeConfig(datadir = "/etc/kylin-version", name = "kylin-system-version.conf")
|
||||
self._system_version_config()
|
||||
|
||||
|
||||
# 初始化连接数据库
|
||||
# 初始化连接数据库,修改为使用时连接
|
||||
def init_sqlit(self):
|
||||
try:
|
||||
logging.info(_("Initialize the connection to the database ..."))
|
||||
if os.path.isfile(DB_FILE):
|
||||
self.connect = sqlite3.connect(DB_FILE, check_same_thread=False)
|
||||
self.cursor = self.connect.cursor()
|
||||
self.insert_new_field()
|
||||
else:
|
||||
logging.info(_("Initialize database files ..."))
|
||||
if not os.path.isfile(DB_FILE):
|
||||
if not os.path.isdir(os.path.dirname(DB_FILE)):
|
||||
os.makedirs(os.path.dirname(DB_FILE))
|
||||
shutil.copy("/usr/share/kylin-system-updater/kylin-system-updater.db", os.path.dirname(DB_FILE))
|
||||
self.connect = sqlite3.connect(DB_FILE, check_same_thread=False)
|
||||
self.cursor = self.connect.cursor()
|
||||
self.insert_new_field()
|
||||
except Exception as e:
|
||||
logging.error(_("Failed to initialize the database: %s"), str(e))
|
||||
logging.error("Failed to initialize database files: %s", str(e))
|
||||
|
||||
#connect连接数据库
|
||||
def connect_database(self):
|
||||
try:
|
||||
logging.debug("Connect database ...")
|
||||
self.connect = sqlite3.connect(DB_FILE, check_same_thread=False)
|
||||
self.cursor = self.connect.cursor()
|
||||
except Exception as e:
|
||||
logging.error("Failed to connect database: %s", str(e))
|
||||
|
||||
#disconnect连接数据库
|
||||
def disconnect_database(self):
|
||||
try:
|
||||
logging.debug("Disconnect database ...")
|
||||
if self.connect != None:
|
||||
self.connect.close()
|
||||
if self.connect != None:
|
||||
del self.cursor
|
||||
except Exception as e:
|
||||
logging.error("Failed to disconnect database: %s", str(e))
|
||||
|
||||
# 数据库表格中动态增加新的字段用于扩展
|
||||
def insert_new_field(self):
|
||||
|
@ -99,33 +111,42 @@ class Sqlite3Server(object):
|
|||
|
||||
# 写入数据到installed表中
|
||||
def insert_into_installed(self, *args, **kwargs):
|
||||
self.connect_database()
|
||||
self.cursor.execute(
|
||||
"insert into installed (appname, version, time, description, icon, statue, keyword, errorcode) values(?,"
|
||||
"?,?,?,?,?,?,?)",
|
||||
(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]))
|
||||
self.connect.commit()
|
||||
self.disconnect_database()
|
||||
|
||||
# 写入数据到display表中
|
||||
def insert_into_display(self, *args, **kwargs):
|
||||
self.connect_database()
|
||||
try:
|
||||
sql = "update display set " + args[0] + "='" + args[1] + "' where id = 1"
|
||||
self.cursor.execute(sql)
|
||||
self.connect.commit()
|
||||
except Exception as e:
|
||||
logging.error("Insert error: %s.", str(e))
|
||||
self.disconnect_database()
|
||||
return False
|
||||
logging.info("Database: Insert (%s=%s) To display Complete ...", args[0], args[1])
|
||||
self.disconnect_database()
|
||||
return True
|
||||
|
||||
# 写入数据到tid_search表中
|
||||
def insert_into_tid(self, *args, **kwargs):
|
||||
self.connect_database()
|
||||
self.cursor.execute(
|
||||
"insert into tid_search (key, tid) values(?,?)",
|
||||
(args[0], args[1]))
|
||||
self.connect.commit()
|
||||
self.disconnect_database()
|
||||
|
||||
# 搜索tid_search表,获取tid值
|
||||
def select_from_tid(self, *args, **kwargs):
|
||||
retval = ''
|
||||
self.connect_database()
|
||||
try:
|
||||
sql = "select "+args[0]+" from tid_search where key='"+args[1]+"'"
|
||||
self.cursor.execute(sql)
|
||||
|
@ -133,33 +154,42 @@ class Sqlite3Server(object):
|
|||
if len(rets)!= 0:
|
||||
if len(rets[0])!=0:
|
||||
ret_first = rets[0]
|
||||
return str(ret_first[0])
|
||||
retval = str(ret_first[0])
|
||||
except Exception as e:
|
||||
logging.error("Insert error: %s.", str(e))
|
||||
self.disconnect_database()
|
||||
logging.info(_("Database: Select data Complete..."))
|
||||
return ""
|
||||
self.disconnect_database()
|
||||
return retval
|
||||
|
||||
# 读出display表中数据
|
||||
def select_from_display(self, *args, **kwargs):
|
||||
try:
|
||||
self.connect_database()
|
||||
sql = "select "+args[0]+" from display"
|
||||
self.cursor.execute(sql)
|
||||
self.connect.commit()
|
||||
return str(self.cursor.fetchone()[0])
|
||||
retval = str(self.cursor.fetchone()[0])
|
||||
self.disconnect_database()
|
||||
return retval
|
||||
except Exception as e:
|
||||
logging.error("select error: %s.", str(e))
|
||||
self.disconnect_database()
|
||||
return "Error"
|
||||
|
||||
# 写入updateinfos表中
|
||||
def insert_into_updateinfo(self, *args, **kwargs):
|
||||
try:
|
||||
self.connect_database()
|
||||
self.cursor.execute(
|
||||
"insert into updateinfos (appname, version, description, date, status, keyword, errorcode, appname_cn, status_cn, changelog) values(?,"
|
||||
"?,?,?,?,?,?,?,?,?)",
|
||||
(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9]))
|
||||
self.connect.commit()
|
||||
self.disconnect_database()
|
||||
except Exception as e:
|
||||
logging.error("Insert error: %s.", str(e))
|
||||
self.disconnect_database()
|
||||
logging.info(_("Database: Insert To Complete..."))
|
||||
|
||||
# 接收更新列表与信息,生成数据并插入数据库中
|
||||
|
@ -219,6 +249,8 @@ class Sqlite3Server(object):
|
|||
pkgversion = str(pkgversion).split('=')[-1]
|
||||
logging.info("Complete system upgrade, refresh system version ...")
|
||||
self._refresh_system_version(pkgversion)
|
||||
#移除step-two标记
|
||||
self._removal_of_marker()
|
||||
|
||||
#FIXME: 临时方案 PHP
|
||||
PHPSeverSend(_appname=pkgname, _appversion=pkgversion, _statue=status, _errorcode="10000100", _errorstring=errstr)
|
||||
|
@ -371,6 +403,8 @@ class Sqlite3Server(object):
|
|||
pkgversion = str(pkgversion).split('=')[-1]
|
||||
logging.info("Complete system upgrade, refresh system version ...")
|
||||
self._refresh_system_version(str(pkgversion))
|
||||
#移除step-two标记
|
||||
self._removal_of_marker()
|
||||
|
||||
elif mode == InstallBackend.MODE_INSTALL_SYSTEM: # 全盘升级
|
||||
self.insert_into_updateinfo(_("Upgrade System"), "", "This is a complete system upgrade, equivalent to the implementation of apt dist-upgrade", timestr, status, "1", errstr, str("全盘升级"), status_cn, " ")
|
||||
|
@ -379,6 +413,8 @@ class Sqlite3Server(object):
|
|||
if status == "success":
|
||||
# 更新版本号
|
||||
self._refresh_system_version(pseudo_version=True)
|
||||
#移除step-two标记
|
||||
self._removal_of_marker()
|
||||
else:
|
||||
logging.warning("Cache is None.")
|
||||
|
||||
|
@ -425,19 +461,32 @@ class Sqlite3Server(object):
|
|||
pass
|
||||
return pkgs_install,pkgs_upgrade,pkgs_remove
|
||||
|
||||
#查找数据库
|
||||
def find_msg_from_datebase(self, table, field, action = 'check', cid = 0):
|
||||
# 查询数据
|
||||
def _removal_of_marker(self):
|
||||
try:
|
||||
sql = "select "+field+" from "+table
|
||||
self.cursor.execute(sql)
|
||||
update_count = self.cursor.fetchone()[0]
|
||||
logging.info("%d history updates detected.", update_count)
|
||||
marker_path = "/var/cache/kylin-update-manager/ignoreOrDelay"
|
||||
if os.path.exists(marker_path):
|
||||
with open(marker_path, 'r+') as f:
|
||||
line= f.readline()
|
||||
if "2107" in line or "2203" in line:
|
||||
f.seek(0)
|
||||
f.truncate()
|
||||
except Exception as e:
|
||||
logging.error("Check update error: %s", str(e))
|
||||
logging.error("Removing the upgrade success mark error: %s.",str(e))
|
||||
|
||||
# #查找数据库
|
||||
# def find_msg_from_datebase(self, table, field, action = 'check', cid = 0):
|
||||
# # 查询数据
|
||||
# try:
|
||||
# sql = "select "+field+" from "+table
|
||||
# self.cursor.execute(sql)
|
||||
# update_count = self.cursor.fetchone()[0]
|
||||
# logging.info("%d history updates detected.", update_count)
|
||||
# except Exception as e:
|
||||
# logging.error("Check update error: %s", str(e))
|
||||
|
||||
def _system_version_config(self):
|
||||
try:
|
||||
self.connect_database()
|
||||
sql = "select init_version from display where id=1"
|
||||
self.cursor.execute(sql)
|
||||
_is_init_verison = self.cursor.fetchone()[0]
|
||||
|
@ -448,8 +497,10 @@ class Sqlite3Server(object):
|
|||
sql = "update display set init_version = 'no'"
|
||||
self.cursor.execute(sql)
|
||||
self.connect.commit()
|
||||
self.disconnect_database()
|
||||
except Exception as e:
|
||||
logging.error(str(e))
|
||||
self.disconnect_database()
|
||||
|
||||
def _refresh_system_version(self, update_version='', os_version = '', pseudo_version = False):
|
||||
try:
|
||||
|
@ -545,6 +596,7 @@ class Sqlite3Server(object):
|
|||
cursor.execute(sql)
|
||||
connect.commit()
|
||||
retval = cursor.fetchone()
|
||||
connect.close()
|
||||
if retval != None and len(retval) != 0:
|
||||
return str(retval[0])
|
||||
else:
|
||||
|
|
|
@ -206,7 +206,8 @@ class InstallBackend():
|
|||
|
||||
#检查是否存在可升级的包
|
||||
if len(pkgs_install) == 0 and len(pkgs_upgrade) == 0 and len(pkgs_remove) == 0 and len(pkgs_downgrade) == 0:
|
||||
raise UpdateBaseError(ERROR_NOT_UPGRADE_PACKAGES)
|
||||
pkgs_install,pkgs_upgrade = self._make_pkgs_list(self.cache,self.upgrade_data.groups_pkgs,self.now_upgrade.upgrade_groups,self.now_upgrade.single_pkgs)
|
||||
logging.warning("There is an exception in the update package install = %r upgrade = %r",pkgs_install,pkgs_upgrade)
|
||||
|
||||
# if self.action_mode == self.MODE_INSTALL_SINGLE:
|
||||
# logging.warning("MODE_INSTALL_SINGLE install:%s , upgrade:%s remove:%s",str(pkgs_install),str(pkgs_upgrade),str(pkgs_remove))
|
||||
|
@ -362,6 +363,7 @@ class InstallBackend():
|
|||
# 没找到包或格式不正确
|
||||
self.window_main.dbusController.UpdateInstallFinished(False, pkgs_install, "'"+pkg_name+"' is not in cache", "")
|
||||
return
|
||||
self._start_install_lock(caller=caller)
|
||||
self.commit(self.ACTION_INSTALL,pkgs_install,[],[])
|
||||
except Exception as e:
|
||||
logging.error(str(e))
|
||||
|
@ -558,8 +560,11 @@ class InstallBackend():
|
|||
continue
|
||||
|
||||
for pkg in pkgs_upgrade + pkgs_install:
|
||||
|
||||
pkg_cache = cache[pkg]
|
||||
if pkg_cache.is_upgradable == False and pkg_cache.is_installed == True:
|
||||
logging.warning("pkg(%s) not upgrade or install and will be continue...",pkg)
|
||||
continue
|
||||
|
||||
pkg_cache.mark_install(False, True, True)
|
||||
|
||||
if pkg_cache.is_upgradable == True:
|
||||
|
@ -852,7 +857,7 @@ class InstallBackend():
|
|||
# self.window_main.collector.Upgrade_Process_Msg(self.action, UpdateMsg.copy())
|
||||
|
||||
self.window_main.dbusController.UpdateInstallFinished(success,self.now_upgrade.upgrade_content,error_string,error_desc)
|
||||
|
||||
|
||||
|
||||
def _start_install_lock(self, caller='Kylin System Updater'):
|
||||
self.window_main.configs_uncover.setValue("SystemStatus","abnormal_reboot",str(True))
|
||||
|
|
Loading…
Reference in New Issue