comparison 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
comparison
equal deleted inserted replaced
40:6f0699ba0329 41:d24629c631fc
17 17
18 You should have received a copy of the GNU General Public License 18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. 19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 """ 20 """
21 21
22 client_name = u'SàT (Salut à toi)' 22 CONST = {
23 client_version = '0.0.1D' #Please add 'D' at the end for dev versions 23 'client_name' : u'SàT (Salut à toi)',
24 'client_version' : u'0.0.1D', #Please add 'D' at the end for dev versions
25 'local_dir' : '~/.sat'
26 }
24 27
25 from twisted.application import internet, service 28 from twisted.application import internet, service
26 from twisted.internet import glib2reactor, protocol, task 29 from twisted.internet import glib2reactor, protocol, task
27 glib2reactor.install() 30 glib2reactor.install()
28 31
248 class SAT(service.Service): 251 class SAT(service.Service):
249 252
250 def get_next_id(self): 253 def get_next_id(self):
251 return sat_next_id() 254 return sat_next_id()
252 255
256 def get_const(self, name):
257 """Return a constant"""
258 if not CONST.has_key(name):
259 error('Trying to access an undefined constant')
260 raise Exception
261 return CONST[name]
262
263 def set_const(self, name, value):
264 """Save a constant"""
265 if CONST.has_key(name):
266 error('Trying to redefine a constant')
267 raise Exception
268 CONST[name] = value
269
253 def __init__(self): 270 def __init__(self):
254 #TODO: standardize callback system 271 #TODO: standardize callback system
272
273 local_dir = os.path.expanduser(self.get_const('local_dir'))
274 if not os.path.exists(local_dir):
275 os.makedirs(local_dir)
276
255 self.__waiting_conf = {} #callback called when a confirmation is received 277 self.__waiting_conf = {} #callback called when a confirmation is received
256 self.__progress_cb_map = {} #callback called when a progress is requested (key = progress id) 278 self.__progress_cb_map = {} #callback called when a progress is requested (key = progress id)
257 self.__general_cb_map = {} #callback called for general reasons (key = name) 279 self.__general_cb_map = {} #callback called for general reasons (key = name)
258 self.__private_data = {} #used for internal callbacks (key = id) 280 self.__private_data = {} #used for internal callbacks (key = id)
259 self.plugins = {} 281 self.plugins = {}
321 self.presence.setHandlerParent(self.xmppclient) 343 self.presence.setHandlerParent(self.xmppclient)
322 344
323 self.fallBack = SatFallbackHandler(self) 345 self.fallBack = SatFallbackHandler(self)
324 self.fallBack.setHandlerParent(self.xmppclient) 346 self.fallBack.setHandlerParent(self.xmppclient)
325 347
326 self.versionHandler = generic.VersionHandler(unicode(client_name), client_version) 348 self.versionHandler = generic.VersionHandler(self.get_const('client_name'),
349 self.get_const('client_version'))
327 self.versionHandler.setHandlerParent(self.xmppclient) 350 self.versionHandler.setHandlerParent(self.xmppclient)
328 351
329 debug ("setting plugins parents") 352 debug ("setting plugins parents")
330 for plugin in self.plugins.iteritems(): 353 for plugin in self.plugins.iteritems():
331 if isinstance(plugin[1], XMPPHandler): 354 if isinstance(plugin[1], XMPPHandler):