diff sat.tac @ 41:d24629c631fc

SàT: new constant management, a local dir (~/.sat) is now used
author Goffi <goffi@goffi.org>
date Sat, 19 Dec 2009 20:32:58 +1100
parents 2e3411a6baad
children daa1f01a5332
line wrap: on
line diff
--- a/sat.tac	Sat Dec 19 18:13:04 2009 +1100
+++ b/sat.tac	Sat Dec 19 20:32:58 2009 +1100
@@ -19,8 +19,11 @@
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
 
-client_name = u'SàT (Salut à toi)'
-client_version = '0.0.1D'   #Please add 'D' at the end for dev versions
+CONST = {
+    'client_name' : u'SàT (Salut à toi)',
+    'client_version' : u'0.0.1D',   #Please add 'D' at the end for dev versions
+    'local_dir' : '~/.sat'
+}
 
 from twisted.application import internet, service
 from twisted.internet import glib2reactor, protocol, task
@@ -250,8 +253,27 @@
     def get_next_id(self):
         return sat_next_id()
 
+    def get_const(self, name):
+        """Return a constant"""
+        if not CONST.has_key(name):
+            error('Trying to access an undefined constant')
+            raise Exception
+        return CONST[name]
+
+    def set_const(self, name, value):
+        """Save a constant"""
+        if CONST.has_key(name):
+            error('Trying to redefine a constant')
+            raise Exception  
+        CONST[name] = value
+    
     def __init__(self):
         #TODO: standardize callback system
+        
+        local_dir = os.path.expanduser(self.get_const('local_dir'))
+        if not os.path.exists(local_dir):
+            os.makedirs(local_dir)
+
         self.__waiting_conf = {}  #callback called when a confirmation is received
         self.__progress_cb_map = {}  #callback called when a progress is requested (key = progress id)
         self.__general_cb_map = {}  #callback called for general reasons (key = name) 
@@ -323,7 +345,8 @@
         self.fallBack = SatFallbackHandler(self)
         self.fallBack.setHandlerParent(self.xmppclient)
 
-        self.versionHandler = generic.VersionHandler(unicode(client_name), client_version)
+        self.versionHandler = generic.VersionHandler(self.get_const('client_name'),
+                                                     self.get_const('client_version'))
         self.versionHandler.setHandlerParent(self.xmppclient)
 
         debug ("setting plugins parents")