[accerciser] Fix for bug #674884 - Use XDG base directory instead of $HOME



commit ba900faf28c3dcefc72db094847e975c984e299d
Author: William Jon McCann <jmccann redhat com>
Date:   Mon May 14 00:20:27 2012 +0200

    Fix for bug #674884 - Use XDG base directory instead of $HOME

 plugins/validate.py                         |    3 +-
 src/accerciser.in                           |   28 ++++++++++++++++++++++++--
 src/lib/accerciser/bookmarks.py             |    3 +-
 src/lib/accerciser/plugin/plugin_manager.py |    5 ++-
 4 files changed, 32 insertions(+), 7 deletions(-)
---
diff --git a/plugins/validate.py b/plugins/validate.py
index a228d43..6412ac2 100644
--- a/plugins/validate.py
+++ b/plugins/validate.py
@@ -14,6 +14,7 @@ import gi
 
 from gi.repository import Gtk as gtk
 from gi.repository import GObject
+from gi.repository import GLib
 
 import os
 import traceback
@@ -26,7 +27,7 @@ from accerciser.i18n import _, N_, DOMAIN
 import pyatspi
 
 UI_FILE = os.path.join(os.path.dirname(__file__), 'validate.ui')
-USER_SCHEMA_PATH = os.path.join(os.environ['HOME'], '.accerciser', 
+USER_SCHEMA_PATH = os.path.join(GLib.get_user_data_dir(), 'accerciser',
                                 'plugindata', 'validate')
 SYS_SCHEMA_PATH = os.path.join(sys.prefix, 'share', 'accerciser', 
                                'plugindata', 'validate')
diff --git a/src/accerciser.in b/src/accerciser.in
index 980ef73..572218a 100755
--- a/src/accerciser.in
+++ b/src/accerciser.in
@@ -13,12 +13,23 @@ available under the terms of the BSD which accompanies this distribution, and
 is available at U{http://www.opensource.org/licenses/bsd-license.php}
 '''
 import gi
+from gi.repository import GLib
 
 import sys, os
+
+def migrate_data (old_path, new_path):
+  if os.path.exists(old_path) and not os.path.exists(new_path):
+    mask = os.umask(077)
+    try:
+      os.renames(old_path, new_path)
+    except:
+      print "Unable to migrate ", old_path
+    os.umask(mask)
+
 # Load gail module no matter what the desktop-wide settings are.
 os.environ['GTK_MODULES'] = 'gail:atk-bridge'
-# make the ~/.accerciser directory part of the path to aid user imports
-sys.path.append(os.path.join(os.environ['HOME'], '.accerciser'))
+# make the accerciser directory part of the path to aid user imports
+sys.path.append(os.path.join(GLib.get_user_config_dir(), 'accerciser'))
 # We can't rely on prefix if we're installed by relocated RPM. Instead, we 
 # use __file__ and for now hope that lib is relative to bin.
 sys.prefix = '@prefix@'
@@ -49,6 +60,17 @@ except Exception:
 else:
   # TODO: REVIEW
   gtk.Window.set_default_icon_list(icons)
-  
+
+# Try migration
+old_plugin_dir = os.path.join(os.environ['HOME'], '.accerciser', 'plugins')
+new_plugin_dir = os.path.join(GLib.get_user_data_dir(), 'accerciser', 'plugins')
+migrate_data(old_plugin_dir, new_plugin_dir)
+old_bookmarks = os.path.join(os.environ['HOME'], '.accerciser', 'bookmarks.xml')
+new_bookmarks = os.path.join(GLib.get_user_config_dir(), 'accerciser', 'bookmarks.xml')
+migrate_data(old_bookmarks, new_bookmarks)
+old_plugindata = os.path.join(os.environ['HOME'], '.accerciser', 'plugindata')
+new_plugindata = os.path.join(GLib.get_user_data_dir(), 'accerciser', 'plugindata')
+
+
 import accerciser
 accerciser.main()
diff --git a/src/lib/accerciser/bookmarks.py b/src/lib/accerciser/bookmarks.py
index 35c0ea5..11724f1 100644
--- a/src/lib/accerciser/bookmarks.py
+++ b/src/lib/accerciser/bookmarks.py
@@ -1,3 +1,4 @@
+from gi.repository import GLib
 from gi.repository import Gtk as gtk
 from gi.repository import Atk as atk
 
@@ -14,7 +15,7 @@ COL_APP = 1
 COL_PATH = 2
 _BM_ATTRIBS = ['title', 'app', 'path']
 
-BOOKMARKS_PATH = os.path.join(os.environ['HOME'], '.accerciser')
+BOOKMARKS_PATH = os.path.join(GLib.get_user_config_dir(), 'accerciser')
 BOOKMARKS_FILE = 'bookmarks.xml'
 
 class BookmarkStore(gtk.ListStore):
diff --git a/src/lib/accerciser/plugin/plugin_manager.py b/src/lib/accerciser/plugin/plugin_manager.py
index 0db1df3..f0b9e96 100644
--- a/src/lib/accerciser/plugin/plugin_manager.py
+++ b/src/lib/accerciser/plugin/plugin_manager.py
@@ -13,6 +13,7 @@ is available at U{http://www.opensource.org/licenses/bsd-license.php}
 
 import gi
 
+from gi.repository import GLib
 from gi.repository import Gtk as gtk
 from gi.repository.Gio import Settings as GSettings
 
@@ -108,8 +109,8 @@ class PluginManager(gtk.ListStore, Tools):
     @rtype: tuple
     '''
     plugin_file_list = []
-    plugin_dir_local = os.path.join(os.environ['HOME'], 
-                                    '.accerciser', 'plugins')
+    plugin_dir_local = os.path.join(GLib.get_user_data_dir(),
+                                    'accerciser', 'plugins')
     plugin_dir_global = os.path.join(sys.prefix, 'share',
                                      'accerciser', 'plugins')
     for plugin_dir in (plugin_dir_local, plugin_dir_global):



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