changeset 923:e77948faaef3

core: removed default_config: - constants in core.default_config moved to core.constants - removed unused host.getConst and host.setConst - APP_NAME* used where it make sense
author Goffi <goffi@goffi.org>
date Sat, 22 Mar 2014 17:48:10 +0100
parents c897c8d321b3
children 861593a5652b
files src/core/constants.py src/core/default_config.py src/core/sat_main.py src/core/xmpp.py src/memory/memory.py
diffstat 5 files changed, 19 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
--- a/src/core/constants.py	Sat Mar 22 15:34:05 2014 +0100
+++ b/src/core/constants.py	Sat Mar 22 17:48:10 2014 +0100
@@ -19,10 +19,20 @@
 
 
 class Const(object):
+    APP_NAME = u'Salut à Toi'
+    APP_NAME_SHORT = u'SàT'
+    APP_NAME_FULL = u'%s (%s)' % (APP_NAME_SHORT, APP_NAME)
+    APP_VERSION = u'0.4.1D' # Please add 'D' at the end for dev versions
+
+    DEFAULT_CONFIG = {
+        'local_dir': '~/.sat',
+        'media_dir': '/usr/share/sat/media',
+    }
+
     NO_SECURITY_LIMIT = -1
     INDIVIDUAL = "individual"
     GENERAL = "general"
-    SAVEFILE_DATABASE = "/sat.db"
+    SAVEFILE_DATABASE = "sat.db"
     PROF_KEY_NONE = '@NONE@'
     PROF_KEY_DEFAULT = '@DEFAULT@'
     IQ_SET = '/iq[@type="set"]'
--- a/src/core/default_config.py	Sat Mar 22 15:34:05 2014 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,31 +0,0 @@
-#!/usr/bin/python
-# -*- coding: utf-8 -*-
-
-# SAT: a jabber client
-# Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org)
-
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-
-# 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 Affero General Public License for more details.
-
-# You should have received a copy of the GNU Affero General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-CONST = {
-    'client_name': u'SàT (Salut à toi)',
-    'client_version': u'0.4.1D',  # Please add 'D' at the end for dev versions
-    'local_dir': '~/.sat'
-}
-
-### Defaut configuration values ###
-
-default_config = {
-    'local_dir': '~/.sat',
-    'media_dir': '/usr/share/sat/media',
-}
--- a/src/core/sat_main.py	Sat Mar 22 15:34:05 2014 +0100
+++ b/src/core/sat_main.py	Sat Mar 22 17:48:10 2014 +0100
@@ -36,7 +36,6 @@
 import sys
 import os.path
 
-from sat.core.default_config import CONST
 from sat.core import xmpp
 from sat.core import exceptions
 from sat.core.constants import Const as C
@@ -85,32 +84,11 @@
 
     @property
     def __version__(self):
-        return self.getConst('client_version')
+        return C.APP_VERSION
 
     def get_next_id(self):
         return sat_next_id()
 
-    def getConst(self, name):
-        """Return a constant"""
-        try:
-            _const = os.environ['SAT_CONST_%s' % name]
-            if _const:
-                warning(_("Constant %(name)s overrided with [%(value)s]") % {'name': name, 'value': _const})
-                return _const
-        except KeyError:
-            pass
-        if name not in CONST:
-            error(_('Trying to access an undefined constant'))
-            raise Exception
-        return CONST[name]
-
-    def setConst(self, name, value):
-        """Save a constant"""
-        if name in CONST:
-            error(_('Trying to redefine a constant'))
-            raise Exception
-        CONST[name] = value
-
     def __init__(self):
         self._cb_map = {}  # map from callback_id to callbacks
         self._menus = {}  # dynamic menus. key: callback_id, value: menu data (dictionnary)
@@ -131,7 +109,7 @@
         except exceptions.BridgeInitError:
             print (u"Bridge can't be initialised, can't start SàT core") # reactor is not launched yet, so we can't use error log
             sys.exit(1)
-        self.bridge.register("getVersion", lambda: self.getConst('client_version'))
+        self.bridge.register("getVersion", lambda: C.APP_VERSION)
         self.bridge.register("getProfileName", self.memory.getProfileName)
         self.bridge.register("getProfilesList", self.memory.getProfilesList)
         self.bridge.register("getEntityData", lambda _jid, keys, profile: self.memory.getEntityData(jid.JID(_jid), keys, profile))
@@ -273,8 +251,8 @@
             current.fallBack = xmpp.SatFallbackHandler(self)
             current.fallBack.setHandlerParent(current)
 
-            current.versionHandler = xmpp.SatVersionHandler(self.getConst('client_name'),
-                                                            self.getConst('client_version'))
+            current.versionHandler = xmpp.SatVersionHandler(C.APP_NAME_FULL,
+                                                            C.APP_VERSION)
             current.versionHandler.setHandlerParent(current)
 
             current.identityHandler = xmpp.SatIdentityHandler()
--- a/src/core/xmpp.py	Sat Mar 22 15:34:05 2014 +0100
+++ b/src/core/xmpp.py	Sat Mar 22 17:48:10 2014 +0100
@@ -18,6 +18,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 from sat.core.i18n import _
+from sat.core.constants import Const as C
 from twisted.internet import task, defer
 from twisted.words.protocols.jabber import jid, xmlstream
 from wokkel import client, disco, xmppim, generic, compat, delay, iwokkel
@@ -475,7 +476,7 @@
     implements(iwokkel.IDisco)
 
     def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
-        return [disco.DiscoIdentity(u"client", u"pc", u"Salut à Toi")]
+        return [disco.DiscoIdentity(u"client", u"pc", C.APP_NAME)]
 
     def getDiscoItems(self, requestor, target, nodeIdentifier=''):
         return []
--- a/src/memory/memory.py	Sat Mar 22 15:34:05 2014 +0100
+++ b/src/memory/memory.py	Sat Mar 22 17:48:10 2014 +0100
@@ -28,7 +28,6 @@
 from twisted.words.protocols.jabber import jid
 from sat.core import exceptions
 from sat.core.constants import Const as C
-from sat.core.default_config import default_config
 from sat.memory.sqlite import SqliteStorage
 from sat.memory.persistent import PersistentDict
 from sat.memory.params import Params
@@ -118,9 +117,7 @@
         self.server_features = {}  # used to store discovery's informations
         self.server_identities = {}
         self.config = self.parseMainConf()
-        host.setConst('savefile_database', C.SAVEFILE_DATABASE)
-        database_file = os.path.expanduser(self.getConfig('', 'local_dir') +
-                                           self.host.getConst('savefile_database'))
+        database_file = os.path.expanduser(os.path.join(self.getConfig('', 'local_dir'), C.SAVEFILE_DATABASE))
         self.storage = SqliteStorage(database_file, host.__version__)
         PersistentDict.storage = self.storage
         self.params = Params(host, self.storage)
@@ -133,7 +130,7 @@
 
     def parseMainConf(self):
         """look for main .ini configuration file, and parse it"""
-        _config = SafeConfigParser(defaults=default_config)
+        _config = SafeConfigParser(defaults=C.DEFAULT_CONFIG)
         try:
             _config.read(map(os.path.expanduser, ['/etc/sat.conf', '~/sat.conf', '~/.sat.conf', 'sat.conf', '.sat.conf']))
         except: