fix logfile specified a directory
authorHuanhuan Li <huanhuanx.li@intel.com>
Thu, 8 Nov 2012 20:13:27 +0000 (15:13 -0500)
committerGui Chen <gui.chen@intel.com>
Wed, 12 Dec 2012 11:33:44 +0000 (19:33 +0800)
when run mic with options '--logfile=dir', traceback shows

mic/creator.py
mic/msger.py

index 9e57841..8d4bd54 100644 (file)
@@ -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:
index 2252786..9afc85b 100644 (file)
@@ -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)