[pitivi: 2/94] Make the XDG dirs more robust



commit 7958ef99c7ab9bc7d19d2800e0f34c74541031c7
Author: Jean-FranÃois Fortin Tam <nekohayo gmail com>
Date:   Thu Aug 25 19:59:00 2011 -0400

    Make the XDG dirs more robust

 pitivi/discoverer.py |   11 +----------
 pitivi/settings.py   |   30 ++++++++++--------------------
 pitivi/ui/preset.py  |    2 +-
 3 files changed, 12 insertions(+), 31 deletions(-)
---
diff --git a/pitivi/discoverer.py b/pitivi/discoverer.py
index 8fcde3f..74a7b7b 100644
--- a/pitivi/discoverer.py
+++ b/pitivi/discoverer.py
@@ -526,19 +526,10 @@ class Discoverer(Signallable, Loggable):
         return tmp
 
     def _getThumbnailFilenameFromPad(self, pad):
-        base = xdg_cache_home()
         md5sum = hashlib.md5()
         md5sum.update(self.current_uri)
         name = md5sum.hexdigest() + '.png'
-        directory = os.path.join(base, "pitivi")
-        try:
-            os.makedirs(directory)
-        except OSError, e:
-            # 17 = file exists
-            if e.errno != 17:
-                raise
-        filename = os.path.join(base, "pitivi", name)
-
+        filename = os.path.join(xdg_cache_home(), name)
         return filename
 
     def _videoPadSeekCb(self, pad):
diff --git a/pitivi/settings.py b/pitivi/settings.py
index 1df969f..e8b18f0 100644
--- a/pitivi/settings.py
+++ b/pitivi/settings.py
@@ -105,15 +105,18 @@ def get_env_dirs(var, default):
 
 
 def xdg_config_home(autocreate=True):
-    return get_dir(xdg_dirs.xdg_config_home, autocreate)
+    """Get the directory for storing the user's pitivi configuration"""
+    return get_dir(os.path.join(xdg_dirs.xdg_config_home, "pitivi"), autocreate)
 
 
 def xdg_data_home(autocreate=True):
-    return get_dir(xdg_dirs.xdg_data_home, autocreate)
+    """Get the directory for storing the user's data: presets, plugins, etc."""
+    return get_dir(os.path.join(xdg_dirs.xdg_data_home, "pitivi"), autocreate)
 
 
 def xdg_cache_home(autocreate=True):
-    return get_dir(xdg_dirs.xdg_cache_home, autocreate)
+    """Get the user cache directory"""
+    return get_dir(os.path.join(xdg_dirs.xdg_cache_home, "pitivi"), autocreate)
 
 
 def xdg_data_dirs():
@@ -177,9 +180,8 @@ class GlobalSettings(Signallable):
         # This reads the configuration from the user configuration file
 
         try:
-            pitivi_path = self.get_local_settings_path()
-            pitivi_conf_file_path = os.path.join(pitivi_path, "pitivi.conf")
-            self._config.read(pitivi_conf_file_path)
+            conf_file_path = os.path.join(xdg_config_home(), "pitivi.conf")
+            self._config.read(conf_file_path)
 
         except ParsingError:
             return
@@ -213,8 +215,7 @@ class GlobalSettings(Signallable):
                 setattr(self, attrname, value)
 
     def _writeSettingsToConfigurationFile(self):
-        pitivi_path = self.get_local_settings_path()
-        pitivi_conf_file_path = os.path.join(pitivi_path, "pitivi.conf")
+        conf_file_path = os.path.join(xdg_config_home(), "pitivi.conf")
 
         for (section, attrname, typ, key, env_var,
             value) in self.iterAllOptions():
@@ -226,7 +227,7 @@ class GlobalSettings(Signallable):
                 else:
                     self._config.remove_option(section, key)
         try:
-            file = open(pitivi_conf_file_path, 'w')
+            file = open(conf_file_path, 'w')
         except IOError, OSError:
             return
         self._config.write(file)
@@ -240,17 +241,6 @@ class GlobalSettings(Signallable):
         """
         self._writeSettingsToConfigurationFile()
 
-    def get_local_settings_path(self, autocreate=True):
-        """
-        Compute the absolute path to local settings directory
-
-        @param autocreate: create the path if missing
-        @return: the plugin repository path
-        """
-
-        return get_dir(os.path.join(xdg_config_home(autocreate), "pitivi"),
-            autocreate)
-
     def iterAllOptions(self):
         """
         Iterate over all registered options
diff --git a/pitivi/ui/preset.py b/pitivi/ui/preset.py
index ed2cffb..472206e 100644
--- a/pitivi/ui/preset.py
+++ b/pitivi/ui/preset.py
@@ -62,7 +62,7 @@ class PresetManager(object):
         self._ignore_update_requests = False
 
     def _getFilename(self):
-        return os.path.join(xdg_data_home(), "pitivi", self.filename)
+        return os.path.join(xdg_data_home(), self.filename)
 
     def load(self):
         parser = ConfigParser.SafeConfigParser()



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]