From 6cb30d778de3daa30a26b9e587c2ae662e3f8a48 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Thu, 26 Apr 2018 00:57:47 +0200 Subject: [PATCH] File transfer example --- Examples/Filetransfer.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/Examples/Filetransfer.py b/Examples/Filetransfer.py index c8d6000..1b9243d 100644 --- a/Examples/Filetransfer.py +++ b/Examples/Filetransfer.py @@ -413,18 +413,21 @@ def download_concluded(resource): global menu_mode, current_filename saved_filename = current_filename - counter = 0 - while os.path.isfile(saved_filename): - counter += 1 - saved_filename = current_filename+"."+str(counter) + if resource.status == RNS.Resource.COMPLETE: + counter = 0 + while os.path.isfile(saved_filename): + counter += 1 + saved_filename = current_filename+"."+str(counter) - try: - file = open(saved_filename, "w") - file.write(resource.data) - file.close() + try: + file = open(saved_filename, "w") + file.write(resource.data) + file.close() + menu_mode = "download_concluded" + except: + menu_mode = "save_error" + else: menu_mode = "download_concluded" - except: - menu_mode = "save_error" # A convenience function for clearing the screen