@@ -236,9 +236,9 @@ def get_drives():
236236 if len (words ) >= 3 and words [1 ] == "2" and words [2 ] == "FAT" :
237237 drives .append (words [0 ])
238238 else :
239- rootpath = "/media"
239+ rootpath = "/run/ media"
240240 if not os .path .isdir (rootpath ):
241- rootpath = "/run/ media"
241+ rootpath = "/media"
242242 if not os .path .isdir (rootpath ):
243243 rootpath = "/opt/media"
244244 if sys .platform == "darwin" :
@@ -318,17 +318,16 @@ def error(msg):
318318 if args .serial :
319319 if str (args .serial ).startswith ("/dev/tty" ) or str (args .serial ).startswith ("COM" ) or str (args .serial ).startswith ("/dev/cu" ):
320320 try :
321- print ("Resetting " + str (args .serial ))
321+ print ("Resetting " + str (args .serial ))
322322 try :
323323 ser = serial .Serial (args .serial , 1200 )
324324 ser .dtr = False
325325 except :
326- pass
326+ print ( "Caught exception during reset!" )
327327 # Probably should be smart and check for device appearance or something
328328 time .sleep (10 )
329329 except :
330330 pass
331-
332331 if args .list :
333332 list_drives ()
334333 else :
@@ -359,12 +358,31 @@ def error(msg):
359358 else :
360359 drives = get_drives ()
361360 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
368386
369387 if args .output :
370388 write_file (args .output , outbuf )
0 commit comments