8
8
import os
9
9
import serial .tools .list_ports
10
10
11
- from cli_utils import help_strings
12
- from cli_utils .constants import NodeID , CmdID , COMM_INFO , MSG_HISTORY_FILENAME
11
+ from utils import help_strings
12
+ from utils .constants import SAVE_DATA_DIR , NodeID , CmdID , COMM_INFO , MSG_HISTORY_PATH
13
13
14
14
from serial_reader import serial_reader
15
15
from message_parser import parser
@@ -79,7 +79,7 @@ def do_query(self, arg):
79
79
"""Queries the telemetry."""
80
80
print (f"\n Searching message history for { arg } commands..." )
81
81
82
- with open (MSG_HISTORY_FILENAME , encoding = "utf_8" ) as history :
82
+ with open (MSG_HISTORY_PATH , encoding = "utf_8" ) as history :
83
83
msgs = json .load (history )
84
84
85
85
num_results = 0
@@ -94,7 +94,7 @@ def do_query(self, arg):
94
94
95
95
def do_clear (self , _ ):
96
96
"""Clears the json message history file."""
97
- with open (MSG_HISTORY_FILENAME , 'w' , encoding = "utf_8" ) as history :
97
+ with open (MSG_HISTORY_PATH , 'w' , encoding = "utf_8" ) as history :
98
98
history .write ("[]" )
99
99
history .flush ()
100
100
print ("The json message history file has been cleared.\n " )
@@ -128,8 +128,11 @@ def do_exit(self, _):
128
128
129
129
def init_json ():
130
130
"""Initializes the JSON file which logs all messages."""
131
- if (not os .path .exists (MSG_HISTORY_FILENAME )) or (os .path .getsize (MSG_HISTORY_FILENAME ) == 0 ):
132
- with open (MSG_HISTORY_FILENAME , 'w' , encoding = "utf_8" ) as history :
131
+ if not os .path .exists (SAVE_DATA_DIR ):
132
+ os .mkdir (SAVE_DATA_DIR )
133
+
134
+ if (not os .path .exists (MSG_HISTORY_PATH )) or (os .path .getsize (MSG_HISTORY_PATH ) == 0 ):
135
+ with open (MSG_HISTORY_PATH , 'w' , encoding = "utf_8" ) as history :
133
136
history .write ("[]" )
134
137
135
138
0 commit comments