Move some common runfolder path management code into its own module
[htsworkflow.git] / htsworkflow / automation / spoolwatcher.py
index 93efe27f96a94478f9262ca0f7d2fb6724911165..932efbf41ca9045656015962e4f2e3593e2812c2 100644 (file)
@@ -7,6 +7,7 @@ import sys
 import time
 
 from htsworkflow.util import mount
+from htsworkflow.automation.solexa import is_runfolder, get_top_dir
 
 # this uses pyinotify
 import pyinotify
@@ -16,41 +17,6 @@ IN_UNMOUNT = EventsCodes.ALL_FLAGS['IN_UNMOUNT']
 
 from benderjab import rpc
 
-def is_runfolder(name):
-    """
-    Is it a runfolder?
-
-    >>> print is_runfolder('090630_HWUSI-EAS999_0006_30LNFAAXX')
-    True
-    >>> print is_runfolder('hello')
-    False
-    """
-    if re.match("[0-9]{6}_.*", name):
-        return True
-    else:
-        return False
-
-def get_top_dir(root, path):
-    """
-    Return the directory in path that is a subdirectory of root.
-    e.g.
-
-    >>> print get_top_dir('/a/b/c', '/a/b/c/d/e/f')
-    d
-    >>> print get_top_dir('/a/b/c/', '/a/b/c/d/e/f')
-    d
-    >>> print get_top_dir('/a/b/c', '/g/e/f')
-    None
-    >>> print get_top_dir('/a/b/c', '/a/b/c')
-    <BLANKLINE>
-    """
-    if path.startswith(root):
-        subpath = path[len(root):]
-        if subpath.startswith('/'):
-            subpath = subpath[1:]
-        return subpath.split(os.path.sep)[0]
-    else:
-        return None
 
 class WatcherEvent(object):
     """