Browse Source

Allow user to choose output file name

Kinda silly that the help message said you could choose it, but in
reality you couldn't.  Now you can.

As an aside: good lord this code is a mess.  I have a ton of cleanup to
do if I feel like it.
Clara Hobbs 6 years ago
parent
commit
b0fad80c76
1 changed files with 8 additions and 6 deletions
  1. 8
    6
      OscScreenGrabLAN.py

+ 8
- 6
OscScreenGrabLAN.py View File

149
 
149
 
150
 # Prepare filename as C:\MODEL_SERIAL_YYYY-MM-DD_HH.MM.SS
150
 # Prepare filename as C:\MODEL_SERIAL_YYYY-MM-DD_HH.MM.SS
151
 timestamp = time.strftime("%Y-%m-%d_%H.%M.%S", time.localtime())
151
 timestamp = time.strftime("%Y-%m-%d_%H.%M.%S", time.localtime())
152
-filename = path_to_save + id_fields[model] + "_" + id_fields[serial] + "_" + timestamp
152
+if len(sys.argv) > 3:
153
+    filename = sys.argv[3]
154
+else:
155
+    filename = path_to_save + id_fields[model] + "_" + id_fields[serial] + "_" + timestamp + "." + file_format
153
 
156
 
154
 if file_format in ["png", "bmp"]:
157
 if file_format in ["png", "bmp"]:
155
     # Ask for an oscilloscope display print screen
158
     # Ask for an oscilloscope display print screen
182
     buff = buff[tmcHeaderLen: tmcHeaderLen+expectedDataLen]
185
     buff = buff[tmcHeaderLen: tmcHeaderLen+expectedDataLen]
183
 
186
 
184
     # Write raw data to file
187
     # Write raw data to file
185
-    full_file_name = filename + '.' + file_format
186
-    with open(full_file_name, 'wb') as f:
188
+    with open(filename, 'wb') as f:
187
     	f.write(buff)
189
     	f.write(buff)
188
-    print('Saved raw data to {}'.format(full_file_name))
190
+    print('Saved raw data to {}'.format(filename))
189
 
191
 
190
 # TODO: Change WAV:FORM from ASC to BYTE
192
 # TODO: Change WAV:FORM from ASC to BYTE
191
 elif file_format == "csv":
193
 elif file_format == "csv":
276
                     csv_buff += "," + str(point) + os.linesep
278
                     csv_buff += "," + str(point) + os.linesep
277
 
279
 
278
     # Save data as CSV
280
     # Save data as CSV
279
-    scr_file = open(filename + "." + file_format, "wb")
281
+    scr_file = open(filename, "wb")
280
     scr_file.write(csv_buff)
282
     scr_file.write(csv_buff)
281
     scr_file.close()
283
     scr_file.close()
282
 
284
 
283
-    print ("Saved file:", "'" + filename + "." + file_format + "'")
285
+    print ("Saved file:", "'" + filename + "'")
284
 
286
 
285
 tn.close()
287
 tn.close()

Loading…
Cancel
Save