From 4d53dff8d6bf4028fdb8208561f67948e91df243 Mon Sep 17 00:00:00 2001 From: wangsong Date: Fri, 21 Oct 2022 10:39:49 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=BD=93=E6=89=80=E6=9C=89=E7=9A=84?= =?UTF-8?q?=E8=BD=AF=E4=BB=B6=E5=8C=85=E9=83=BD=E8=A2=AB=E5=8D=87=E7=BA=A7?= =?UTF-8?q?=E6=97=B6=20=E4=B9=9F=E8=A2=AB=E6=A0=87=E8=AE=B0=E4=B8=BA?= =?UTF-8?q?=E5=8D=87=E7=BA=A7=E6=88=90=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/SystemUpdater/backend/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/SystemUpdater/backend/__init__.py b/backend/SystemUpdater/backend/__init__.py index 0396c4b..985c940 100644 --- a/backend/SystemUpdater/backend/__init__.py +++ b/backend/SystemUpdater/backend/__init__.py @@ -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)) From 9443ecc2b1704acaffe5460dc18cca0be6742d2a Mon Sep 17 00:00:00 2001 From: wangsong Date: Fri, 21 Oct 2022 11:24:48 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BE=9D=E8=B5=96?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E7=BC=BA=E5=B0=91=E4=BE=9D=E8=B5=96=E7=9A=84?= =?UTF-8?q?=E5=87=86=E7=A1=AE=E6=80=A7=E4=BB=A5=E5=8F=8A=E6=8E=92=E9=99=A4?= =?UTF-8?q?=E8=AF=AF=E6=8A=A5=E7=BC=BA=E5=B0=91=E4=BE=9D=E8=B5=96=E7=9A=84?= =?UTF-8?q?=E7=8A=B6=E5=86=B5=EF=BC=8C=E5=A2=9E=E5=8A=A0=E8=BF=87=E6=BB=A4?= =?UTF-8?q?=E5=9C=A8=E8=AE=A1=E7=AE=97=E4=BE=9D=E8=B5=96=E4=BA=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/SystemUpdater/backend/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/SystemUpdater/backend/__init__.py b/backend/SystemUpdater/backend/__init__.py index 985c940..f8ddff6 100644 --- a/backend/SystemUpdater/backend/__init__.py +++ b/backend/SystemUpdater/backend/__init__.py @@ -559,8 +559,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: From 1be7115e28cf970f4642231dea4552b3f9a6ca23 Mon Sep 17 00:00:00 2001 From: luoxueyi Date: Fri, 21 Oct 2022 11:26:48 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/SystemUpdater/Core/DataAcquisition.py | 9 +- backend/SystemUpdater/Core/Database.py | 92 +++++++++++++------ backend/SystemUpdater/backend/__init__.py | 3 +- 3 files changed, 66 insertions(+), 38 deletions(-) diff --git a/backend/SystemUpdater/Core/DataAcquisition.py b/backend/SystemUpdater/Core/DataAcquisition.py index 2c15f98..33b0d20 100644 --- a/backend/SystemUpdater/Core/DataAcquisition.py +++ b/backend/SystemUpdater/Core/DataAcquisition.py @@ -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: diff --git a/backend/SystemUpdater/Core/Database.py b/backend/SystemUpdater/Core/Database.py index 80f2c75..9564c7d 100644 --- a/backend/SystemUpdater/Core/Database.py +++ b/backend/SystemUpdater/Core/Database.py @@ -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...")) # 接收更新列表与信息,生成数据并插入数据库中 @@ -425,19 +455,20 @@ class Sqlite3Server(object): pass return pkgs_install,pkgs_upgrade,pkgs_remove - #查找数据库 - 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 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 +479,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 +578,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: diff --git a/backend/SystemUpdater/backend/__init__.py b/backend/SystemUpdater/backend/__init__.py index 06b1de0..80197dc 100644 --- a/backend/SystemUpdater/backend/__init__.py +++ b/backend/SystemUpdater/backend/__init__.py @@ -362,6 +362,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)) @@ -850,7 +851,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)) From 5097059cc156e21183762fad26a73fb6ac1ed4b2 Mon Sep 17 00:00:00 2001 From: luoxueyi Date: Fri, 21 Oct 2022 11:43:42 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E6=A0=87=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/SystemUpdater/Core/Database.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/backend/SystemUpdater/Core/Database.py b/backend/SystemUpdater/Core/Database.py index 9564c7d..321b904 100644 --- a/backend/SystemUpdater/Core/Database.py +++ b/backend/SystemUpdater/Core/Database.py @@ -249,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) @@ -401,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, " ") @@ -409,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.") @@ -455,6 +461,18 @@ class Sqlite3Server(object): pass return pkgs_install,pkgs_upgrade,pkgs_remove + def _removal_of_marker(self): + try: + 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("Removing the upgrade success mark error: %s.",str(e)) + # #查找数据库 # def find_msg_from_datebase(self, table, field, action = 'check', cid = 0): # # 查询数据