添加单独下载的接口
This commit is contained in:
parent
f2192c289a
commit
1a11ccf5df
|
@ -104,11 +104,14 @@ class Sqlite3Server(object):
|
|||
# 写入updateinfo表中
|
||||
def insert_into_updateinfo(self, *args, **kwargs):
|
||||
logging.info(_("Inserting data into the database... "))
|
||||
self.cursor.execute(
|
||||
"insert into updateinfos (update_lists, date, status, keyword, errorcode) values(?,"
|
||||
"?,?,?,?)",
|
||||
(args[0], args[1], args[2], args[3], args[4]))
|
||||
self.connect.commit()
|
||||
try:
|
||||
self.cursor.execute(
|
||||
"insert into updateinfos (update_lists, date, status, keyword, errorcode) values(?,"
|
||||
"?,?,?,?)",
|
||||
(args[0], args[1], args[2], args[3], args[4]))
|
||||
self.connect.commit()
|
||||
except Exception as e:
|
||||
logging.error("Insert error: %s.", str(e))
|
||||
logging.info(_("Data insertion complete ."))
|
||||
|
||||
# 接收更新列表与信息,生成数据并插入数据库中
|
||||
|
|
|
@ -158,7 +158,7 @@ class UpdateListFilterCache(apt.Cache):
|
|||
for pkg in pkgs:
|
||||
for v in pkg.versions:
|
||||
if is_in_allowed_origin(v, self.allowed_origins) and not pkg in new_upgrade_pkgs:
|
||||
new_upgrade_pkgs.append(pkg)
|
||||
new_upgrade_pkgs.append(pkg.name)
|
||||
return new_upgrade_pkgs
|
||||
|
||||
def is_pkgname_in_blacklist(self, pkgs):
|
||||
|
|
|
@ -23,6 +23,7 @@ from .backend import (InstallBackend,
|
|||
get_backend)
|
||||
from .Core.Database import Sqlite3Server
|
||||
from .Core.filter import UpdateListFilterCache
|
||||
from SystemUpdater.backend import DownloadBackend as downb
|
||||
|
||||
|
||||
from gettext import gettext as _
|
||||
|
@ -114,6 +115,14 @@ class UpdateManager():
|
|||
|
||||
return True
|
||||
|
||||
#download only
|
||||
def download_backend(self):
|
||||
try:
|
||||
download_backend = downb.DownloadBackend(self)
|
||||
download_backend.downloadpkgs()
|
||||
except Exception as e:
|
||||
logging.error(str(e))
|
||||
|
||||
#进行更新的操作
|
||||
def start_update(self):
|
||||
try:
|
||||
|
|
|
@ -162,6 +162,8 @@ class UpdateManagerDbusController(dbus.service.Object):
|
|||
pkgs_upgrade.append(pkg.name)
|
||||
elif pkg.marked_delete:
|
||||
pkgs_remove.append(pkg.name)
|
||||
elif pkg.is_upgradable :
|
||||
pkgs_upgrade.append(pkg.name)
|
||||
except Exception as e:
|
||||
logging.error(e)
|
||||
pkgs_upgrade = self.parent.filter.check_in_allowed_origin(pkgs_upgrade)
|
||||
|
@ -195,6 +197,20 @@ class UpdateManagerDbusController(dbus.service.Object):
|
|||
return False
|
||||
return True
|
||||
|
||||
# # download certain package and its dependencies
|
||||
@dbus.service.method(INTERFACE, in_signature='asi', out_signature='b')
|
||||
def DownloadPackages(self, pkgs=[''], try_times=1):
|
||||
logging.info("Download Packages ...")
|
||||
if try_times > 0:
|
||||
pass
|
||||
else:
|
||||
try_times = 1
|
||||
times = try_times
|
||||
while times > 0:
|
||||
self.parent.download_backend()
|
||||
times -= 1
|
||||
return True
|
||||
|
||||
#更新进度信息 0~100 进度信息 101为非预期的信号
|
||||
@dbus.service.signal(INTERFACE,signature='is')
|
||||
def UpdateDetectStatusChanged(self,progress,status):
|
||||
|
|
|
@ -0,0 +1,138 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import os
|
||||
import apt
|
||||
import logging
|
||||
import apt_pkg
|
||||
from defer import inline_callbacks
|
||||
from apt.progress.base import AcquireProgress
|
||||
from gettext import gettext as _
|
||||
|
||||
#python-apt download only
|
||||
class FetchProgress(AcquireProgress):
|
||||
def __init__(self, downdeamon) -> None:
|
||||
super().__init__()
|
||||
self.downd = downdeamon
|
||||
self.dbusDeamon = downdeamon.window_main.dbusController
|
||||
self.kargs = {"desc":"", "err_text":"","status":"", "type":""}
|
||||
self.time = 0
|
||||
|
||||
|
||||
def pulse(self, owner):
|
||||
progress = int((self.current_bytes / self.total_bytes) * 100)
|
||||
total_size = self.total_bytes
|
||||
pkgname = ''
|
||||
tmplist = []
|
||||
current_cps =0
|
||||
if owner.workers[0].current_item != None:
|
||||
pkgname=str(owner.workers[0].current_item.shortdesc)
|
||||
for i in owner.items:
|
||||
allpkgs=os.path.basename(i.destfile)
|
||||
allpkgs = allpkgs.split("_")[0]
|
||||
tmplist.append(allpkgs)
|
||||
current_items = tmplist.index(pkgname)
|
||||
else:
|
||||
current_items = 0
|
||||
current_cps = self.calculatcps()
|
||||
|
||||
self.dbusDeamon.UpdateDownloadInfo(\
|
||||
current_items, len(owner.items), \
|
||||
self.current_bytes, owner.total_needed, \
|
||||
current_cps)
|
||||
return
|
||||
|
||||
def stop(self):
|
||||
logging.info("fetch progess finished")
|
||||
finish_status = False
|
||||
if self.current_items == self.total_items:
|
||||
finish_status = True
|
||||
else:
|
||||
finish_status = False
|
||||
error_string = "Download " + self.kargs['desc'] + self.kargs['type']
|
||||
error_desc = self.kargs['err_text']
|
||||
self.dbusDeamon.UpdateDownloadFinished(finish_status, self.downd.pkglists, error_string, error_desc)
|
||||
return
|
||||
|
||||
def fail(self, acquireitemdesc):
|
||||
desc = acquireitemdesc.shortdesc
|
||||
err_text = acquireitemdesc.owner.error_text
|
||||
status = acquireitemdesc.owner.status
|
||||
type = ""
|
||||
if status == apt_pkg.AcquireItem.STAT_AUTH_ERROR:
|
||||
type = "authentication error"
|
||||
elif status == apt_pkg.AcquireItem.STAT_ERROR:
|
||||
type = "fetch error"
|
||||
elif status == apt_pkg.AcquireItem.STAT_TRANSIENT_NETWORK_ERROR:
|
||||
type = "network error"
|
||||
elif status == apt_pkg.AcquireItem.STAT_IDLE:
|
||||
type = "to be fetched"
|
||||
elif status == apt_pkg.AcquireItem.STAT_FETCHING:
|
||||
type = "fetching"
|
||||
elif status == apt_pkg.AcquireItem.STAT_DONE:
|
||||
type = "finished"
|
||||
else:
|
||||
type = "normal"
|
||||
self.kargs = {"desc":desc, \
|
||||
"err_text":err_text, \
|
||||
"status":status, \
|
||||
"type":type}
|
||||
# self.deamon.DownloadErrorSignal(desc, type, err_text)
|
||||
return
|
||||
|
||||
def start(self):
|
||||
# type: () -> None
|
||||
"""Invoked when the Acquire process starts running."""
|
||||
# Reset all our values.
|
||||
self.current_bytes = 0.0
|
||||
self.current_cps = 0.0
|
||||
self.current_items = 0
|
||||
self.elapsed_time = 0
|
||||
self.fetched_bytes = 0.0
|
||||
self.last_bytes = 0.0
|
||||
self.total_bytes = 0.0
|
||||
self.total_items = 0
|
||||
logging.info("start download ...")
|
||||
|
||||
def calculatcps(self):
|
||||
import datetime
|
||||
if self.time == 0:
|
||||
self.time = datetime.datetime.now()
|
||||
self.currentbyte = self.current_bytes
|
||||
return 0
|
||||
else:
|
||||
time = datetime.datetime.now()
|
||||
if self.current_bytes == self.currentbyte:
|
||||
cps = 0
|
||||
else:
|
||||
cps = (self.current_bytes-self.currentbyte) / (time-self.time).microseconds * 1000
|
||||
# print((time-self.time).microseconds)
|
||||
# print(self.current_bytes-self.currentbyte)
|
||||
self.currentbyte = self.current_bytes
|
||||
self.time = time
|
||||
return cps
|
||||
|
||||
class DownloadBackend():
|
||||
def __init__(self, window_main):
|
||||
self.window_main = window_main
|
||||
self.pkglists = []
|
||||
|
||||
def downloadpkgs(self, pkgs = ['minizip', 'code', 'libminizip1', 'libminizip-dev']):
|
||||
self.pkglists = pkgs
|
||||
apt_pkg.init()
|
||||
cache = apt_pkg.Cache()
|
||||
depcache = apt_pkg.DepCache(cache)
|
||||
packagerecords = apt_pkg.PackageRecords(cache)
|
||||
pm = apt_pkg.PackageManager(depcache)
|
||||
sourcelist = apt_pkg.SourceList()
|
||||
sourcelist.read_main_list()
|
||||
try:
|
||||
for pkgname in pkgs:
|
||||
pkg = cache[pkgname]
|
||||
depcache.mark_install(pkg)
|
||||
except Exception as e:
|
||||
logging.error(str(e))
|
||||
return False
|
||||
fetcher = apt_pkg.Acquire(FetchProgress(self))
|
||||
pm.get_archives(fetcher, sourcelist, packagerecords)
|
||||
ret = fetcher.run()
|
||||
|
|
@ -37,7 +37,7 @@ class InstallBackendAptdaemon(InstallBackend):
|
|||
try:
|
||||
trans = yield self.client.update_cache(defer=True)
|
||||
self.window_main.dbusController.transaction = trans
|
||||
#注册回调函数 接收更新的状态
|
||||
# 注册回调函数 接收更新的状态
|
||||
yield self._show_transaction(trans, self.ACTION_UPDATE,
|
||||
_("Checking for updates…"), False)
|
||||
except errors.NotAuthorizedError:
|
||||
|
|
Loading…
Reference in New Issue