Try to make missing pidfile and logfile parent dir
[mudpy.git] / mudpy / misc.py
index 6b24e1b..f4168ee 100644 (file)
@@ -1,8 +1,8 @@
 """Miscellaneous functions for the mudpy engine."""
 
-# Copyright (c) 2004-2018 Jeremy Stanley <fungi@yuggoth.org>. Permission
-# to use, copy, modify, and distribute this software is granted under
-# terms provided in the LICENSE file distributed with this software.
+# Copyright (c) 2004-2018 mudpy authors. Permission to use, copy,
+# modify, and distribute this software is granted under terms
+# provided in the LICENSE file distributed with this software.
 
 import codecs
 import os
@@ -994,6 +994,7 @@ def log(message, level=0):
     if file_name:
         if not os.path.isabs(file_name):
             file_name = os.path.join(universe.startdir, file_name)
+        os.makedirs(os.path.dirname(file_name), exist_ok=True)
         file_descriptor = codecs.open(file_name, "a", "utf-8")
         for line in lines:
             file_descriptor.write(timestamp + " " + line + "\n")
@@ -2389,6 +2390,7 @@ def create_pidfile(universe):
     if file_name:
         if not os.path.isabs(file_name):
             file_name = os.path.join(universe.startdir, file_name)
+        os.makedirs(os.path.dirname(file_name), exist_ok=True)
         file_descriptor = codecs.open(file_name, "w", "utf-8")
         file_descriptor.write(pid + "\n")
         file_descriptor.flush()