changeset 833:039e93a95c20

dataset.config uses logging for warnings
author James Bergstra <bergstrj@iro.umontreal.ca>
date Fri, 16 Oct 2009 12:14:11 -0400
parents 67b92a42f86b
children 580087712f69
files pylearn/datasets/config.py
diffstat 1 files changed, 15 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/pylearn/datasets/config.py	Fri Oct 16 12:04:05 2009 -0400
+++ b/pylearn/datasets/config.py	Fri Oct 16 12:14:11 2009 -0400
@@ -4,18 +4,26 @@
 Especially, the locations of data files.
 """
 
-import os, sys
+import os, sys, logging
+_logger = logging.getLogger('pylearn.datasets.config')
+def debug(*msg): _logger.debug(' '.join(str(m) for m in msg))
+def info(*msg): _logger.info(' '.join(str(m) for m in msg))
+def warn(*msg): _logger.warn(' '.join(str(m) for m in msg))
+def warning(*msg): _logger.warning(' '.join(str(m) for m in msg))
+def error(*msg): _logger.error(' '.join(str(m) for m in msg))
+
+
 def env_get(key, default, key2 = None):
     if key2 and os.getenv(key) is None:
         key=key2
     if os.getenv(key) is None:
-        print >> sys.stderr, "WARNING: Environment variable", key,
-        print >> sys.stderr, "is not set. Using default of", default
-    if os.getenv(key) is None:
-      return default
+        if env_get.first_warning:
+            warning("Environment variable", key, 'is not set. Using default of', default)
+            env_get.first_warning = False
+        return default
     else:
-      return os.getenv(key)
-    #return default if os.getenv(key) is None else os.getenv(key)
+        os.getenv(key)
+env_get.first_warning = True
 
 def data_root():
     return env_get('PYLEARN_DATA_ROOT', os.getenv('HOME')+'/data', 'DBPATH')