[ocrfeeder] Use the XDG configuration directory



commit f5abc569ba46737b8c996c977e7468030bd50317
Author: Joaquim Rocha <me joaquimrocha com>
Date:   Sun Dec 21 00:04:15 2014 +0000

    Use the XDG configuration directory
    
    Use this standard directory instead of ".ocrfeeder".
    Also automatically copies the current configuration to the new folder
    if the latter does not exist.

 src/ocrfeeder/util/configuration.py |   14 ++++++++++++--
 src/ocrfeeder/util/constants.py.in  |    2 ++
 2 files changed, 14 insertions(+), 2 deletions(-)
---
diff --git a/src/ocrfeeder/util/configuration.py b/src/ocrfeeder/util/configuration.py
index 8e9134d..bb594c5 100644
--- a/src/ocrfeeder/util/configuration.py
+++ b/src/ocrfeeder/util/configuration.py
@@ -20,7 +20,7 @@
 
 from ocrfeeder.feeder.ocrEngines import Engine
 from ocrfeeder.util.lib import getExecPath, debug
-from ocrfeeder.util.constants import OCRFEEDER_COMPACT_NAME
+from ocrfeeder.util.constants import OCRFEEDER_COMPACT_NAME, USER_CONFIG_DIR
 import tempfile
 import shutil
 from xml.dom import minidom
@@ -128,7 +128,8 @@ class ConfigurationManager(object):
     conf = dict(DEFAULTS)
 
     def __init__(self):
-        self.user_configuration_folder = os.path.expanduser('~/.ocrfeeder')
+        self.user_configuration_folder = USER_CONFIG_DIR
+        self.migrateOldConfigFolder()
         self.user_engines_folder = os.path.join(self.user_configuration_folder, 'engines')
         self.makeUserConfigurationFolder()
         self.has_unpaper = self.getDefault(self.UNPAPER)
@@ -396,6 +397,15 @@ class ConfigurationManager(object):
             debug('Error when removing the temporary folder: ' + \
                   self.TEMPORARY_FOLDER)
 
+    def migrateOldConfigFolder(self):
+        old_config_folder = os.path.expanduser('~/.ocrfeeder')
+        if os.path.exists(old_config_folder) and \
+           not os.path.exists(self.user_configuration_folder):
+            shutil.copytree(old_config_folder, self.user_configuration_folder)
+            debug('Migrated old configuration directory "%s" to the '
+                  'new one: "%s"' %
+                  (old_config_folder, self.user_configuration_folder))
+
     text_fill = property(getTextFill,
                          setTextFill)
     image_fill = property(getImageFill,
diff --git a/src/ocrfeeder/util/constants.py.in b/src/ocrfeeder/util/constants.py.in
index 533c507..e8aaf87 100644
--- a/src/ocrfeeder/util/constants.py.in
+++ b/src/ocrfeeder/util/constants.py.in
@@ -21,6 +21,7 @@
 import sys
 import os
 import locale
+from gi.repository import GLib
 
 OCRFEEDER_STUDIO_NAME = 'OCRFeeder'
 OCRFEEDER_COMPACT_NAME = 'ocrfeeder'
@@ -47,6 +48,7 @@ GPL_STATEMENT = """
 OCRFEEDER_STUDIO_COMMENTS = 'The complete OCR suite.'
 
 # DIRECTORIES
+USER_CONFIG_DIR = os.path.join(GLib.get_user_config_dir(), OCRFEEDER_COMPACT_NAME)
 DEFAULT_SYSTEM_APP_DIR = os.path.join('@prefix@', 'share', 'ocrfeeder')
 APP_DIR = DEFAULT_SYSTEM_APP_DIR
 RESOURCES_DIR = APP_DIR


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