comparison plugins/plugin_xep_0096.py @ 69:86f1f7f6d332

i18n first draft - gettext support added in SàT - first draft of french translation - added README with a HOWTO for translators
author Goffi <goffi@goffi.org>
date Wed, 03 Mar 2010 17:12:23 +1100
parents d46f849664aa
children f271fff3a713
comparison
equal deleted inserted replaced
68:9b842086d915 69:86f1f7f6d332
47 "type": "XEP", 47 "type": "XEP",
48 "protocols": ["XEP-0096"], 48 "protocols": ["XEP-0096"],
49 "dependencies": ["XEP_0065"], 49 "dependencies": ["XEP_0065"],
50 "main": "XEP_0096", 50 "main": "XEP_0096",
51 "handler": "yes", 51 "handler": "yes",
52 "description": """Implementation of SI File Transfert""" 52 "description": _("""Implementation of SI File Transfert""")
53 } 53 }
54 54
55 class XEP_0096(): 55 class XEP_0096():
56 56
57 def __init__(self, host): 57 def __init__(self, host):
58 info("Plugin XEP_0096 initialization") 58 info(_("Plugin XEP_0096 initialization"))
59 self.host = host 59 self.host = host
60 self._waiting_for_approval = {} 60 self._waiting_for_approval = {}
61 host.bridge.addMethod("sendFile", ".communication", in_sign='sss', out_sign='s', method=self.sendFile) 61 host.bridge.addMethod("sendFile", ".communication", in_sign='sss', out_sign='s', method=self.sendFile)
62 62
63 def getHandler(self): 63 def getHandler(self):
64 return XEP_0096_handler(self) 64 return XEP_0096_handler(self)
65 65
66 def xep_96(self, IQ, profile): 66 def xep_96(self, IQ, profile):
67 info ("XEP-0096 management") 67 info (_("XEP-0096 management"))
68 IQ.handled=True 68 IQ.handled=True
69 SI_elem = IQ.firstChildElement() 69 SI_elem = IQ.firstChildElement()
70 debug(SI_elem.toXml()) 70 debug(SI_elem.toXml())
71 filename = "" 71 filename = ""
72 file_size = "" 72 file_size = ""
73 for element in SI_elem.elements(): 73 for element in SI_elem.elements():
74 if element.name == "file": 74 if element.name == "file":
75 info ("File proposed: name=[%s] size=%s", element['name'], element['size']) 75 info (_("File proposed: name=[%(name)s] size=%(size)s") % {'name':element['name'], 'size':element['size']})
76 filename = element["name"] 76 filename = element["name"]
77 file_size = element["size"] 77 file_size = element["size"]
78 elif element.name == "feature": 78 elif element.name == "feature":
79 from_jid = IQ["from"] 79 from_jid = IQ["from"]
80 self._waiting_for_approval[IQ["id"]] = (element, from_jid, file_size, profile) 80 self._waiting_for_approval[IQ["id"]] = (element, from_jid, file_size, profile)
86 if accepted: 86 if accepted:
87 data['size'] = self._waiting_for_approval[id][2] 87 data['size'] = self._waiting_for_approval[id][2]
88 self.host.plugins["XEP_0065"].setData(data, id) 88 self.host.plugins["XEP_0065"].setData(data, id)
89 self.approved(id) 89 self.approved(id)
90 else: 90 else:
91 debug ("Transfert [%s] refused", id) 91 debug (_("Transfert [%s] refused"), id)
92 del(self._waiting_for_approval[id]) 92 del(self._waiting_for_approval[id])
93 93
94 def approved(self, id): 94 def approved(self, id):
95 """must be called when a file transfert has be accepted by client""" 95 """must be called when a file transfert has be accepted by client"""
96 debug ("Transfert [%s] accepted", id) 96 debug (_("Transfert [%s] accepted"), id)
97 97
98 if ( not self._waiting_for_approval.has_key(id) ): 98 if ( not self._waiting_for_approval.has_key(id) ):
99 error ("Approved unknow id !") 99 error (_("Approved unknow id !"))
100 #TODO: manage this (maybe approved by several frontends) 100 #TODO: manage this (maybe approved by several frontends)
101 else: 101 else:
102 element, from_id, size, profile = self._waiting_for_approval[id] 102 element, from_id, size, profile = self._waiting_for_approval[id]
103 del(self._waiting_for_approval[id]) 103 del(self._waiting_for_approval[id])
104 self.negociate(element, id, from_id, profile) 104 self.negociate(element, id, from_id, profile)
106 def negociate(self, feat_elem, id, to_jid, profile): 106 def negociate(self, feat_elem, id, to_jid, profile):
107 #TODO: put this in a plugin 107 #TODO: put this in a plugin
108 #FIXME: over ultra mega ugly, need to be generic 108 #FIXME: over ultra mega ugly, need to be generic
109 client = self.host.getClient(profile) 109 client = self.host.getClient(profile)
110 assert(client) 110 assert(client)
111 info ("Feature negociation") 111 info (_("Feature negociation"))
112 data = feat_elem.firstChildElement() 112 data = feat_elem.firstChildElement()
113 field = data.firstChildElement() 113 field = data.firstChildElement()
114 #FIXME: several options ! Q&D code for test only 114 #FIXME: several options ! Q&D code for test only
115 option = field.firstChildElement() 115 option = field.firstChildElement()
116 value = option.firstChildElement() 116 value = option.firstChildElement()
149 """send a file using XEP-0096 149 """send a file using XEP-0096
150 Return an unique id to identify the transfert 150 Return an unique id to identify the transfert
151 """ 151 """
152 current_jid, xmlstream = self.host.getJidNStream(profile_key) 152 current_jid, xmlstream = self.host.getJidNStream(profile_key)
153 if not xmlstream: 153 if not xmlstream:
154 error ('Asking profile for an non-existant or not connected profile') 154 error (_('Asking for an non-existant or not connected profile'))
155 return "" 155 return ""
156 debug ("sendfile (%s) to %s", filepath, to ) 156 debug ("sendfile (%s) to %s", filepath, to )
157 print type(filepath), type(to) 157 print type(filepath), type(to)
158 158
159 statinfo = os.stat(filepath) 159 statinfo = os.stat(filepath)