Skip to content

Commit

Permalink
Don't create a new log file if a sonde is lost and re-detected.
Browse files Browse the repository at this point in the history
  • Loading branch information
darksidelemm committed Jan 4, 2018
1 parent 7f2cce5 commit b46758b
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions auto_rx/auto_rx.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import datetime
import time
import os
import glob
import shutil
import platform
import signal
Expand Down Expand Up @@ -509,11 +510,17 @@ def decode_rs92(frequency, ppm=0, gain=-1, bias=False, rx_queue=None, almanac=No
# Per-Sonde Logging
if save_log:
if _log_file is None:
_log_file_name = "./log/%s_%s_%s_%d.log" % (
datetime.datetime.utcnow().strftime("%Y%m%d-%H%M%S"),
data['id'],
(data['type'] + _ozone),
int(frequency/1e3))
_existing_files = glob.glob("./log/*%s_%s*.log" % (data['id'], data['type']))
if len(_existing_files) != 0:
_log_file_name = _existing_files[0]
logging.debug("Using existing log file: %s" % _log_file_name)
else:
_log_file_name = "./log/%s_%s_%s_%d.log" % (
datetime.datetime.utcnow().strftime("%Y%m%d-%H%M%S"),
data['id'],
(data['type'] + _ozone),
int(frequency/1e3))
logging.debug("Opening new log file: %s" % _log_file_name)

_log_file = open(_log_file_name,'wb')

Expand Down Expand Up @@ -613,11 +620,17 @@ def decode_rs41(frequency, ppm=0, gain=-1, bias=False, rx_queue=None, timeout=12
# Per-Sonde Logging
if save_log:
if _log_file is None:
_log_file_name = "./log/%s_%s_%s_%d.log" % (
datetime.datetime.utcnow().strftime("%Y%m%d-%H%M%S"),
data['id'],
data['type'],
int(frequency/1e3))
_existing_files = glob.glob("./log/*%s_%s*.log" % (data['id'], data['type']))
if len(_existing_files) != 0:
_log_file_name = _existing_files[0]
logging.debug("Using existing log file: %s" % _log_file_name)
else:
_log_file_name = "./log/%s_%s_%s_%d.log" % (
datetime.datetime.utcnow().strftime("%Y%m%d-%H%M%S"),
data['id'],
data['type'],
int(frequency/1e3))
logging.debug("Opening new log file: %s" % _log_file_name)

_log_file = open(_log_file_name,'wb')

Expand Down

2 comments on commit b46758b

@ED6E0F17
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_log_file = open(_log_file_name,'wb')

is overwriting any existing file; google says:

“a” (append), or “wb” (write binary). Note that if you use either “w” or “wb”, Python will overwrite the file, if it exists already or create it if the file doesn't exist.

@TheSkorm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the report @ED6E0F17 . I've fixed this in commit 7415e29

Please sign in to comment.