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"
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.
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.
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