summaryrefslogtreecommitdiff
path: root/targetcli
diff options
context:
space:
mode:
authorChristophe Vu-Brugier <cvubrugier@fastmail.fm>2017-08-22 14:55:53 +0200
committerChristophe Vu-Brugier <cvubrugier@fastmail.fm>2017-09-01 18:58:52 +0200
commit0872eb88390e28e558a4a118864ea46224ce49f6 (patch)
treeb0cd19b68ad00d270a71fb1d21333a3c09b837b7 /targetcli
parentee32a2493eaccd9352cc596b9e3387960cca48fc (diff)
downloadtargetcli-0872eb88390e28e558a4a118864ea46224ce49f6.tar.gz
Replace dbus-python with GObject Introspection
The dbus-python homepage advises against using it: https://pypi.python.org/pypi/dbus-python/1.2.4 dbus-python might not be the best D-Bus binding for you to use. dbus-python does not follow the principle of “In the face of ambiguity, refuse the temptation to guess”, and can’t be changed to not do so without seriously breaking compatibility. In addition, it uses libdbus (which has known problems with multi-threaded use) and attempts to be main-loop-agnostic (which means you have to select a suitable main loop for your application). Alternative ways to get your Python code onto D-Bus include: - GDBus, part of the GIO module of GLib, via GObject-Introspection and PyGI (uses the GLib main loop and object model) - QtDBus, part of Qt, via PyQt (uses the Qt main loop and object model) This patch replaces dbus-python with the GObject Introspection Gio module and fixes issue #90. Signed-off-by: Christophe Vu-Brugier <cvubrugier@fastmail.fm>
Diffstat (limited to 'targetcli')
-rw-r--r--targetcli/ui_backstore.py30
1 files changed, 20 insertions, 10 deletions
diff --git a/targetcli/ui_backstore.py b/targetcli/ui_backstore.py
index 83673a0..a040f67 100644
--- a/targetcli/ui_backstore.py
+++ b/targetcli/ui_backstore.py
@@ -17,11 +17,11 @@ License for the specific language governing permissions and limitations
under the License.
'''
+from gi.repository import Gio
import glob
import os
import re
import stat
-import dbus
from configshell_fb import ExecutionError
from rtslib_fb import BlockStorageObject, FileIOStorageObject
@@ -229,16 +229,26 @@ class UIBackstores(UINode):
tcmu-runner (or other daemon providing the same service) exposes a
DBus ObjectManager-based iface to find handlers it supports.
'''
- bus = dbus.SystemBus()
+ bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
try:
- mgr_obj = bus.get_object('org.kernel.TCMUService1', '/org/kernel/TCMUService1')
- mgr_iface = dbus.Interface(mgr_obj, 'org.freedesktop.DBus.ObjectManager')
-
- for k,v in mgr_iface.GetManagedObjects().items():
- tcmu_obj = bus.get_object('org.kernel.TCMUService1', k)
- tcmu_iface = dbus.Interface(tcmu_obj, dbus_interface='org.kernel.TCMUService1')
+ mgr_iface = Gio.DBusProxy.new_sync(bus,
+ Gio.DBusProxyFlags.NONE,
+ None,
+ 'org.kernel.TCMUService1',
+ '/org/kernel/TCMUService1',
+ 'org.freedesktop.DBus.ObjectManager',
+ None)
+
+ for k, v in mgr_iface.GetManagedObjects().items():
+ tcmu_iface = Gio.DBusProxy.new_sync(bus,
+ Gio.DBusProxyFlags.NONE,
+ None,
+ 'org.kernel.TCMUService1',
+ k,
+ 'org.kernel.TCMUService1',
+ None)
yield (k[k.rfind("/")+1:], tcmu_iface, v)
- except dbus.DBusException as e:
+ except Exception as e:
return
def refresh(self):
@@ -595,7 +605,7 @@ class UIUserBackedBackstore(UIBackstore):
config = self.handler + "/" + cfgstring
- ok, errmsg = self.iface.CheckConfig(config)
+ ok, errmsg = self.iface.CheckConfig('(s)', config)
if not ok:
raise ExecutionError("cfgstring invalid: %s" % errmsg)