Module: deluge
Branch: 1.3-stable
Commit: 83283cdcf38fd20d2ab1b8981fcee7004f477c3d

Author: Calum Lind <[email protected]>
Date:   Thu May 26 01:11:09 2011 +0100

Add XDG_DOWNLOAD_DIR for default download folder #1788

---

 deluge/common.py |   22 +++++++++++++++++-----
 1 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/deluge/common.py b/deluge/common.py
index 50a9417..d24de40 100644
--- a/deluge/common.py
+++ b/deluge/common.py
@@ -165,6 +165,18 @@ def get_default_download_dir():
     if windows_check():
         return os.path.expanduser("~")
     else:
+        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:
+                        download_dir = os.path.expandvars(\
+                                        
line.partition("=")[2].rstrip().strip('"'))
+                        if os.path.isdir(download_dir):
+                            return download_dir
+        except IOError:
+            pass
+
         return os.environ.get("HOME")
 
 def windows_check():
@@ -527,7 +539,7 @@ def path_join(*parts):
             path += '/' + part
     return path
 
-XML_ESCAPES = ( 
+XML_ESCAPES = (
     ('&', '&amp;'),
     ('<', '&lt;'),
     ('>', '&gt;'),
@@ -536,9 +548,9 @@ XML_ESCAPES = (
 )
 
 def xml_decode(string):
-    """ 
+    """
     Unescape a string that was previously encoded for use within xml.
-    
+
     :param string: The string to escape
     :type string: string
     :returns: The unescaped version of the string.
@@ -549,9 +561,9 @@ def xml_decode(string):
     return string
 
 def xml_encode(string):
-    """ 
+    """
     Escape a string for use within an xml element or attribute.
-    
+
     :param string: The string to escape
     :type string: string
     :returns: An escaped version of the string.

-- 
You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en.

Reply via email to