From: Jeremy Stanley Date: Sat, 27 Oct 2018 20:52:04 +0000 (+0000) Subject: Try to make missing pidfile and logfile parent dir X-Git-Tag: 0.0.1~44 X-Git-Url: https://mudpy.org/gitweb?a=commitdiff_plain;h=41a4d11fc1fa4d9aa801c879c7464bd0de6defcc;p=mudpy.git Try to make missing pidfile and logfile parent dir Rather than assume the path to a specified pidfile or logfile already exists, try to make it before opening the file for writing. This solves an issue with `tox -e debug` raising FileNotFoundError when trying to open the logfile. Remove the mkdir() call in the selftest setup so that this gets exercised properly. --- diff --git a/mudpy/misc.py b/mudpy/misc.py index 7698e81..f4168ee 100644 --- a/mudpy/misc.py +++ b/mudpy/misc.py @@ -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() diff --git a/mudpy/tests/selftest.py b/mudpy/tests/selftest.py index c3c5dea..40ea0f3 100644 --- a/mudpy/tests/selftest.py +++ b/mudpy/tests/selftest.py @@ -347,7 +347,6 @@ def start_service(config): os.remove(f.name) for d in ("data", "var"): shutil.rmtree(d, ignore_errors=True) - os.mkdir("var") # Start the service and wait for it to be ready for connections service = subprocess.Popen(("mudpy", config),