mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-05 07:58:38 +00:00
Use list comprehension in get_file_progress
Should be slightly quicker with large numbers of files. Also moved socket import to the top as it will always be imported.
This commit is contained in:
parent
4ad45b2d4a
commit
2df2f882e0
1 changed files with 8 additions and 11 deletions
|
@ -18,6 +18,7 @@ from __future__ import division
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
|
import socket
|
||||||
from urlparse import urlparse
|
from urlparse import urlparse
|
||||||
from itertools import izip
|
from itertools import izip
|
||||||
|
|
||||||
|
@ -771,18 +772,15 @@ class Torrent(object):
|
||||||
return self.handle.queue_position()
|
return self.handle.queue_position()
|
||||||
|
|
||||||
def get_file_progress(self):
|
def get_file_progress(self):
|
||||||
"""Returns the file progress as a list of floats... 0.0 -> 1.0"""
|
"""Calculates the file progress as a percentage.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list of floats: The file progress (0.0 -> 1.0)
|
||||||
|
"""
|
||||||
if not self.has_metadata:
|
if not self.has_metadata:
|
||||||
return 0.0
|
return 0.0
|
||||||
|
return [progress / _file.size if _file.size else 0.0 for progress, _file in
|
||||||
file_progress = self.handle.file_progress()
|
izip(self.handle.file_progress(), self.torrent_info.files())]
|
||||||
ret = []
|
|
||||||
for index, _file in enumerate(self.get_files()):
|
|
||||||
try:
|
|
||||||
ret.append(file_progress[index] / _file["size"])
|
|
||||||
except ZeroDivisionError:
|
|
||||||
ret.append(0.0)
|
|
||||||
return ret
|
|
||||||
|
|
||||||
def get_tracker_host(self):
|
def get_tracker_host(self):
|
||||||
"""Get the hostname of the currently connected tracker.
|
"""Get the hostname of the currently connected tracker.
|
||||||
|
@ -804,7 +802,6 @@ class Torrent(object):
|
||||||
if hasattr(url, "hostname"):
|
if hasattr(url, "hostname"):
|
||||||
host = (url.hostname or "DHT")
|
host = (url.hostname or "DHT")
|
||||||
# Check if hostname is an IP address and just return it if that's the case
|
# Check if hostname is an IP address and just return it if that's the case
|
||||||
import socket
|
|
||||||
try:
|
try:
|
||||||
socket.inet_aton(host)
|
socket.inet_aton(host)
|
||||||
except socket.error:
|
except socket.error:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue