This commit is contained in:
parent
a44d1e61b7
commit
a8f1be436e
2 changed files with 126 additions and 110 deletions
|
@ -18,6 +18,9 @@ class Account:
|
||||||
self._transport2proto={}
|
self._transport2proto={}
|
||||||
self._cnx=None
|
self._cnx=None
|
||||||
|
|
||||||
|
def getDesc(self):
|
||||||
|
return (self._hlogin + "@" + self._host)
|
||||||
|
|
||||||
def setHost(self,hostName):
|
def setHost(self,hostName):
|
||||||
self._host=hostName
|
self._host=hostName
|
||||||
|
|
||||||
|
|
231
start.py
231
start.py
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
# vim: set sw=4 ts=4 si et:
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
@ -20,12 +21,13 @@ from xml.dom.ext import *
|
||||||
from xml.dom.ext.reader.Sax import *
|
from xml.dom.ext.reader.Sax import *
|
||||||
|
|
||||||
class Answer:
|
class Answer:
|
||||||
def __init__(self,question,answerlist):
|
def __init__(self, question, answerlist):
|
||||||
self._answer=None
|
self._answer = None
|
||||||
while not self._answer:
|
while not self._answer:
|
||||||
sys.stderr.write(question)
|
sys.stderr.write(question)
|
||||||
tmp_ans=raw_input()
|
tmp_ans = raw_input()
|
||||||
if tmp_ans in (answerlist): self._answer=tmp_ans
|
if tmp_ans in (answerlist):
|
||||||
|
self._answer = tmp_ans
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
return self._answer;
|
return self._answer;
|
||||||
|
@ -34,115 +36,126 @@ class Answer:
|
||||||
class JabSync:
|
class JabSync:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# init des var
|
# init des var
|
||||||
self._commonJIDs={}
|
self._commonJIDs = {}
|
||||||
self._commonTransports={}
|
self._commonTransports = {}
|
||||||
self._configFile=None
|
self._configFile = None
|
||||||
self._config=None
|
self._config = None
|
||||||
self._accountList=None
|
self._accountList = None
|
||||||
self._jabservers={}
|
self._jabservers = {}
|
||||||
|
|
||||||
def parseCmdLine(self):
|
def parseCmdLine(self):
|
||||||
parser=OptionParser()
|
parser = OptionParser()
|
||||||
parser.add_option("-c","--config",\
|
parser.add_option(\
|
||||||
action="store", type="string", dest="filename",\
|
"-c","--config",\
|
||||||
help="Use file a configuration file",metavar="config")
|
action="store", \
|
||||||
(options,args)=parser.parse_args()
|
type="string", \
|
||||||
if options.filename:
|
dest="filename",\
|
||||||
self._configFile=options.filename
|
help="Use file a configuration file",\
|
||||||
else:
|
metavar="config")
|
||||||
self._configFile=os.path.join(os.path.expanduser("~"),".jabsync")
|
(options,args)=parser.parse_args()
|
||||||
print "Configuration file: " + self._configFile
|
if options.filename:
|
||||||
def init(self):
|
self._configFile=options.filename
|
||||||
self._config=Config()
|
|
||||||
self._config.loadFromFile(self._configFile)
|
|
||||||
self._accountList=self._config.getAccounts()
|
|
||||||
for account in self._accountList:
|
|
||||||
account.connect()
|
|
||||||
agents=account.getAgents()
|
|
||||||
self._commonTransports.update(agents)
|
|
||||||
for transport in self._commonTransports.keys():
|
|
||||||
print "Transport: "+transport
|
|
||||||
|
|
||||||
def giveTransport(self,hostName):
|
|
||||||
if self._jabservers.has_key(hostName):
|
|
||||||
trans_proto=hostName
|
|
||||||
return trans_proto
|
|
||||||
else:
|
|
||||||
if self._commonTransports.has_key(hostName):
|
|
||||||
trans_proto=self._commonTransports[hostName]
|
|
||||||
return trans_proto
|
|
||||||
else:
|
|
||||||
# TODO: ask user input
|
|
||||||
is_jabber=Answer(\
|
|
||||||
"# ERR : is "+hostName+" a jabber server ? [y/n]\n",\
|
|
||||||
["y","n"]).get()
|
|
||||||
if is_jabber == "y":
|
|
||||||
self._jabservers[hostName]=1
|
|
||||||
else:
|
else:
|
||||||
what_tp_ans={\
|
self._configFile=os.path.join(os.path.expanduser("~"),".jabsync")
|
||||||
"a" : "aim",\
|
print "Configuration file: " + self._configFile
|
||||||
"i" : "icq",\
|
|
||||||
"r" : "irc",\
|
|
||||||
"g" : "gadu",\
|
|
||||||
"m" : "msn",\
|
|
||||||
"p" : "public",\
|
|
||||||
"v" : "private",\
|
|
||||||
"y" : "yahoo",\
|
|
||||||
"-" : "forget"}
|
|
||||||
what_transport=Answer(\
|
|
||||||
" Select transport type :\n"+\
|
|
||||||
" [a]im"+\
|
|
||||||
" [i]cq"+\
|
|
||||||
" i[r]c):"+\
|
|
||||||
" [g]adu"+\
|
|
||||||
" [m]sn"+\
|
|
||||||
" [p]ublic:"+\
|
|
||||||
" pri[v]ate:"+\
|
|
||||||
" [y]ahoo"+\
|
|
||||||
" [-] Forget JIDs using this host",\
|
|
||||||
what_tp_ans.keys())
|
|
||||||
trans_proto=what_tp_ans[what_transport]
|
|
||||||
if trans_proto == "forget":
|
|
||||||
# TODO: ajouter regles d'exclusion
|
|
||||||
zero=0
|
|
||||||
else:
|
|
||||||
# TODO: ajouter transport a la config XML
|
|
||||||
zero=0
|
|
||||||
return self.giveTransport(hostName)
|
|
||||||
|
|
||||||
def get(self):
|
def init(self):
|
||||||
#get Roster
|
self._config = Config()
|
||||||
for account in self._accountList:
|
self._config.loadFromFile(self._configFile)
|
||||||
roster=account.getRoster()
|
self._accountList = self._config.getAccounts()
|
||||||
# fusionner les roster
|
for account in self._accountList:
|
||||||
jid_list=roster.getJIDs()
|
account.connect()
|
||||||
for jid in jid_list:
|
agents = account.getAgents()
|
||||||
transport=jid.getDomain()
|
self._commonTransports.update(agents)
|
||||||
trans_proto=self.giveTransport(transport)
|
for transport in self._commonTransports.keys():
|
||||||
if not self._commonJIDs.has_key(trans_proto):
|
print "Transport: "+transport
|
||||||
self._commonJIDs[trans_proto]={}
|
|
||||||
jid_name=roster.getName(jid)
|
def giveTransport(self, hostName):
|
||||||
jid_groups=roster.getGroups(jid)
|
if self._jabservers.has_key(hostName):
|
||||||
if not jid_name: jid_name=jid.getNode()
|
trans_proto = hostName
|
||||||
if not self._commonJIDs[trans_proto].has_key(jid.getNode()):
|
return trans_proto
|
||||||
self._commonJIDs[trans_proto][jid.getNode()]=(jid_name,jid_groups)
|
else:
|
||||||
# print " <- "+jid.getNode()+" @ "+trans_proto+" = "+jid_name
|
if self._commonTransports.has_key(hostName):
|
||||||
print "\x1B[G <- "+jid.getNode()+" @ "+trans_proto+" = "+jid_name
|
trans_proto = self._commonTransports[hostName]
|
||||||
|
return trans_proto
|
||||||
|
else:
|
||||||
|
# TODO: ask user input
|
||||||
|
is_jabber = Answer(\
|
||||||
|
"# ERR : is "+hostName+" a jabber server ? [y/n]\n",\
|
||||||
|
["y","n"]).get()
|
||||||
|
if is_jabber == "y":
|
||||||
|
self._jabservers[hostName] = 1
|
||||||
|
else:
|
||||||
|
what_tp_ans = {\
|
||||||
|
"a" : "aim",\
|
||||||
|
"i" : "icq",\
|
||||||
|
"r" : "irc",\
|
||||||
|
"g" : "gadu",\
|
||||||
|
"m" : "msn",\
|
||||||
|
"p" : "public",\
|
||||||
|
"v" : "private",\
|
||||||
|
"y" : "yahoo",\
|
||||||
|
"-" : "forget"}
|
||||||
|
what_transport = Answer(\
|
||||||
|
" Select transport type :\n"+\
|
||||||
|
" [a]im"+\
|
||||||
|
" [i]cq"+\
|
||||||
|
" i[r]c):"+\
|
||||||
|
" [g]adu"+\
|
||||||
|
" [m]sn"+\
|
||||||
|
" [p]ublic:"+\
|
||||||
|
" pri[v]ate:"+\
|
||||||
|
" [y]ahoo"+\
|
||||||
|
" [-] Forget JIDs using this host",\
|
||||||
|
what_tp_ans.keys())
|
||||||
|
trans_proto = what_tp_ans[what_transport.get()]
|
||||||
|
print "Selected : " + trans_proto
|
||||||
|
if trans_proto == "forget":
|
||||||
|
# TODO: ajouter regles d'exclusion
|
||||||
|
zero = 0
|
||||||
|
else:
|
||||||
|
# TODO: ajouter transport a la config XML
|
||||||
|
self._commonTransports[hostName] = trans_proto
|
||||||
|
zero = 0
|
||||||
|
return self.giveTransport(hostName)
|
||||||
|
|
||||||
|
|
||||||
|
def get(self):
|
||||||
|
print "jabsync::get\n"
|
||||||
|
#get Roster
|
||||||
|
for account in self._accountList:
|
||||||
|
roster = account.getRoster()
|
||||||
|
# fusionner les roster
|
||||||
|
jid_list = roster.getJIDs()
|
||||||
|
for jid in jid_list:
|
||||||
|
print "Getting... "
|
||||||
|
print jid
|
||||||
|
transport = jid.getDomain()
|
||||||
|
trans_proto = self.giveTransport(transport)
|
||||||
|
if not self._commonJIDs.has_key(trans_proto):
|
||||||
|
self._commonJIDs[trans_proto]={}
|
||||||
|
jid_name = roster.getName(jid)
|
||||||
|
jid_groups = roster.getGroups(jid)
|
||||||
|
if not jid_name: jid_name = jid.getNode()
|
||||||
|
if not self._commonJIDs[trans_proto].has_key(jid.getNode()):
|
||||||
|
self._commonJIDs[trans_proto][jid.getNode()] = \
|
||||||
|
(jid_name,jid_groups)
|
||||||
|
print "\x1B[G <- "+jid.getNode()+" @ "+trans_proto+" = "+jid_name
|
||||||
|
|
||||||
#upload rosters
|
#upload rosters
|
||||||
def set(self):
|
def set(self):
|
||||||
for account in self._accountList:
|
for account in self._accountList:
|
||||||
account.setRoster(self._commonJIDs)
|
account.setRoster(self._commonJIDs)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
for account in self._accountList:
|
for account in self._accountList:
|
||||||
account.disconnect()
|
account.disconnect()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
jabsync=JabSync()
|
jabsync=JabSync()
|
||||||
jabsync.parseCmdLine()
|
jabsync.parseCmdLine()
|
||||||
jabsync.init()
|
jabsync.init()
|
||||||
jabsync.get()
|
jabsync.get()
|
||||||
jabsync.set()
|
jabsync.set()
|
||||||
jabsync.stop()
|
jabsync.stop()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue