[orca] [config] Moved config files to XDG_DATA_HOME



commit 759c61df50e61c92c274cf5a9461945bd267d54b
Author: Juanje Ojeda <jojeda emergya es>
Date:   Mon Jun 21 21:59:43 2010 +0200

    [config] Moved config files to XDG_DATA_HOME
    
    Fix for bgo#596108 - Changed old ~/.orca config directory to XDG_DATA_HOME/orca which is more Freedesktop.org compilant.
    There is a check for the old ~/.orca in case someone has an old configuration. A migration method will be provided for that, but
    until this feature is implemented, the check is needed.

 src/orca/app_prefs.py  |   26 ++++++++++++++------------
 src/orca/orca_prefs.py |   13 +++++++------
 src/orca/settings.py   |   10 +++++++++-
 3 files changed, 30 insertions(+), 19 deletions(-)
---
diff --git a/src/orca/app_prefs.py b/src/orca/app_prefs.py
index e2e3e34..534646f 100644
--- a/src/orca/app_prefs.py
+++ b/src/orca/app_prefs.py
@@ -57,8 +57,8 @@ class OrcaPrefs(orca_prefs.OrcaPrefs):
         self.appScript = appScript
 
     def _writeKeyBindingsPreamble(self, prefs):
-        """Writes the preamble to the  ~/.orca/app-settings/<APPNAME>.py
-        keyBindings section."""
+        """Writes the preamble to the
+        XDG_DATA_HOME/orca/app-settings/<APPNAME>.py keyBindings section."""
 
         prefs.writelines("\n")
         prefs.writelines("# Set up a user key-bindings profile\n")
@@ -66,8 +66,8 @@ class OrcaPrefs(orca_prefs.OrcaPrefs):
         prefs.writelines('def overrideAppKeyBindings(script, keyB):\n')
 
     def _writeAppKeyBindingsPostamble(self, prefs, appName, appScript):
-        """Writes the postamble to the ~/.orca/app-settings/<APPNAME>.py
-        keyBindings section.
+        """Writes the postamble to the
+        XDG_DATA_HOME/orca/app-settings/<APPNAME>.py keyBindings section.
 
         Arguments:
         - prefs: file handle for application preferences.
@@ -94,8 +94,8 @@ class OrcaPrefs(orca_prefs.OrcaPrefs):
         self._writeAppKeyBindingsPostamble(prefs, appName, appScript)
 
     def _writePronunciationsPreamble(self, prefs):
-        """Writes the preamble to the  ~/.orca/app-settings/<APPNAME>.py
-        pronunciations section."""
+        """Writes the preamble to the
+        XDG_DATA_HOME/orca/app-settings/<APPNAME>.py pronunciations section."""
 
         prefs.writelines("\n")
         prefs.writelines("# User customized application specific ")
@@ -106,8 +106,8 @@ class OrcaPrefs(orca_prefs.OrcaPrefs):
                     'def overridePronunciations(script, pronunciations):\n')
 
     def _writePronunciationsPostamble(self, prefs):
-        """Writes the postamble to the ~/.orca/app-settings/<APPNAME>.py
-        pronunciations section."""
+        """Writes the postamble to the
+        XDG_DATA_HOME/orca/app-settings/<APPNAME>.py pronunciations section."""
 
         prefs.writelines('    return pronunciations')
         prefs.writelines("\n\n")
