new plugin gestion
This commit is contained in:
parent
57f0b11a38
commit
6234777d45
|
@ -22,7 +22,10 @@ import threading
|
||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import plugins
|
|
||||||
|
sys.path.append("..")
|
||||||
|
|
||||||
|
import plugins.sock
|
||||||
|
|
||||||
class GajimThread(threading.Thread):
|
class GajimThread(threading.Thread):
|
||||||
def __init__(self, name = None, queueIn = None, queueOut = None):
|
def __init__(self, name = None, queueIn = None, queueOut = None):
|
||||||
|
@ -34,10 +37,8 @@ class GajimThread(threading.Thread):
|
||||||
# END __init__
|
# END __init__
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
#This is VERY bad
|
mod = compile("import plugins.%s" % self.getName(), \
|
||||||
if self.getName() == 'gtkgui':
|
self.getName(), "exec")
|
||||||
plugins.gtkgui.plugin(self.queueIn, self.queueOut)
|
res = eval(mod)
|
||||||
elif self.getName() == 'logger':
|
|
||||||
plugins.logger.plugin(self.queueIn, self.queueOut)
|
|
||||||
# END run
|
# END run
|
||||||
# END GajimThread
|
# END GajimThread
|
||||||
|
|
38
core/core.py
38
core/core.py
|
@ -18,19 +18,20 @@
|
||||||
## GNU General Public License for more details.
|
## GNU General Public License for more details.
|
||||||
##
|
##
|
||||||
|
|
||||||
import socket
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
sys.path.append("..")
|
||||||
import time
|
import time
|
||||||
import string
|
import string
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import plugins
|
|
||||||
import common.hub
|
import common.hub
|
||||||
import common.jabber
|
import common.jabber
|
||||||
import common.optparser
|
import common.optparser
|
||||||
|
|
||||||
log = logging.getLogger('core.core')
|
log = logging.getLogger('core.core')
|
||||||
log.setLevel(logging.DEBUG)
|
log.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
CONFPATH = "~/.gajimrc"
|
CONFPATH = "~/.gajimrc"
|
||||||
|
|
||||||
class GajimCore:
|
class GajimCore:
|
||||||
|
@ -180,21 +181,24 @@ class GajimCore:
|
||||||
# END main
|
# END main
|
||||||
# END GajimCore
|
# END GajimCore
|
||||||
|
|
||||||
|
def loadPlugins(gc):
|
||||||
|
modStr = gc.cfgParser.Core_modules
|
||||||
|
mods = string.split (modStr, ' ')
|
||||||
|
|
||||||
|
for mod in mods:
|
||||||
|
modObj = gc.hub.newPlugin(mod)
|
||||||
|
gc.hub.register(mod, 'ROSTER')
|
||||||
|
gc.hub.register(mod, 'NOTIFY')
|
||||||
|
gc.hub.register(mod, 'MSG')
|
||||||
|
gc.hub.register(mod, 'SUBSCRIBED')
|
||||||
|
gc.hub.register(mod, 'SUBSCRIBE')
|
||||||
|
gc.hub.register(mod, 'AGENTS')
|
||||||
|
gc.hub.register(mod, 'AGENT_INFO')
|
||||||
|
modObj.load()
|
||||||
|
# END loadPLugins
|
||||||
|
|
||||||
def start():
|
def start():
|
||||||
gc = GajimCore()
|
gc = GajimCore()
|
||||||
guiPl = gc.hub.newPlugin('gtkgui')
|
loadPlugins(gc)
|
||||||
gc.hub.register('gtkgui', 'ROSTER')
|
|
||||||
gc.hub.register('gtkgui', 'NOTIFY')
|
|
||||||
gc.hub.register('gtkgui', 'MSG')
|
|
||||||
gc.hub.register('gtkgui', 'SUBSCRIBED')
|
|
||||||
gc.hub.register('gtkgui', 'SUBSCRIBE')
|
|
||||||
gc.hub.register('gtkgui', 'AGENTS')
|
|
||||||
gc.hub.register('gtkgui', 'AGENT_INFO')
|
|
||||||
guiPl.load()
|
|
||||||
logPl = gc.hub.newPlugin('logger')
|
|
||||||
gc.hub.register('logger', 'MSG')
|
|
||||||
gc.hub.register('logger', 'MSGSENT')
|
|
||||||
gc.hub.register('logger', 'NOTIFY')
|
|
||||||
gc.hub.register('logger', 'QUIT')
|
|
||||||
logPl.load()
|
|
||||||
gc.mainLoop()
|
gc.mainLoop()
|
||||||
|
# END start
|
||||||
|
|
|
@ -1,2 +1 @@
|
||||||
import gtkgui
|
import sock
|
||||||
import logger
|
|
||||||
|
|
|
@ -1,96 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
## plugins/logger.py
|
|
||||||
##
|
|
||||||
## Gajim Team:
|
|
||||||
## - Yann Le Boulanger <asterix@crans.org>
|
|
||||||
## - Vincent Hanquez <tab@tuxfamily.org>
|
|
||||||
## - David Ferlier <david@yazzy.org>
|
|
||||||
##
|
|
||||||
## Copyright (C) 2003 Gajim Team
|
|
||||||
##
|
|
||||||
## 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 only.
|
|
||||||
##
|
|
||||||
## 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.
|
|
||||||
##
|
|
||||||
|
|
||||||
import os
|
|
||||||
import string
|
|
||||||
import time
|
|
||||||
import common.optparser
|
|
||||||
CONFPATH = "~/.gajimrc"
|
|
||||||
LOGPATH = os.path.expanduser("~/.gajim/logs/")
|
|
||||||
|
|
||||||
class plugin:
|
|
||||||
def read_queue(self):
|
|
||||||
while 1:
|
|
||||||
while self.queueIN.empty() == 0:
|
|
||||||
lognotsep = self.cfgParser.Logger_lognotsep
|
|
||||||
if lognotsep:
|
|
||||||
lognotsep = string.atoi(lognotsep)
|
|
||||||
else:
|
|
||||||
#default
|
|
||||||
lognotsep = 1
|
|
||||||
lognotusr = self.cfgParser.Logger_lognotusr
|
|
||||||
if lognotusr:
|
|
||||||
lognotusr = string.atoi(lognotusr)
|
|
||||||
else:
|
|
||||||
#default
|
|
||||||
lognotusr = 1
|
|
||||||
# tim = time.strftime("%d%m%y%H%M%S")
|
|
||||||
tim = time.time()
|
|
||||||
|
|
||||||
ev = self.queueIN.get()
|
|
||||||
if ev[0] == 'QUIT':
|
|
||||||
return
|
|
||||||
elif ev[0] == 'NOTIFY':
|
|
||||||
status = ev[1][2]
|
|
||||||
if not status:
|
|
||||||
status = ""
|
|
||||||
if lognotsep == 1:
|
|
||||||
fic = open(LOGPATH + "notify.log", "a")
|
|
||||||
fic.write("%s:%s:%s:%s\n" % (tim, ev[1][0], \
|
|
||||||
ev[1][1], status))
|
|
||||||
fic.close()
|
|
||||||
if lognotusr == 1:
|
|
||||||
fic = open(LOGPATH + ev[1][0], "a")
|
|
||||||
fic.write("%s:%s:%s:%s\n" % (tim, ev[1][0], \
|
|
||||||
ev[1][1], status))
|
|
||||||
fic.close()
|
|
||||||
elif ev[0] == 'MSG':
|
|
||||||
fic = open(LOGPATH + ev[1][0], "a")
|
|
||||||
fic.write("%s:recv:%s\n" % (tim, ev[1][1]))
|
|
||||||
fic.close()
|
|
||||||
elif ev[0] == 'MSGSENT':
|
|
||||||
fic = open(LOGPATH + ev[1][0], "a")
|
|
||||||
fic.write("%s:sent:%s\n" % (tim, ev[1][1]))
|
|
||||||
fic.close()
|
|
||||||
time.sleep(0.5)
|
|
||||||
|
|
||||||
def __init__(self, quIN, quOUT):
|
|
||||||
self.cfgParser = common.optparser.OptionsParser(CONFPATH)
|
|
||||||
self.cfgParser.parseCfgFile()
|
|
||||||
self.queueIN = quIN
|
|
||||||
self.queueOUT = quOUT
|
|
||||||
#create ~/.gajim/logs if it doesn't exist
|
|
||||||
try:
|
|
||||||
os.stat(os.path.expanduser("~/.gajim"))
|
|
||||||
except OSError:
|
|
||||||
os.mkdir(os.path.expanduser("~/.gajim"))
|
|
||||||
print "creating ~/.gajim/"
|
|
||||||
try:
|
|
||||||
os.stat(LOGPATH)
|
|
||||||
except OSError:
|
|
||||||
os.mkdir(LOGPATH)
|
|
||||||
print "creating ~/.gajim/logs/"
|
|
||||||
self.read_queue()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
plugin(None, None)
|
|
||||||
|
|
||||||
print "plugin logger loaded"
|
|
Loading…
Reference in New Issue