From 631e57ec8babdaede82794bbe16f3cca37008644 Mon Sep 17 00:00:00 2001 From: Huanhuan Li Date: Thu, 8 Nov 2012 15:13:27 -0500 Subject: [PATCH] fix logfile specified a directory when run mic with options '--logfile=dir', traceback shows --- mic/creator.py | 8 +++++++- mic/msger.py | 4 +--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/mic/creator.py b/mic/creator.py index 9e57841..8d4bd54 100644 --- a/mic/creator.py +++ b/mic/creator.py @@ -159,8 +159,14 @@ class Creator(cmdln.Cmdln): msger.set_loglevel('debug') if self.options.logfile: + logfile_abs_path = abspath(self.options.logfile) + if not os.path.exists(os.path.dirname(logfile_abs_path)): + os.makedirs(os.path.dirname(logfile_abs_path)) + if os.path.isdir(logfile_abs_path): + raise errors.Usage("logfile's path %s should be file" + % self.options.logfile) msger.set_interactive(False) - msger.set_logfile(self.options.logfile) + msger.set_logfile(logfile_abs_path) configmgr.create['logfile'] = self.options.logfile if self.options.config: diff --git a/mic/msger.py b/mic/msger.py index 2252786..9afc85b 100644 --- a/mic/msger.py +++ b/mic/msger.py @@ -270,8 +270,6 @@ def set_logfile(fpath): def _savelogf(): if LOG_FILE_FP: - if not os.path.exists(os.path.dirname(LOG_FILE_FP)): - os.makedirs(os.path.dirname(LOG_FILE_FP)) fp = open(LOG_FILE_FP, 'w') fp.write(LOG_CONTENT) fp.close() @@ -279,7 +277,7 @@ def set_logfile(fpath): if LOG_FILE_FP is not None: warning('duplicate log file configuration') - LOG_FILE_FP = os.path.abspath(os.path.expanduser(fpath)) + LOG_FILE_FP = fpath import atexit atexit.register(_savelogf) -- 2.7.4