@@ -117,7 +117,7 @@ class OrcaPrefs(orca_prefs.OrcaPrefs):
 
     def _writePronunciation(self, prefs, word, value):
         """Write out a single pronunciation entry to the
-        ~/.orca/app-settings/<APPNAME>.py settings file.
+        XDG_DATA_HOME/orca/app-settings/<APPNAME>.py settings file.
 
         Arguments:
         - prefs: file handle for application specific preferences.
@@ -142,7 +142,8 @@ class OrcaPrefs(orca_prefs.OrcaPrefs):
         self._writePronunciationsPostamble(prefs)
 
     def _writeAppPreferencesPreamble(self, prefs, appName):
-        """Writes the preamble to the ~/.orca/app-settings/<APPNAME>.py file.
+        """Writes the preamble to the
+        XDG_DATA_HOME/orca/app-settings/<APPNAME>.py file.
 
         Arguments:
         - prefs: file handle for application preferences.
@@ -163,7 +164,8 @@ class OrcaPrefs(orca_prefs.OrcaPrefs):
         prefs.writelines("\n")
 
     def _writeAppPreferencesPostamble(self, prefs, appName):
-        """Writes the postamble to the ~/.orca/app-settings/<APPNAME>.py file.
+        """Writes the postamble to the
+        XDG_DATA_HOME/orca/app-settings/<APPNAME>.py file.
 
         Arguments:
         - prefs: file handle for application preferences.
@@ -191,7 +193,7 @@ class OrcaPrefs(orca_prefs.OrcaPrefs):
 
         oldPrefsDict = orca_prefs.readPreferences()
 
-        # Write ~/.orca/app-settings/<APPNAME>.py
+        # Write XDG_DATA_HOME/orca/app-settings/<APPNAME>.py
         #
         orcaDir = settings.userPrefsDir
         orcaSettingsDir = os.path.join(orcaDir, "app-settings")
diff --git a/src/orca/orca_prefs.py b/src/orca/orca_prefs.py
index fae2b03..b47cd5a 100644
--- a/src/orca/orca_prefs.py
+++ b/src/orca/orca_prefs.py
@@ -652,7 +652,7 @@ class OrcaPrefs:
         self._writeKeyBindingsPostamble(prefs)
 
     def _writePronunciationsPreamble(self, prefs):
-        """Writes the preamble to the  ~/.orca/user-settings.py
+        """Writes the preamble to the  XDG_DATA_HOME/orca/user-settings.py
         pronunciations section."""
 
         prefs.writelines("\n")
@@ -664,7 +664,7 @@ class OrcaPrefs:
 
     def _writePronunciation(self, prefs, word, value):
         """Write out a single pronunciation entry to the 
-        ~/.orca/user-setting.py settings file.
+        XDG_DATA_HOME/orca/user-setting.py settings file.
 
         Arguments:
         - prefs: file handle for user preferences.
@@ -708,12 +708,13 @@ class OrcaPrefs:
         """Creates the directories and standard files to hold user 
         preferences."""
 
-        # Set up the user's preferences directory (~/.orca by default).
+        # Set up the user's preferences directory
+        # (XDG_DATA_HOME/orca by default).
         #
         orcaDir = settings.userPrefsDir
         self._createDir(orcaDir)
 
-        # Set up ~/.orca/orca-scripts as a Python package
+        # Set up XDG_DATA_HOME/orca/orca-scripts as a Python package
         #
         orcaScriptDir = os.path.join(orcaDir, "orca-scripts")
         self._createDir(orcaScriptDir)
@@ -721,7 +722,7 @@ class OrcaPrefs:
         if not os.path.exists(initFile):
             os.close(os.open(initFile, os.O_CREAT, 0700))
 
-        # Set up ~/.orca/app-settings as a Python package.
+        # Set up XDG_DATA_HOME/orca/app-settings as a Python package.
         #
         orcaSettingsDir = os.path.join(orcaDir, "app-settings")
         self._createDir(orcaSettingsDir)
@@ -821,7 +822,7 @@ class OrcaPrefs:
 
         self._setupPreferencesDirs()
 
-        # Write ~/.orca/user-settings.py
+        # Write XDG_DATA_HOME/orca/user-settings.py
         #
         orcaDir = settings.userPrefsDir
         prefs = open(os.path.join(orcaDir, "user-settings.py"), "w")
diff --git a/src/orca/settings.py b/src/orca/settings.py
index 88d3206..58edc28 100644
--- a/src/orca/settings.py
+++ b/src/orca/settings.py
@@ -848,11 +848,19 @@ learnModeEnabled        = False
 #
 listShortcutsModeEnabled = False
 
-# The location of the user's preferences. By default this is ~/.orca.
+# The location of the user's preferences. By default this is
+# $XDG_DATA_HOME/orca.
 # It can be overridden by the Orca -d command line option.
+# For migration reasons the old location (~/.orca) will be
+# checking. If this path exists it will be the location.
 #
 userPrefsDir = os.path.join(os.environ["HOME"], ".orca")
 
+if not os.path.exists(userPrefsDir):
+    from xdg.BaseDirectory import xdg_data_home
+
+    userPrefsDir = os.path.join(xdg_data_home, "orca")
+
 # Assists with dealing with CORBA COMM_FAILURES.  A failure doesn't
 # always mean an object disappeared - there just might be a network
 # glitch.  So, on COMM_FAILURES, we might retry a few times before



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