From bddfb2a5c68a14a4abc8f211dbb3094652fbd3f8 Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Mon, 3 Feb 2014 12:26:57 +0000 Subject: [PATCH] Change get_default_download_dir to use expanduser as fallback --- deluge/common.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/deluge/common.py b/deluge/common.py index c7f912383..295be98a0 100644 --- a/deluge/common.py +++ b/deluge/common.py @@ -165,21 +165,21 @@ def get_default_download_dir(): :rtype: string """ - if windows_check(): - return os.path.join(os.path.expanduser("~"), 'Downloads') - else: + download_dir = "" + if not windows_check(): from xdg.BaseDirectory import xdg_config_home - userdir_file = os.path.join(xdg_config_home, 'user-dirs.dirs') try: - for line in open(userdir_file, 'r'): - if not line.startswith('#') and 'XDG_DOWNLOAD_DIR' in line: + with open(os.path.join(xdg_config_home, 'user-dirs.dirs'), 'r') as _file: + for line in _file: + if not line.startswith('#') and line.startswith('XDG_DOWNLOAD_DIR'): download_dir = os.path.expandvars(line.partition("=")[2].rstrip().strip('"')) - if os.path.isdir(download_dir): - return download_dir + break except IOError: pass - return os.environ.get("HOME") + if not download_dir: + download_dir = os.path.join(os.path.expanduser("~"), 'Downloads') + return download_dir def windows_check():