Skip to content

Commit

Permalink
Refs #15 Potential fix for WatchTransfer issues with text logs. Added…
Browse files Browse the repository at this point in the history
… delay before transfer to OpenTera.
  • Loading branch information
SBriere committed May 1, 2024
1 parent 60886ef commit c3e819b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

config_man = ConfigManager()

version_string = '1.2.1'
version_string = '1.2.2'
12 changes: 11 additions & 1 deletion libs/servers/WatchServerOpenTera.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,20 @@ def new_file_received(self, device_name: str, filename: str):
kwargs={'device_name': device_name})
self._device_timeouts[device_name].start()

def new_file_received(self, device_name: str, filename: str):
# Cancel sync timer on new file
if self.file_syncher_timer:
self.file_syncher_timer.cancel()
self.file_syncher_timer = None

def device_disconnected(self, device_name: str):
self.initiate_opentera_transfer(device_name)
# self.initiate_opentera_transfer(device_name)
# Wait 30 seconds after the last disconnected device to start transfer
self.file_syncher_timer = threading.Timer(30, self.sync_files)
self.file_syncher_timer.start()

def sync_files(self):
self.file_syncher_timer = None
logging.info("WatchServerOpenTera: Checking if any pending transfers...")
# Get base folder path
base_folder = os.path.join(self.data_path, 'ToProcess')
Expand Down
32 changes: 12 additions & 20 deletions libs/servers/handlers/BaseAppleWatchRequestHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ def do_POST(self):
# Supported file type?
if file_type.lower() in ['data', 'dat', 'csv', 'txt', 'oimi']:

if file_type.lower() in ['data', 'dat']:
# Binary file
fh = open(destination_path, 'wb')
text_format = False
else:
# Text file
fh = open(destination_path, 'w')
text_format = True
# if file_type.lower() in ['data', 'dat']:
# Binary file
fh = open(destination_path, 'wb')
# text_format = False
# else:
# Text file
# fh = open(destination_path, 'w')
# text_format = True

while content_size_remaining > 0:
if buffer_size > content_size_remaining:
Expand All @@ -110,19 +110,11 @@ def do_POST(self):
str(err_desc))
return

if text_format:
fh.write(data.decode(errors="ignore")) # Ignore unknown characters and errors
else:
fh.write(data)
# if text_format:
# fh.write(data.decode(errors="ignore")) # Ignore unknown characters and errors
# else:
fh.write(data)
content_size_remaining -= buffer_size
# content_received = (content_length - content_size_remaining)
# pc = math.floor((content_received / content_length) * 100)
# if pc != last_pc:
# self.streamer.update_progress.emit(file_name, " (" + str(content_received) + "/ " +
# str(content_length) + ")", (content_length -
# content_size_remaining),
# content_length)
# last_pc = pc
fh.close()
else:
# self.streamer.add_log.emit(device_name + ": " + file_name + " - Type de fichier non-supporté: " +
Expand Down

0 comments on commit c3e819b

Please sign in to comment.