comparison src/plugins/plugin_adhoc_dbus.py @ 993:301b342c697a

core: use of the new core.log module: /!\ this is a massive refactoring and was largely automated, it probably did bring some bugs /!\
author Goffi <goffi@goffi.org>
date Sat, 19 Apr 2014 19:19:19 +0200
parents 1a759096ccbd
children 069ad98b360d
comparison
equal deleted inserted replaced
992:f51a1895275c 993:301b342c697a
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 _, D_
21 from sat.core.constants import Const as C 21 from sat.core.constants import Const as C
22 from logging import debug, info, warning, error 22 from sat.core.log import getLogger
23 log = getLogger(__name__)
23 from twisted.words.protocols.jabber import jid 24 from twisted.words.protocols.jabber import jid
24 from twisted.internet import defer, reactor 25 from twisted.internet import defer, reactor
25 from wokkel import data_form 26 from wokkel import data_form
26 from lxml import etree 27 from lxml import etree
27 from os import path 28 from os import path
51 52
52 53
53 class AdHocDBus(object): 54 class AdHocDBus(object):
54 55
55 def __init__(self, host): 56 def __init__(self, host):
56 info(_("plugin Ad-Hoc D-Bus initialization")) 57 log.info(_("plugin Ad-Hoc D-Bus initialization"))
57 self.host = host 58 self.host = host
58 host.bridge.addMethod("adHocDBusAddAuto", ".plugin", in_sign='sasasasasasass', out_sign='(sa(sss))', 59 host.bridge.addMethod("adHocDBusAddAuto", ".plugin", in_sign='sasasasasasass', out_sign='(sa(sss))',
59 method=self._adHocDBusAddAuto, 60 method=self._adHocDBusAddAuto,
60 async=True) 61 async=True)
61 self.session_bus = dbus.SessionBus() 62 self.session_bus = dbus.SessionBus()
95 return False 96 return False
96 return True 97 return True
97 98
98 @defer.inlineCallbacks 99 @defer.inlineCallbacks
99 def _introspect(self, methods, bus_name, proxy): 100 def _introspect(self, methods, bus_name, proxy):
100 debug("introspecting path [%s]" % proxy.object_path) 101 log.debug("introspecting path [%s]" % proxy.object_path)
101 introspect_xml = yield self._DBusIntrospect(proxy) 102 introspect_xml = yield self._DBusIntrospect(proxy)
102 el = etree.fromstring(introspect_xml) 103 el = etree.fromstring(introspect_xml)
103 for node in el.iterchildren('node', 'interface'): 104 for node in el.iterchildren('node', 'interface'):
104 if node.tag == 'node': 105 if node.tag == 'node':
105 new_path = path.join(proxy.object_path, node.get('name')) 106 new_path = path.join(proxy.object_path, node.get('name'))
106 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)
107 yield self._introspect(methods, bus_name, new_proxy) 108 yield self._introspect(methods, bus_name, new_proxy)
108 elif node.tag == 'interface': 109 elif node.tag == 'interface':
109 name = node.get('name') 110 name = node.get('name')
110 if any(name.startswith(ignored) for ignored in IGNORED_IFACES_START): 111 if any(name.startswith(ignored) for ignored in IGNORED_IFACES_START):
111 debug('interface [%s] is ignored' % name) 112 log.debug('interface [%s] is ignored' % name)
112 continue 113 continue
113 debug("introspecting interface [%s]" % name) 114 log.debug("introspecting interface [%s]" % name)
114 for method in node.iterchildren('method'): 115 for method in node.iterchildren('method'):
115 if self._acceptMethod(method): 116 if self._acceptMethod(method):
116 method_name = method.get('name') 117 method_name = method.get('name')
117 debug("method accepted: [%s]" % method_name) 118 log.debug("method accepted: [%s]" % method_name)
118 methods.add((proxy.object_path, name, method_name)) 119 methods.add((proxy.object_path, name, method_name))
119 120
120 def _adHocDBusAddAuto(self, prog_name, allowed_jids, allowed_groups, allowed_magics, forbidden_jids, forbidden_groups, flags, profile_key): 121 def _adHocDBusAddAuto(self, prog_name, allowed_jids, allowed_groups, allowed_magics, forbidden_jids, forbidden_groups, flags, profile_key):
121 return self.adHocDBusAddAuto(prog_name, allowed_jids, allowed_groups, allowed_magics, forbidden_jids, forbidden_groups, flags, profile_key) 122 return self.adHocDBusAddAuto(prog_name, allowed_jids, allowed_groups, allowed_magics, forbidden_jids, forbidden_groups, flags, profile_key)
122 123
123 @defer.inlineCallbacks 124 @defer.inlineCallbacks
124 def adHocDBusAddAuto(self, prog_name, allowed_jids=None, allowed_groups=None, allowed_magics=None, forbidden_jids=None, forbidden_groups=None, flags=None, profile_key=C.PROF_KEY_NONE): 125 def adHocDBusAddAuto(self, prog_name, allowed_jids=None, allowed_groups=None, allowed_magics=None, forbidden_jids=None, forbidden_groups=None, flags=None, profile_key=C.PROF_KEY_NONE):
125 bus_names = yield self._DBusListNames() 126 bus_names = yield self._DBusListNames()
126 bus_names = [bus_name for bus_name in bus_names if '.' + prog_name in bus_name] 127 bus_names = [bus_name for bus_name in bus_names if '.' + prog_name in bus_name]
127 if not bus_names: 128 if not bus_names:
128 info("Can't find any bus for [%s]" % prog_name) 129 log.info("Can't find any bus for [%s]" % prog_name)
129 return 130 return
130 bus_names.sort() 131 bus_names.sort()
131 for bus_name in bus_names: 132 for bus_name in bus_names:
132 if bus_name.endswith(prog_name): 133 if bus_name.endswith(prog_name):
133 break 134 break
134 info("bus name found: [%s]" % bus_name) 135 log.info("bus name found: [%s]" % bus_name)
135 proxy = self.session_bus.get_object(bus_name, '/', introspect=False) 136 proxy = self.session_bus.get_object(bus_name, '/', introspect=False)
136 methods = set() 137 methods = set()
137 138
138 yield self._introspect(methods, bus_name, proxy) 139 yield self._introspect(methods, bus_name, proxy)
139 140