From 1edc4bfe73f7d9530ec348c90beabcfe213ae2a7 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Sun, 17 Aug 2008 00:56:29 +0000 Subject: [PATCH] Fix-up the main startup code a bit so that Windows is always logging to a file and config folders are properly created for the daemon --- deluge/main.py | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/deluge/main.py b/deluge/main.py index b1ad84b0a..ed64b4146 100644 --- a/deluge/main.py +++ b/deluge/main.py @@ -61,10 +61,19 @@ def start_ui(): if options.config: if not os.path.exists(options.config): - os.makedirs(options.config) + # Try to create the config folder if it doesn't exist + try: + os.makedirs(options.config) + except Exception, e: + pass else: if not os.path.exists(deluge.common.get_default_config_dir()): os.makedirs(deluge.common.get_default_config_dir()) + + # Always log to a file in Windows + if deluge.common.windows_check() and not options.logfile: + options.logfile = "deluge.log" + if options.logfile: if options.config: logfile = os.path.join(options.config, options.logfile) @@ -108,6 +117,17 @@ def start_daemon(): # Get the options and args from the OptionParser (options, args) = parser.parse_args() + if options.config: + if not os.path.exists(options.config): + # Try to create the config folder if it doesn't exist + try: + os.makedirs(options.config) + except Exception, e: + pass + else: + if not os.path.exists(deluge.common.get_default_config_dir()): + os.makedirs(deluge.common.get_default_config_dir()) + # If the donot daemonize is set, then we just skip the forking if not options.donot and not deluge.common.windows_check(): if os.fork() == 0: @@ -122,14 +142,29 @@ def start_daemon(): config_dir = deluge.common.get_default_config_dir() logfile = os.path.join(config_dir, "deluged.log") - sys.stdout = open(logfile, "w") + sys.stdout = open(logfile, "wb") sys.stderr = sys.stdout sys.stdin = None else: os._exit(0) else: os._exit(0) - + + # Windows check, we log to the config folder by default + if not options.donot and deluge.common.windows_check(): + if options.logfile: + logfile = options.logfile + else: + if options.config: + logfile = os.path.join(options.config, "deluged.log") + else: + config_dir = deluge.common.get_default_config_dir() + logfile = os.path.join(config_dir, "deluged.log") + + sys.stdout = open(logfile, "wb") + sys.stderr = sys.stdout + sys.stdin = None + from deluge.core.daemon import Daemon Daemon(options, args)