# HG changeset patch # User Frederic Bastien # Date 1296756990 18000 # Node ID 58dff11840f062c9fd0e02cf02e5aeb4be327625 # Parent e1b5092b4a5371630cc786e5e30b34ef7d8fc2f7 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. diff -r e1b5092b4a53 -r 58dff11840f0 pylearn/datasets/config.py --- 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