From 100a3b35ed6ed59fc481922996b16c361fd1a368 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 9 Jan 2009 09:50:57 -0500 Subject: [PATCH] Moved normalize_logdir() out of data_log. Now code that wants to use the default data_logger directory doesn't need a fullblown data_log instance. --- data_logger.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/data_logger.py b/data_logger.py index 3286468..a901733 100644 --- a/data_logger.py +++ b/data_logger.py @@ -31,7 +31,7 @@ import time import string import numpy -VERSION = "0.1" +VERSION = "0.2" DEFAULT_PATH = "~/rsrch/data" DEFAULT_PATH_REPLACE_STRING = "$DEFAULT$/" @@ -42,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. @@ -100,14 +107,8 @@ class data_log : """ cleanname = filename.translate(self.transtable, self.delete_chars) return cleanname - 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) + log_dir = normalize_logdir(log_dir) if not os.path.exists(log_dir) : os.mkdir(log_dir, 0755) return log_dir -- 2.26.2