This commit is contained in:
glenux 2006-02-13 22:44:29 +00:00
parent 623d584382
commit 3eff1b83b9
2 changed files with 156 additions and 123 deletions

View file

@ -1,4 +1,5 @@
#/usr/bin/env python
# vim: set tw=72 ts=4 sw=4 st et sts si at:
import jabber
import sys
@ -6,52 +7,65 @@ import sys
def _gdisconnectHD(param=None):
if param:
print " Disconnecting : "+param
return None
class Account:
def __init__(self):
self._host=None
self._login=None
self._password=None
self._rosterHash={}
self._proto2transport={}
self._transport2proto={}
self._cnx=None
self._host = None
self._login = None
self._password = None
self._rosterHash = {}
self._proto2transport = {}
self._transport2proto = {}
self._cnx = None
def getDesc(self):
return (self._hlogin + "@" + self._host)
def setHost(self,hostName):
self._host=hostName
def setLogin(self,userName):
self._login=userName
def setHost(self, hostName):
self._host = hostName
def setPassword(self,passWord):
self._password=passWord
def setProtocol(self,protocolName,transportName):
self._proto2transport[protocolName]=transportName
def setLogin(self, userName):
self._login = userName
def setTransport(self,transportName,protocolName):
self._transport2proto[transportName]=protocolName
def getTransport(self,protocolName):
def setPassword(self, passWord):
self._password = passWord
def setProtocol(self, protocolName, transportName):
self._proto2transport[protocolName] = transportName
def setTransport(self, transportName, protocolName):
self._transport2proto[transportName] = protocolName
def getTransport(self, protocolName):
if self._proto2transport.has_key(protocolName):
return self._proto2transport[protocolName]
else:
return None
def getProtocol(self,hostName):
if self._transport2proto.has_key(hostName):
return self._transport2proto[hostName]
else:
return None
def connect(self):
# se connecte et choppe le roster
## connexion au serveur
self._cnx=jabber.Client(host=self._host)
self._cnx = jabber.Client(host=self._host)
self._cnx.setDisconnectHandler(_gdisconnectHD)
if self._cnx:
try:
@ -61,13 +75,16 @@ class Account:
if self._login and self._password \
and self._cnx.auth(self._login, self._password, 'default'):
sys.stderr.write(" Authenticated\n")
else:
sys.stderr.write(" Not Athenticated. \n")
sys.stderr.write(" Disconnecting from "+self._host+"\n")
self._cnx=None
sys.stderr.write(" Disconnecting from " + self._host+"\n")
self._cnx = None
except IOError, e:
print e
self._cnx=None
self._cnx = None
def disconnect(self):
if self._cnx:
@ -86,9 +103,12 @@ class Account:
self.setTransport(agent,agentsList[agent]["service"])
print " - "+agent+" @ "+agentsList[agent]["service"]
return self._transport2proto
else:
return None
def getRoster(self):
if self._cnx:
roster=self._cnx.requestRoster()
@ -99,9 +119,11 @@ class Account:
node=jid.getNode()
if not self._rosterHash.has_key(transport):
self._rosterHash[transport]={}
if not self._rosterHash[transport].has_key(node):
self._rosterHash[transport][node]=1
return roster
else:
return None
@ -109,29 +131,39 @@ class Account:
# on se connecte
if self._cnx:
for trans_proto in rosterHash.keys():
trans_host=self.getTransport(trans_proto)
if not trans_host: trans_host=trans_proto
trans_host = self.getTransport(trans_proto)
if not trans_host:
trans_host = trans_proto
# pour chaque id connue dans ce proto
for proto_id in rosterHash[trans_proto]:
if proto_id:
jid=jabber.JID()
jid = jabber.JID()
jid.setNode(proto_id)
jid.setDomain(trans_host)
jid.setResource("")
jid_name,jid_groups=rosterHash[trans_proto][proto_id]
sys.stdout.write(" -> "+proto_id)
sys.stdout.write(" @ "+trans_host)
sys.stdout.write(" = "+jid_name.encode('iso-8859-1','replace')+"...")
jid_name, jid_groups = rosterHash[trans_proto][proto_id]
sys.stdout.write(" -> " + proto_id)
sys.stdout.write(" @ " + trans_host)
sys.stdout.write(" = " + \
jid_name.encode('iso-8859-1','replace') + \
"...")
sys.stdout.flush()
if not(self._rosterHash.has_key(trans_host) \
and self._rosterHash[trans_host].has_key(proto_id)):
self._cnx.addRosterItem(jid)
sys.stdout.write(" [done]\n")
else:
#ne pas faire la mise a jour, le contact existe deja la-bas
sys.stdout.write(" [exists]\n")
# on met d'abord a jour le nom
self._cnx.updateRosterItem(jid,name=jid_name)
# puis le groupe
self._cnx.updateRosterItem(jid,name=jid_name,groups=jid_groups)
self._cnx.updateRosterItem(jid, name = jid_name)
# puis le groupe
self._cnx.updateRosterItem(jid, \
name = jid_name, \
groups=jid_groups)

View file

@ -1,4 +1,5 @@
#!/usr/bin/env python
# vim: set sw=4 ts=4 si et:
from xml.dom.ext import *
from xml.dom.ext.reader.Sax import *