← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~raoul-snyman/openlp/config into lp:openlp

 

Raoul Snyman has proposed merging lp:~raoul-snyman/openlp/config into lp:openlp.

Requested reviews:
    openlp.org Core (openlp-core)

This will mean some data directory changes, but we can handle that ;-)
-- 
https://code.launchpad.net/~raoul-snyman/openlp/config/+merge/7072
Your team openlp.org Core is subscribed to branch lp:openlp.
=== modified file 'openlp/core/utils/confighelper.py'
--- openlp/core/utils/confighelper.py	2009-01-05 12:33:15 +0000
+++ openlp/core/utils/confighelper.py	2009-06-04 16:53:49 +0000
@@ -2,7 +2,7 @@
 # vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
 """
 OpenLP - Open Source Lyrics Projection
-Copyright (c) 2008 Raoul Snyman
+Copyright (c) 2008-2009 Raoul Snyman
 Portions copyright (c) 2008 Martin Thompson, Tim Bentley
 
 This program is free software; you can redistribute it and/or modify it under
@@ -19,26 +19,32 @@
 """
 
 import os
+from openlp.core.utils.registry import Registry
 
 class ConfigHelper(object):
     """
     Utility Helper to allow classes to find directories in a standard manner.
     """
+    __registry__ = None
+
     @staticmethod
     def get_data_path():
-        if os.name == 'nt':
+        if os.name == u'nt':
             # ask OS for path to application data, set on Windows XP and Vista
-            appdata = os.getenv('APPDATA')
-            default = os.path.join(appdata, u'.openlp', u'data')
+            path = os.path.join(os.getenv(u'APPDATA'), u'openlp', u'data')
+        elif os.name == u'mac':
+            path = os.path.join(os.getenv(u'HOME'), u'Library',
+                u'Application Support', u'openlp', u'Data')
         else:
-            default = os.path.expanduser(u'~/.openlp/data')
-
+            try:
+                from xdg import BaseDirectory
+                path = os.path.join(BaseDirectory.xdg_data_home, u'openlp')
+            except ImportError:
+                path = os.path.join(os.getenv(u'HOME'), u'.openlp', u'data')
         reg = ConfigHelper.get_registry()
-        path = ConfigHelper.get_config('main', 'data path', default)
-
+        #path = ConfigHelper.get_config('main', 'data path', path)
         if not os.path.exists(path):
             os.makedirs(path)
- 
         return path
 
     @staticmethod
@@ -69,13 +75,18 @@
         This static method loads the appropriate registry class based on the
         current operating system, and returns an instantiation of that class.
         """
-        reg = None
-        if os.name == 'nt':
-            #from winregistry import WinRegistry
-            #reg = WinRegistry(r'\Software\openlp')
-            from linregistry import LinRegistry
-            reg = LinRegistry(os.path.join(os.getenv('APPDATA'), '.openlp'))
-        else:
-            from linregistry import LinRegistry
-            reg = LinRegistry(os.path.join(os.getenv('HOME'), '.openlp'))
-        return reg
+        if ConfigHelper.__registry__ is None:
+            config_path = u''
+            if os.name == u'nt':
+                config_path = os.path.join(os.getenv(u'APPDATA'), u'openlp')
+            elif os.name == u'mac':
+                config_path = os.path.join(os.getenv(u'HOME'), u'Library',
+                    u'Application Support', u'openlp')
+            else:
+                try:
+                    from xdg import BaseDirectory
+                    config_path = os.path.join(BaseDirectory.xdg_config_home, u'openlp')
+                except ImportError:
+                    config_path = os.path.join(os.getenv(u'HOME'), u'.openlp')
+            ConfigHelper.__registry__ = Registry(config_path)
+        return ConfigHelper.__registry__

=== renamed file 'openlp/core/utils/linregistry.py' => 'openlp/core/utils/registry.py'
--- openlp/core/utils/linregistry.py	2009-03-15 19:31:33 +0000
+++ openlp/core/utils/registry.py	2009-06-04 16:53:49 +0000
@@ -20,12 +20,11 @@
 import os
 import sys
 from ConfigParser import SafeConfigParser
-from openlp.core.utils import Registry
 
-class LinRegistry(Registry):
+class Registry(object):
     """
