Resource work

This commit is contained in:
Mark Qvist 2020-08-12 20:58:32 +02:00
parent bf0e22d461
commit 81804b5d19

View File

@ -122,6 +122,7 @@ class Resource:
resource_data = None resource_data = None
if hasattr(data, "read"): if hasattr(data, "read"):
data_size = os.stat(data.name).st_size data_size = os.stat(data.name).st_size
self.grand_total_parts = math.ceil(data_size/Resource.SDU)
if data_size <= Resource.MAX_EFFICIENT_SIZE: if data_size <= Resource.MAX_EFFICIENT_SIZE:
self.total_segments = 1 self.total_segments = 1
@ -142,6 +143,8 @@ class Resource:
elif isinstance(data, bytes): elif isinstance(data, bytes):
data_size = len(data) data_size = len(data)
self.grand_total_parts = math.ceil(data_size/Resource.SDU)
resource_data = data resource_data = data
self.total_segments = 1 self.total_segments = 1
self.segment_index = 1 self.segment_index = 1
@ -167,7 +170,6 @@ class Resource:
self.__watchdog_job_id = 0 self.__watchdog_job_id = 0
self.__progress_callback = progress_callback self.__progress_callback = progress_callback
self.rtt = None self.rtt = None
self.grand_total_parts = math.ceil(data_size/Resource.SDU)
self.receiver_min_consecutive_height = 0 self.receiver_min_consecutive_height = 0
@ -717,6 +719,8 @@ class Resource:
def progress(self): def progress(self):
if self.initiator: if self.initiator:
# TODO: Remove
# progress = self.sent_parts / len(self.parts)
self.processed_parts = (self.segment_index-1)*math.ceil(Resource.MAX_EFFICIENT_SIZE/Resource.SDU) self.processed_parts = (self.segment_index-1)*math.ceil(Resource.MAX_EFFICIENT_SIZE/Resource.SDU)
self.processed_parts += self.sent_parts self.processed_parts += self.sent_parts
self.progress_total_parts = float(self.grand_total_parts) self.progress_total_parts = float(self.grand_total_parts)