From 063cc375dfd76c415077fb4b31bbf85c2b8dd2dc Mon Sep 17 00:00:00 2001 From: Davte Date: Sun, 19 Apr 2020 20:41:36 +0200 Subject: [PATCH] Always print progress bar at 100% --- filebridging/__init__.py | 2 +- filebridging/client.py | 4 +++- filebridging/server.py | 6 ++++-- filebridging/utilities.py | 4 ++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/filebridging/__init__.py b/filebridging/__init__.py index e91deb7..8fbde5a 100644 --- a/filebridging/__init__.py +++ b/filebridging/__init__.py @@ -13,6 +13,6 @@ __author__ = "Davide Testa" __email__ = "davide@davte.it" __credits__ = [] __license__ = "GNU General Public License v3.0" -__version__ = "0.0.8" +__version__ = "0.0.9" __maintainer__ = "Davide Testa" __contact__ = "t.me/davte" diff --git a/filebridging/client.py b/filebridging/client.py index 23c3284..5fa2ccc 100644 --- a/filebridging/client.py +++ b/filebridging/client.py @@ -399,6 +399,7 @@ class Client: self.print_progress_bar( progress=new_progress, bytes_=bytes_sent, + force=(new_progress == 100) ) print() # New line after progress_bar writer.close() @@ -431,7 +432,8 @@ class Client: ) self.print_progress_bar( progress=new_progress, - bytes_=bytes_received + bytes_=bytes_received, + force=(new_progress == 100) ) if not input_data: break diff --git a/filebridging/server.py b/filebridging/server.py index fc10c64..c4f550d 100644 --- a/filebridging/server.py +++ b/filebridging/server.py @@ -73,7 +73,7 @@ class Server: def set_ssl_context(self, ssl_context: ssl.SSLContext): self._ssl_context = ssl_context - async def run_reader(self, reader, connection_token): + async def run_reader(self, reader: asyncio.StreamReader, connection_token): while 1: try: # Wait one second if buffer is full @@ -90,7 +90,7 @@ class Server: except Exception as e: logging.error(f"Unexpected exception:\n{e}", exc_info=True) - async def run_writer(self, writer, connection_token): + async def run_writer(self, writer: asyncio.StreamWriter, connection_token): consecutive_interruptions = 0 errors = 0 while connection_token in self.buffers: @@ -100,6 +100,7 @@ class Server: # Slow down if buffer is empty; after 1.5 s of silence, break consecutive_interruptions += 1 if consecutive_interruptions > 3: + logging.error("Too many interruptions...") break await asyncio.sleep(.5) continue @@ -166,6 +167,7 @@ class Server: else: return 0 # On success, return 0 # On exception, disconnect and return 1 + logging.error("Disconnecting...") self.disconnect(connection_token=connection_token) return 1 diff --git a/filebridging/utilities.py b/filebridging/utilities.py index c7db6c6..a3d2b4c 100644 --- a/filebridging/utilities.py +++ b/filebridging/utilities.py @@ -77,9 +77,9 @@ def timed_action(interval: Union[int, float, datetime.timedelta] = None): timedelta = interval def timer(function_to_time): - def timed_function(*args, **kwargs): + def timed_function(*args, force: bool = False, **kwargs): nonlocal last_call - if now() > last_call + timedelta: + if force or now() > last_call + timedelta: last_call = now() return function_to_time(*args, **kwargs) return