613 |
613 |
614 if findAll: |
614 if findAll: |
615 return volumeDirectories |
615 return volumeDirectories |
616 else: |
616 else: |
617 return volumeDirectory |
617 return volumeDirectory |
|
618 |
|
619 |
|
620 def getUserMounts(): |
|
621 """ |
|
622 Function to determine all available user mounts. |
|
623 |
|
624 Note: On Windows platforms all available drives are returned. |
|
625 |
|
626 @return list of user mounts or drives |
|
627 @rtype list of str |
|
628 """ |
|
629 mountedPaths = [] |
|
630 |
|
631 if OSUtilities.isWindowsPlatform(): |
|
632 # we are on a Windows platform |
|
633 for disk in "ABCDEFGHIJKLMNOPQRSTUVWXYZ": |
|
634 dirpath = "{0}:\\".format(disk) |
|
635 if os.path.exists(dirpath): |
|
636 mountedPaths.append(dirpath) |
|
637 else: |
|
638 # we are on a Linux or macOS platform |
|
639 mountPathStart = ( |
|
640 "/media/{0}/".format(OSUtilities.getUserName()) |
|
641 if OSUtilities.isLinuxPlatform() |
|
642 else "/Volumes/" |
|
643 ) |
|
644 |
|
645 for mountCommand in ["mount", "/sbin/mount", "/usr/sbin/mount"]: |
|
646 with contextlib.suppress(FileNotFoundError): |
|
647 mountOutput = subprocess.run( # secok |
|
648 mountCommand, check=True, capture_output=True, text=True |
|
649 ).stdout.splitlines() |
|
650 mounts = [ |
|
651 x.split(" type", 1)[0].split(" (", 1)[0].split(maxsplit=2)[-1] |
|
652 for x in mountOutput |
|
653 ] |
|
654 mountedPaths = [x for x in mounts if x.startswith(mountPathStart)] |
|
655 break |
|
656 |
|
657 return mountedPaths |