-    The LinRegistry class is a high-level class for working with Linux and
-    Unix configurations.
+    The Registry class is a high-level class for working with a configuration
+    file.
     """
     def __init__(self, dir):
         self.config = SafeConfigParser()
@@ -100,7 +99,6 @@
         try:
             if not os.path.exists(os.path.dirname(self.file_name)):
                 os.makedirs(os.path.dirname(self.file_name))
-
             file_handle = open(self.file_name, 'w')
             self.config.write(file_handle)
             close(file_handle)

=== removed file 'openlp/core/utils/registry.py'
--- openlp/core/utils/registry.py	2008-12-03 08:51:35 +0000
+++ openlp/core/utils/registry.py	1970-01-01 00:00:00 +0000
@@ -1,71 +0,0 @@
-# -*- coding: utf-8 -*-
-# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
-"""
-OpenLP - Open Source Lyrics Projection
-Copyright (c) 2008 Raoul Snyman
-Portions copyright (c) 2008 Martin Thompson, Tim Bentley
-
-This program is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free Software
-Foundation; version 2 of the License.
-
-This program is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
-PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License along with
-this program; if not, write to the Free Software Foundation, Inc., 59 Temple
-Place, Suite 330, Boston, MA 02111-1307 USA
-"""
-
-class Registry(object):
-    """
-    The Registry class is a generic class for the accessing configurations.
-    """
-    def __init__(self):
-        """
-        Initialise the Registry object. Override this to add custom initialisation.
-        """
-        pass
-
-    def has_value(self, section, key):
-        """
-        Check if a value exists.
-        """
-        pass
-
-    def get_value(self, section, key, default=None):
-        """
-        Get a single value from the registry.
-        """
-        pass
-
-    def set_value(self, section, key, value):
-        """
-        Set a single value in the registry.
-        """
-        pass
-
-    def delete_value(self, section, key):
-        """
-        Delete a single value from the registry.
-        """
-        pass
-
-    def has_section(self, section):
-        """
-        Check if a section exists.
-        """
-        return False
-
-    def create_section(self, section):
-        """
-        Create a new section in the registry.
-        """
-        pass
-
-    def delete_section(self, section):
-        """
-        Delete a section (including all values).
-        """
-        pass

=== removed file 'openlp/core/utils/winregistry.py'
--- openlp/core/utils/winregistry.py	2009-01-05 12:31:32 +0000
+++ openlp/core/utils/winregistry.py	1970-01-01 00:00:00 +0000
@@ -1,134 +0,0 @@
-# -*- coding: utf-8 -*-
-# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
-"""
-OpenLP - Open Source Lyrics Projection
-Copyright (c) 2008 Raoul Snyman
-Portions copyright (c) 2008 Martin Thompson, Tim Bentley
-
-This program is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free Software
-Foundation; version 2 of the License.
-
-This program is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
-PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License along with
-this program; if not, write to the Free Software Foundation, Inc., 59 Temple
-Place, Suite 330, Boston, MA 02111-1307 USA
-"""
-import _winreg
-import types
-
-from openlp.core.utils import Registry
-
-class WinRegistry(Registry):
-    """
-    The WinRegistry class is a high-level wrapper class for the Windows registry
-    functions in Python.
-    """
-    def __init__(self, base_key):
-        """
-        Connection to the Windows registry, and save the handle.
-        """
-        self.reg_handle = _winreg.ConnectRegistry(None, _winreg.HKEY_CURRENT_USER)
-        self.base_key = base_key
-        if not self.base_key.endswith('\\'):
-            self.base_key = self.base_key + '\\'
-
-    def has_value(self, section, key):
-        """
-        Check if a key/value exists.
-        """
-        if not self.has_section(section):
-            return False
-        key_handle = _winreg.OpenKey(self.reg_handle, self.base_key + section)
-        try:
-            value, reg_type = _winreg.QueryValueEx(key_handle, key)
-        except EnvironmentError:
-            return False
-        finally:
-            _winreg.CloseKey(key_handle)
-        if reg_type == _winreg.REG_NONE:
-            return False
-        elif reg_type == _winreg.REG_SZ and value == '':
-            return False
-        elif reg_type == _winreg.REG_DWORD and value == 0:
-            return False
-        else:
-            return True
-
-    def get_value(self, section, key, default=None):
-        """
-        Get a single value from the Windows registry.
-        """
-        if not self.has_value(section, key):
-            return default
-        else:
-            key_handle = _winreg.OpenKey(self.reg_handle, self.base_key + section)
-            try:
-                value = _winreg.QueryValueEx(key_handle, key)[0]
-            except EnvironmentError:
-                value = default
-            finally:
-                _winreg.CloseKey(key_handle)
-            return value
-
-    def set_value(self, section, key, value):
-        """
-        Set a single value in the Windows registry.
-        """
-        reg_type = _winreg.REG_BINARY
-        if type(value) is types.StringType:
-            reg_type = _winreg.REG_SZ
-        elif type(value) is types.IntType:
-            reg_type = _winreg.REG_DWORD
-        key_handle = _winreg.OpenKey(self.reg_handle, self.base_key + section)
-        _winreg.SetValueEx(key_handle, key, 0, reg_type, value)
-        _winreg.CloseKey(key_handle)
-
-    def delete_value(self, section, key):
-        """
-        Delete a value from the Windows registry.
-        """
-        key_handle = _winreg.OpenKey(self.reg_handle, self.base_key + section)
-        _winreg.DeleteValue(key_handle, key)
-        _winreg.CloseKey(key_handle)
-
-    def has_section(self, section):
-        """
-        Check if a section exists.
-        """
-        key_handle = None
-        try:
-            key_handle = _winreg.OpenKey(self.reg_handle, self.base_key + section)
-        except EnvironmentError:
-            return False
-        finally:
-            if key_handle is None:
-                return False
-            _winreg.CloseKey(key_handle)
-            return True
-
-    def create_section(self, section):
-        """
-        Create a new section in the Windows registry.
-        """
-        try:
-            _winreg.CreateKey(self.reg_handle, self.base_key + section)
-            return True
-        except EnvironmentError:
-            return False
-
-    def delete_section(self, section):
-        key_handle = None
-        try:
-            key_handle = _winreg.OpenKey(self.reg_handle, self.base_key)
-            _winreg.DeleteKey(key_handle, section)
-        except EnvironmentError:
-            return False
-        finally:
-            if key_handle is None:
-                return False
-            _winreg.CloseKey(key_handle)
-            return True


Follow ups