Implemented :download-delete.
This commit is contained in:
parent
dd995c434c
commit
8cd5f9e6d1
@ -358,16 +358,19 @@ class DownloadItem(QObject):
|
|||||||
self.reply = None
|
self.reply = None
|
||||||
if self.fileobj is not None:
|
if self.fileobj is not None:
|
||||||
self.fileobj.close()
|
self.fileobj.close()
|
||||||
try:
|
if remove_data:
|
||||||
if (self._filename is not None and os.path.exists(self._filename)
|
self.delete()
|
||||||
and remove_data):
|
|
||||||
os.remove(self._filename)
|
|
||||||
except OSError:
|
|
||||||
log.downloads.exception("Failed to remove partial file")
|
|
||||||
self.done = True
|
self.done = True
|
||||||
self.finished.emit()
|
self.finished.emit()
|
||||||
self.data_changed.emit()
|
self.data_changed.emit()
|
||||||
|
|
||||||
|
def delete(self):
|
||||||
|
try:
|
||||||
|
if (self._filename is not None and os.path.exists(self._filename)):
|
||||||
|
os.remove(self._filename)
|
||||||
|
except OSError:
|
||||||
|
log.downloads.exception("Failed to remove partial file")
|
||||||
|
|
||||||
def retry(self):
|
def retry(self):
|
||||||
"""Retry a failed download."""
|
"""Retry a failed download."""
|
||||||
self.cancel()
|
self.cancel()
|
||||||
@ -749,9 +752,26 @@ class DownloadManager(QAbstractListModel):
|
|||||||
except IndexError:
|
except IndexError:
|
||||||
raise cmdexc.CommandError("There's no download {}!".format(count))
|
raise cmdexc.CommandError("There's no download {}!".format(count))
|
||||||
if download.done:
|
if download.done:
|
||||||
raise cmdexc.CommandError("Download {} is already done!".format(count))
|
raise cmdexc.CommandError("Download {} is already done!"
|
||||||
|
.format(count))
|
||||||
download.cancel()
|
download.cancel()
|
||||||
|
|
||||||
|
@cmdutils.register(instance='download-manager', scope='window')
|
||||||
|
def download_delete(self, count: {'special': 'count'}=0):
|
||||||
|
"""Delete the last/[count]th download from disk.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
count: The index of the download to cancel.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
download = self.downloads[count - 1]
|
||||||
|
except IndexError:
|
||||||
|
raise cmdexc.CommandError("There's no download {}!".format(count))
|
||||||
|
if not download.successful:
|
||||||
|
raise cmdexc.CommandError("Download {} is not done!".format(count))
|
||||||
|
download.delete()
|
||||||
|
self.remove_item(download)
|
||||||
|
|
||||||
@cmdutils.register(instance='download-manager', scope='window',
|
@cmdutils.register(instance='download-manager', scope='window',
|
||||||
deprecated="Use :download instead.")
|
deprecated="Use :download instead.")
|
||||||
def cancel_download(self, count: {'special': 'count'}=1):
|
def cancel_download(self, count: {'special': 'count'}=1):
|
||||||
|
Loading…
Reference in New Issue
Block a user