我正在尝试将与Glib / dbus相关的C代码重写为python。对应的C代码:
GVariant *real_value;
JsonNode *root;
JsonGenerator *generator;
gsize json_length;
gchar *json;
GDBusProxy *proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_NONE,
NULL, /* interface info */
"org.gnome.Shell",
"/org/gnome/Shell",
"org.gnome.Shell.Extensions",
NULL, /* GCancellable */
&error);
GVariant *variant = g_dbus_proxy_call_sync (obj->proxy,
"ListExtensions",
NULL, /* parameters */
G_DBUS_CALL_FLAGS_NONE,
-1, /* timeout */
NULL, /* cancellable */
&error);
g_variant_get (variant, "(@*)", &real_value);
root = json_gvariant_serialize (real_value);
generator = json_generator_new ();
json_generator_set_root (generator, root);
json = json_generator_to_data (generator, &json_length);
我的python代码是:
proxy = Gio.DBusProxy.new_for_bus_sync(Gio.BusType.SESSION,
Gio.DBusProxyFlags.NONE,
None,
'org.gnome.Shell',
'/org/gnome/Shell',
'org.gnome.Shell.Extensions',
None)
result = proxy.call_sync("ListExtensions",
None,
Gio.DBusCallFlags.NONE,
-1,
None)
real_value = ???
root = Json.gvariant_serialize(real_value)
generator = Json.Generator.new()
generator.set_root(root)
data = generator.to_data()
问题是我没有看到任何g_variant_get()绑定来获取“real_value”。我怎么能在python中做到这一点?
谢谢!
答案 0 :(得分:0)
所以我用过:
proxy = Gio.DBusProxy.new_for_bus_sync(Gio.BusType.SESSION,
Gio.DBusProxyFlags.NONE,
None,
'org.gnome.Shell',
'/org/gnome/Shell',
'org.gnome.Shell.Extensions',
None)
result = proxy.call_sync("ListExtensions",
None,
Gio.DBusCallFlags.NONE,
-1,
None)
jsonStr = json.dumps(result.unpack()[0])