@@ -236,9 +236,9 @@ def get_drives():
236
236
if len (words ) >= 3 and words [1 ] == "2" and words [2 ] == "FAT" :
237
237
drives .append (words [0 ])
238
238
else :
239
- rootpath = "/media"
239
+ rootpath = "/run/ media"
240
240
if not os .path .isdir (rootpath ):
241
- rootpath = "/run/ media"
241
+ rootpath = "/media"
242
242
if not os .path .isdir (rootpath ):
243
243
rootpath = "/opt/media"
244
244
if sys .platform == "darwin" :
@@ -318,17 +318,16 @@ def error(msg):
318
318
if args .serial :
319
319
if str (args .serial ).startswith ("/dev/tty" ) or str (args .serial ).startswith ("COM" ) or str (args .serial ).startswith ("/dev/cu" ):
320
320
try :
321
- print ("Resetting " + str (args .serial ))
321
+ print ("Resetting " + str (args .serial ))
322
322
try :
323
323
ser = serial .Serial (args .serial , 1200 )
324
324
ser .dtr = False
325
325
except :
326
- pass
326
+ print ( "Caught exception during reset!" )
327
327
# Probably should be smart and check for device appearance or something
328
328
time .sleep (10 )
329
329
except :
330
330
pass
331
-
332
331
if args .list :
333
332
list_drives ()
334
333
else :
@@ -359,12 +358,31 @@ def error(msg):
359
358
else :
360
359
drives = get_drives ()
361
360
if (len (drives ) == 0 ) and (sys .platform == "linux" ):
362
- rpidisk = glob .glob ("/dev/disk/by-id/usb-RPI_RP2*-part1" )
363
- try :
364
- subprocess .run (["udisksctl" , "mount" , "--block-device" , os .path .realpath (rpidisk [0 ])])
365
- drives = get_drives ()
366
- except :
367
- pass # If it fails, no problem since it was a heroic attempt
361
+ globexpr = "/dev/disk/by-id/usb-RPI_RP2*-part1"
362
+ rpidisk = glob .glob (globexpr )
363
+ if len (rpidisk ) == 0 :
364
+ print ("Unable to find disk by ID using expression: {}" .format (globexpr ))
365
+ else :
366
+ try :
367
+ cmd = ["udisksctl" , "mount" , "--block-device" , os .path .realpath (rpidisk [0 ])]
368
+ proc_out = subprocess .run (cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
369
+ if proc_out .returncode == 0 :
370
+ stdoutput = proc_out .stdout .decode ("UTF-8" )
371
+ match = re .search (r'Mounted\s+.*\s+at\s+([^\.]*)' , stdoutput )
372
+ if match is None :
373
+ print ("Warn: {} did not print mount point. Attempting to locate mounted drive in file system. StdOut={}" .format (cmd [0 ], stdoutput ))
374
+ drives = get_drives ()
375
+ else :
376
+ drives = [match .group (1 )]
377
+ else :
378
+ print ("Error executing command {}. Return Code: {} Std Output: {} StdError: {}" .format (" " .join (cmd ),
379
+ proc_out .returncode ,
380
+ proc_out .stdout .decode ("UTF-8" ),
381
+ proc_out .stderr .decode ("UTF-8" )))
382
+
383
+ except Exception as ex :
384
+ print ("Exception executing udisksctl. Exception: {}" .format (ex ))
385
+ # If it fails, no problem since it was a heroic attempt
368
386
369
387
if args .output :
370
388
write_file (args .output , outbuf )
0 commit comments