src/eric7/SystemUtilities/FileSystemUtilities.py

branch
eric7
changeset 9944
011ae0edbcff
parent 9923
f706be800097
child 9972
68ac01294544
diff -r 02a40e8bd135 -r 011ae0edbcff src/eric7/SystemUtilities/FileSystemUtilities.py
--- a/src/eric7/SystemUtilities/FileSystemUtilities.py	Wed Mar 29 11:32:06 2023 +0200
+++ b/src/eric7/SystemUtilities/FileSystemUtilities.py	Wed Mar 29 14:15:55 2023 +0200
@@ -615,3 +615,43 @@
         return volumeDirectories
     else:
         return volumeDirectory
+
+
+def getUserMounts():
+    """
+    Function to determine all available user mounts.
+
+    Note: On Windows platforms all available drives are returned.
+
+    @return list of user mounts or drives
+    @rtype list of str
+    """
+    mountedPaths = []
+
+    if OSUtilities.isWindowsPlatform():
+        # we are on a Windows platform
+            for disk in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
+                dirpath = "{0}:\\".format(disk)
+                if os.path.exists(dirpath):
+                    mountedPaths.append(dirpath)
+    else:
+        # we are on a Linux or macOS platform
+        mountPathStart = (
+            "/media/{0}/".format(OSUtilities.getUserName())
+            if OSUtilities.isLinuxPlatform()
+            else "/Volumes/"
+        )
+
+        for mountCommand in ["mount", "/sbin/mount", "/usr/sbin/mount"]:
+            with contextlib.suppress(FileNotFoundError):
+                mountOutput = subprocess.run(  # secok
+                    mountCommand, check=True, capture_output=True, text=True
+                ).stdout.splitlines()
+                mounts = [
+                    x.split(" type", 1)[0].split(" (", 1)[0].split(maxsplit=2)[-1]
+                    for x in mountOutput
+                ]
+                mountedPaths = [x for x in mounts if x.startswith(mountPathStart)]
+                break
+
+    return mountedPaths

eric ide

mercurial