comparison src/plugins/plugin_adhoc_dbus.py @ 1540:9a4e95c62380

plugin ad-hoc D-Bus: exception fixe + minor fixes
author Goffi <goffi@goffi.org>
date Wed, 30 Sep 2015 17:24:19 +0200
parents 069ad98b360d
children 94901070478e
comparison
equal deleted inserted replaced
1539:98f92a054539 1540:9a4e95c62380
15 # GNU Affero General Public License for more details. 15 # GNU Affero General Public License for more details.
16 16
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 from sat.core.i18n import _, D_ 20 from sat.core.i18n import _
21 from sat.core.constants import Const as C 21 from sat.core.constants import Const as C
22 from sat.core.log import getLogger 22 from sat.core.log import getLogger
23 log = getLogger(__name__) 23 log = getLogger(__name__)
24 from twisted.words.protocols.jabber import jid 24 from sat.core import exceptions
25 from twisted.internet import defer, reactor 25 from twisted.internet import defer
26 from wokkel import data_form 26 from wokkel import data_form
27 from lxml import etree 27 from lxml import etree
28 from os import path 28 from os import path
29 import uuid 29 import uuid
30 import dbus 30 import dbus
101 log.debug("introspecting path [%s]" % proxy.object_path) 101 log.debug("introspecting path [%s]" % proxy.object_path)
102 introspect_xml = yield self._DBusIntrospect(proxy) 102 introspect_xml = yield self._DBusIntrospect(proxy)
103 el = etree.fromstring(introspect_xml) 103 el = etree.fromstring(introspect_xml)
104 for node in el.iterchildren('node', 'interface'): 104 for node in el.iterchildren('node', 'interface'):
105 if node.tag == 'node': 105 if node.tag == 'node':
106 new_path = path.join(proxy.object_path, node.get('name')) 106 new_path = os.path.join(proxy.object_path, node.get('name'))
107 new_proxy = self.session_bus.get_object(bus_name, new_path, introspect=False) 107 new_proxy = self.session_bus.get_object(bus_name, new_path, introspect=False)
108 yield self._introspect(methods, bus_name, new_proxy) 108 yield self._introspect(methods, bus_name, new_proxy)
109 elif node.tag == 'interface': 109 elif node.tag == 'interface':
110 name = node.get('name') 110 name = node.get('name')
111 if any(name.startswith(ignored) for ignored in IGNORED_IFACES_START): 111 if any(name.startswith(ignored) for ignored in IGNORED_IFACES_START):
181 # we should have the answer here 181 # we should have the answer here
182 try: 182 try:
183 x_elt = command_elt.elements(data_form.NS_X_DATA,'x').next() 183 x_elt = command_elt.elements(data_form.NS_X_DATA,'x').next()
184 answer_form = data_form.Form.fromElement(x_elt) 184 answer_form = data_form.Form.fromElement(x_elt)
185 command = answer_form['command'] 185 command = answer_form['command']
186 except KeyError, StopIteration: 186 except (KeyError, StopIteration):
187 raise self.XEP_0050.AdHocError(self.XEP_0050.ERROR.BAD_PAYLOAD) 187 raise self.XEP_0050.AdHocError(self.XEP_0050.ERROR.BAD_PAYLOAD)
188 188
189 if command not in names_map: 189 if command not in names_map:
190 raise self.XEP_0050.AdHocError(self.XEP_0050.ERROR.BAD_PAYLOAD) 190 raise self.XEP_0050.AdHocError(self.XEP_0050.ERROR.BAD_PAYLOAD)
191 191
192 path, iface, command = names_map[command] 192 path, iface, command = names_map[command]
193 proxy = self.session_bus.get_object(bus_name, path) 193 proxy = self.session_bus.get_object(bus_name, path)
194 194
195 d = self._DBusAsyncCall(proxy, command, interface=iface) 195 self._DBusAsyncCall(proxy, command, interface=iface)
196 196
197 # job done, we can end the session, except if we have FLAG_LOOP 197 # job done, we can end the session, except if we have FLAG_LOOP
198 if FLAG_LOOP in flags: 198 if FLAG_LOOP in flags:
199 # We have a loop, so we clear everything and we execute again the command as we had a first call (command_elt is not used, so None is OK) 199 # We have a loop, so we clear everything and we execute again the command as we had a first call (command_elt is not used, so None is OK)
200 del actions[:] 200 del actions[:]