ソースを参照

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年前
コミット
b0fad80c76
1個のファイルの変更8行の追加6行の削除
  1. 8
    6
      OscScreenGrabLAN.py

+ 8
- 6
OscScreenGrabLAN.py ファイルの表示

@@ -149,7 +149,10 @@ print ("Instrument ID:", instrument_id)
149 149
 
150 150
 # Prepare filename as C:\MODEL_SERIAL_YYYY-MM-DD_HH.MM.SS
151 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 157
 if file_format in ["png", "bmp"]:
155 158
     # Ask for an oscilloscope display print screen
@@ -182,10 +185,9 @@ if file_format in ["png", "bmp"]:
182 185
     buff = buff[tmcHeaderLen: tmcHeaderLen+expectedDataLen]
183 186
 
184 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 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 192
 # TODO: Change WAV:FORM from ASC to BYTE
191 193
 elif file_format == "csv":
@@ -276,10 +278,10 @@ elif file_format == "csv":
276 278
                     csv_buff += "," + str(point) + os.linesep
277 279
 
278 280
     # Save data as CSV
279
-    scr_file = open(filename + "." + file_format, "wb")
281
+    scr_file = open(filename, "wb")
280 282
     scr_file.write(csv_buff)
281 283
     scr_file.close()
282 284
 
283
-    print ("Saved file:", "'" + filename + "." + file_format + "'")
285
+    print ("Saved file:", "'" + filename + "'")
284 286
 
285 287
 tn.close()

読み込み中…
キャンセル
保存