Fixing of spoolwatch for hybrid version.
authorBrandon King <kingb@caltech.edu>
Tue, 5 Aug 2008 21:16:09 +0000 (21:16 +0000)
committerBrandon King <kingb@caltech.edu>
Tue, 5 Aug 2008 21:16:09 +0000 (21:16 +0000)
htswcommon/htswcommon/util/mount.py [new file with mode: 0644]
htswdataprod/htswdataprod/automation/spoolwatcher.py
htswdataprod/scripts/spoolwatcher

diff --git a/htswcommon/htswcommon/util/mount.py b/htswcommon/htswcommon/util/mount.py
new file mode 100644 (file)
index 0000000..75dbe0a
--- /dev/null
@@ -0,0 +1,65 @@
+"""
+Utilities for working with unix-style mounts.
+"""
+import os
+import subprocess
+
+def list_mount_points():
+    """
+    Return list of current mount points
+
+    Note: unix-like OS specific
+    """
+    mount_points = []
+    likely_locations = ['/sbin/mount', '/bin/mount']
+    for mount in likely_locations:
+        if os.path.exists(mount):
+            p = subprocess.Popen(mount, stdout=subprocess.PIPE)
+            p.wait()
+            for l in p.stdout.readlines():
+                rec = l.split()
+                device = rec[0]            
+                mount_point = rec[2]
+                assert rec[1] == 'on'
+                # looking at the output of mount on linux, osx, and 
+                # sunos, the first 3 elements are always the same
+                # devicename on path
+                # everything after that displays the attributes
+                # of the mount points in wildly differing formats
+                mount_points.append(mount_point)
+            return mount_points
+    else:
+        raise RuntimeError("Couldn't find a mount executable")
+
+def is_mounted(point_to_check):
+    """
+    Return true if argument exactly matches a current mount point.
+    """
+    for mount_point in list_mount_points():
+        if point_to_check == mount_point:
+            return True
+    else:
+        return False
+
+def find_mount_point_for(pathname):
+    """
+    Find the deepest mount point pathname is located on
+    """
+    realpath = os.path.realpath(pathname)
+    mount_points = list_mount_points()
+
+    prefixes = set()
+    for current_mount in mount_points:
+        cp = os.path.commonprefix([current_mount, realpath])
+        prefixes.add((len(cp), cp))
+
+    prefixes = list(prefixes)
+    prefixes.sort()
+    if len(prefixes) == 0:
+        return None
+    else:
+        print prefixes
+        # return longest common prefix
+        return prefixes[-1][1]
+
+
index 56ad42f3c81e55fc89aa4491c08b5457f0026301..4b21fe853bfed1c72c24b5ba559063afcbbd5946 100644 (file)
@@ -6,7 +6,7 @@ import sys
 import time
 #import glob
 
-from gaworkflow.util import mount
+from htswcommon.util import mount
 
 # this uses pyinotify
 import pyinotify
index c805b5c35e598e860c05eabf4a2285b4bc4e22d2..b4ba7ab52c0d4a43a994d9dae2c31f2ab1652810 100644 (file)
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 import sys
-from htsdataprod.automation.spoolwatcher import main
+from htswdataprod.automation.spoolwatcher import main
 
 if __name__ == "__main__":
     sys.exit(main(sys.argv[1:]))