From 35094ae1cec0a51815dccec3528014bbfd9b9ac9 Mon Sep 17 00:00:00 2001 From: Richard Poettler Date: Wed, 8 Jul 2015 10:45:37 +0200 Subject: [PATCH 1/2] moved dublicate code into one method --- config.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/config.py b/config.py index c5d46cdeb8..f93c36c708 100644 --- a/config.py +++ b/config.py @@ -32,6 +32,10 @@ saveDB = None gameDB = None +def __createSavePath(): + if not os.path.exists(savePath): + os.mkdir(savePath) + def defPaths(): global pyfaPath global savePath @@ -69,15 +73,13 @@ def defPaths(): # Redirect stderr to file if we're requested to do so stderrToFile = getattr(configforced, "stderrToFile", None) if stderrToFile is True: - if not os.path.exists(savePath): - os.mkdir(savePath) + __createSavePath() sys.stderr = open(os.path.join(savePath, "error_log.txt"), "w") # Same for stdout stdoutToFile = getattr(configforced, "stdoutToFile", None) if stdoutToFile is True: - if not os.path.exists(savePath): - os.mkdir(savePath) + __createSavePath() sys.stdout = open(os.path.join(savePath, "output_log.txt"), "w") # Static EVE Data from the staticdata repository, should be in the staticdata From f08dc975769c851d936a9e8a094c98a1340892b4 Mon Sep 17 00:00:00 2001 From: Richard Poettler Date: Wed, 8 Jul 2015 10:47:14 +0200 Subject: [PATCH 2/2] logging crashes if the directory doesn't exist --- config.py | 1 + 1 file changed, 1 insertion(+) diff --git a/config.py b/config.py index f93c36c708..4d019590ec 100644 --- a/config.py +++ b/config.py @@ -63,6 +63,7 @@ def defPaths(): format = '%(asctime)s %(name)-24s %(levelname)-8s %(message)s' logging.basicConfig(format=format, level=logLevel) + __createSavePath() handler = logging.handlers.RotatingFileHandler(os.path.join(savePath, "log.txt"), maxBytes=1000000, backupCount=3) formatter = logging.Formatter(format) handler.setFormatter(formatter)