Example D-Bus usage

Examples using dnf5daemon server via D-Bus from Python.

System upgrade

Perform a system-upgrade.

 1"""
 2This is an example how to perform a system-upgrade with dnf5daemon-server.
 3"""
 4
 5import dbus
 6
 7DNFDAEMON_BUS_NAME = 'org.rpm.dnf.v0'
 8DNFDAEMON_OBJECT_PATH = '/' + DNFDAEMON_BUS_NAME.replace('.', '/')
 9
10IFACE_SESSION_MANAGER = '{}.SessionManager'.format(DNFDAEMON_BUS_NAME)
11IFACE_RPM = '{}.rpm.Rpm'.format(DNFDAEMON_BUS_NAME)
12IFACE_GOAL = '{}.Goal'.format(DNFDAEMON_BUS_NAME)
13
14
15bus = dbus.SystemBus()
16iface_session = dbus.Interface(
17    bus.get_object(DNFDAEMON_BUS_NAME, DNFDAEMON_OBJECT_PATH),
18    dbus_interface=IFACE_SESSION_MANAGER)
19
20# set the releasever to the new distribution release
21session = iface_session.open_session(
22    dbus.Dictionary({"releasever": "40"}, signature=dbus.Signature('sv')))
23
24iface_rpm = dbus.Interface(
25    bus.get_object(DNFDAEMON_BUS_NAME, session),
26    dbus_interface=IFACE_RPM)
27iface_goal = dbus.Interface(
28    bus.get_object(DNFDAEMON_BUS_NAME, session),
29    dbus_interface=IFACE_GOAL)
30
31# Add system upgrade to the transaction
32options = {
33    "mode": "distrosync",
34}
35iface_rpm.system_upgrade(options)
36
37# resolve the transaction
38resolved, result = iface_goal.resolve({})
39
40# now you can print the transaction table and ask the user for confirmation
41print("Resolved.")
42
43if result == 0:
44    # execute the transaction offline (durint the next reboot)
45    iface_goal.do_transaction({"offline": True}, timeout=2000)
46    print("Reboot to continue with system upgrade...")
47else:
48    errors = iface_goal.get_transaction_problems_string()
49    print("Errors while resolving the transaction:")
50    for error in errors:
51        print(error)

list_fd()

D-Bus API bindings for dnfdaemon org.rpm.dnf.v0.rpm.Rpm.list_fd() example.

 1"""
 2This is an example how to perform a system-upgrade with dnf5daemon-server.
 3"""
 4
 5import dbus
 6
 7DNFDAEMON_BUS_NAME = 'org.rpm.dnf.v0'
 8DNFDAEMON_OBJECT_PATH = '/' + DNFDAEMON_BUS_NAME.replace('.', '/')
 9
10IFACE_SESSION_MANAGER = '{}.SessionManager'.format(DNFDAEMON_BUS_NAME)
11IFACE_RPM = '{}.rpm.Rpm'.format(DNFDAEMON_BUS_NAME)
12IFACE_GOAL = '{}.Goal'.format(DNFDAEMON_BUS_NAME)
13
14
15bus = dbus.SystemBus()
16iface_session = dbus.Interface(
17    bus.get_object(DNFDAEMON_BUS_NAME, DNFDAEMON_OBJECT_PATH),
18    dbus_interface=IFACE_SESSION_MANAGER)
19
20# set the releasever to the new distribution release
21session = iface_session.open_session(
22    dbus.Dictionary({"releasever": "40"}, signature=dbus.Signature('sv')))
23
24iface_rpm = dbus.Interface(
25    bus.get_object(DNFDAEMON_BUS_NAME, session),
26    dbus_interface=IFACE_RPM)
27iface_goal = dbus.Interface(
28    bus.get_object(DNFDAEMON_BUS_NAME, session),
29    dbus_interface=IFACE_GOAL)
30
31# Add system upgrade to the transaction
32options = {
33    "mode": "distrosync",
34}
35iface_rpm.system_upgrade(options)
36
37# resolve the transaction
38resolved, result = iface_goal.resolve({})
39
40# now you can print the transaction table and ask the user for confirmation
41print("Resolved.")
42
43if result == 0:
44    # execute the transaction offline (durint the next reboot)
45    iface_goal.do_transaction({"offline": True}, timeout=2000)
46    print("Reboot to continue with system upgrade...")
47else:
48    errors = iface_goal.get_transaction_problems_string()
49    print("Errors while resolving the transaction:")
50    for error in errors:
51        print(error)