增加记录查询接口

This commit is contained in:
luoxueyi 2021-09-29 17:06:37 +08:00
parent 27aad204bd
commit 4e377dbecf
2 changed files with 68 additions and 0 deletions

View File

@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
import os
import re
import json
import shutil
import sqlite3
import logging
@ -181,7 +182,63 @@ class Sqlite3Server(object):
# pkg missing from fresh_cache can't be modified
pass
return pkgs_install,pkgs_upgrade,pkgs_remove
#查找数据库
def find_msg_from_datebase(self, action = 'check',table = 'updateinfos', cid = 0):
# 查询table
try:
self.cursor.execute("select sql from sqlite_master")
count_tables = 0
while True:
all_table = self.cursor.fetchone()
if all_table == None:
break
tmpstr = str(all_table)
if ("sqlite_sequence") in tmpstr or '(None,)' in tmpstr:
continue
else:
# logging.info(tmpstr)
count_tables = count_tables + 1
pass
logging.info("%d tables were found.", count_tables)
except Exception as e:
logging.error("Check tables error: %s", str(e))
# 检测历史更新升级
try:
sql = "SELECT COUNT(*) FROM updateinfos "
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))
# 获取第cid次更新
if cid != 0 and cid > 0:
sql = "SELECT * FROM updateinfos where id='"+str(cid-1)+"'"
try:
self.cursor.execute(sql)
update_count = self.cursor.fetchone()
logging.info("\n\n### Update %d =============>\n### date:%s\n### status:%s\n### keyword:%s\n### errorcode:%s", \
update_count[0]+1, \
update_count[2], \
update_count[3], \
update_count[4], \
update_count[5])
updatelists = json.loads(update_count[1])
logging.info("update_lists: ------------------------>")
for i in updatelists:
for key in i:
logging.info("package name:\n[ %s ].\n----- version: %s\n----- description: %s\n----- icon: %s\n----- action: %s\n", \
key, \
i[key]['version'], \
i[key]['description'], \
i[key]['icon'], \
i[key]['action'])
print("\n")
except Exception as e:
logging.error("Get update error: %s", str(e))
def listtojsonstr(lists):
import json
jsonfile = json.dumps(lists)

View File

@ -184,6 +184,17 @@ class UpdateManagerDbusController(dbus.service.Object):
logging.error(False, str(e))
return (False, str(e))
# 操作数据库的接口
@dbus.service.method(INTERFACE, out_signature='b')
def DataBaseOpt(self, action='check',table='', cid=19):
if action == 'check':
try:
self.parent.sqlite3_server.find_msg_from_datebase(action, table, cid)
except Exception as e:
logging.error(str(e))
return False
return True
#更新进度信息 0~100 进度信息 101为非预期的信号
@dbus.service.signal(INTERFACE,signature='is')
def UpdateDetectStatusChanged(self,progress,status):