Moved LICENSE -> COPYING. A more traditional name
[data_logger.git] / data_logger.py
index 72acb7f8960da796cd0565cb0de24710f1ace9bd..a901733cddcd4f59ddc74622e0de31eda30863fc 100644 (file)
@@ -31,7 +31,9 @@ import time
 import string
 import numpy
 
-VERSION = "0.1"
+VERSION = "0.2"
+DEFAULT_PATH = "~/rsrch/data"
+DEFAULT_PATH_REPLACE_STRING = "$DEFAULT$/"
 
 class error (Exception) :
     "Basic module error class"
@@ -40,6 +42,13 @@ class error (Exception) :
 class errorDirExists (error) :
     "The specified directory already exists"
 
+def normalize_logdir(log_dir):
+        length = len(DEFAULT_PATH_REPLACE_STRING)
+        if log_dir[:length] == DEFAULT_PATH_REPLACE_STRING:
+            log_dir = os.path.join(DEFAULT_PATH, log_dir[length:])
+        log_dir = os.path.expanduser(log_dir)
+        return log_dir
+
 class data_log :
     """
     Data logging class.
@@ -48,6 +57,9 @@ class data_log :
     Initialized with log_dir and log_name.
     log_dir specifies the base data directory.
     If it doesn't exist, log_dir is created.
+    
+    If log_dir begins with '$DEFAULT$/', that portion of the path is replaced
+    with the then-current contents of the DEFAULT_PATH module global.
 
     A subdir of log_dir is created (if necessary) named YYYYMMDD,
     where YYYYMMDD is the current day in localtime.
@@ -96,7 +108,7 @@ class data_log :
         cleanname = filename.translate(self.transtable, self.delete_chars)
         return cleanname
     def _create_logdir(self, log_dir) :
-        log_dir = os.path.expanduser(log_dir)
+        log_dir = normalize_logdir(log_dir)
         if not os.path.exists(log_dir) :
             os.mkdir(log_dir, 0755)
         return log_dir