Queer European MD passionate about IT
Browse Source

Always print progress bar at 100%

Davte 4 years ago
parent
commit
063cc375df
4 changed files with 10 additions and 6 deletions
  1. 1 1
      filebridging/__init__.py
  2. 3 1
      filebridging/client.py
  3. 4 2
      filebridging/server.py
  4. 2 2
      filebridging/utilities.py

+ 1 - 1
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"

+ 3 - 1
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

+ 4 - 2
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
 

+ 2 - 2
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