This commit is contained in:
parent
623d584382
commit
3eff1b83b9
2 changed files with 156 additions and 123 deletions
38
account.py
38
account.py
|
@ -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,8 +7,10 @@ import sys
|
|||
def _gdisconnectHD(param=None):
|
||||
if param:
|
||||
print " Disconnecting : "+param
|
||||
|
||||
return None
|
||||
|
||||
|
||||
class Account:
|
||||
def __init__(self):
|
||||
self._host = None
|
||||
|
@ -18,36 +21,47 @@ class Account:
|
|||
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 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
|
||||
|
@ -61,14 +75,17 @@ 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
|
||||
|
||||
except IOError, e:
|
||||
print e
|
||||
self._cnx = None
|
||||
|
||||
|
||||
def disconnect(self):
|
||||
if self._cnx:
|
||||
self._cnx.disconnect()
|
||||
|
@ -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
|
||||
|
||||
|
@ -110,7 +132,9 @@ class Account:
|
|||
if self._cnx:
|
||||
for trans_proto in rosterHash.keys():
|
||||
trans_host = self.getTransport(trans_proto)
|
||||
if not trans_host: trans_host=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:
|
||||
|
@ -121,17 +145,25 @@ class Account:
|
|||
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.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, \
|
||||
groups=jid_groups)
|
||||
|
||||
|
|
|
@ -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 *
|
||||
|
|
Loading…
Reference in a new issue