changeset 1413:58dff11840f0

Allow PYLEARN_DATA_ROOT to be a list of directory. created pylearn.datasets.config.get_filepath_in_roots(name) fct to find a file in the list of directory.
author Frederic Bastien <nouiz@nouiz.org>
date Thu, 03 Feb 2011 13:16:30 -0500
parents e1b5092b4a53
children 2b82c5a11512
files pylearn/datasets/config.py
diffstat 1 files changed, 32 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/pylearn/datasets/config.py	Wed Feb 02 14:33:01 2011 -0500
+++ b/pylearn/datasets/config.py	Thu Feb 03 13:16:30 2011 -0500
@@ -26,5 +26,36 @@
 env_get.first_warning = True
 
 def data_root():
-    return env_get('PYLEARN_DATA_ROOT', os.getenv('HOME')+'/data', 'DBPATH')
+    """Deprecated, use data_roots() or get_filepath_in_roots()
+    
+    It id deprecated as it don't allow to use more then 1 path.
+    """
+    roots = env_get('PYLEARN_DATA_ROOT', os.getenv('HOME')+'/data', 'DBPATH')
+    return roots.split(':')[0]
 
+def data_roots():
+    """Return a list of path that are in the PYLEARN_DATA_ROOT env variable."""
+    if hasattr(data_roots, 'rval'):
+        return data_roots.rval
+    roots = os.getenv('PYLEARN_DATA_ROOT')
+    if roots is None:
+        roots = data_root()
+    else:
+        roots = roots.split(':')
+    roots2 = []
+    #remove directory that don't exist
+    for root in roots:
+        if os.path.exists(root):
+            roots2.append(root)
+    data_roots.rval = roots2
+    return roots2
+
+
+def get_filepath_in_roots(name):
+    """Return the full path of name that exist under a directory
+    in the PYLEARN_DATA_ROOT env variable.
+    """
+    for root in data_roots():
+        path = os.path.join(root,name)
+        if os.path.exists(path):
+            return path