From ff4c41c0139c324b35c209e85a70cb0d42799ce7 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 8 Jan 2009 10:36:20 -0500 Subject: [PATCH] Added $DEFAULT$ replacement to log_dir path to ease log_dir adjustment. --- data_logger.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/data_logger.py b/data_logger.py index 72acb7f..3286468 100644 --- a/data_logger.py +++ b/data_logger.py @@ -32,6 +32,8 @@ import string import numpy VERSION = "0.1" +DEFAULT_PATH = "~/rsrch/data" +DEFAULT_PATH_REPLACE_STRING = "$DEFAULT$/" class error (Exception) : "Basic module error class" @@ -48,6 +50,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. @@ -95,8 +100,14 @@ class data_log : """ cleanname = filename.translate(self.transtable, self.delete_chars) return cleanname - def _create_logdir(self, log_dir) : + def _normalize_logdir(self, 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 + def _create_logdir(self, log_dir) : + log_dir = self._normalize_logdir(log_dir) if not os.path.exists(log_dir) : os.mkdir(log_dir, 0755) return log_dir -- 2.26.2