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
This commit is contained in:
parent
93826f1ce8
commit
6d768028d1
5 changed files with 19 additions and 64 deletions
|
|
@ -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"]'
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
}
|
||||
|
|
@ -36,7 +36,6 @@ from logging import debug, info, warning, error
|
|||
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 @@ class SAT(service.Service):
|
|||
|
||||
@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 @@ class SAT(service.Service):
|
|||
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 @@ class SAT(service.Service):
|
|||
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()
|
||||
|
|
|
|||
|
|
@ -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 @@ class SatIdentityHandler(XMPPHandler):
|
|||
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 []
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ from twisted.internet import defer, reactor
|
|||
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 @@ class Memory(object):
|
|||
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 @@ class Memory(object):
|
|||
|
||||
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:
|
||||
|
|
|
|||
Loading…
Reference in a new issue