forked from jlebon/atomic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
atomic_dbus.py
65 lines (55 loc) · 2.06 KB
/
atomic_dbus.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/python -Es
import dbus
import dbus.service
import dbus.mainloop.glib
from gi.repository import GLib # pylint: disable=no-name-in-module
import slip.dbus.service
from slip.dbus import polkit
from . import Atomic
class atomic_dbus(slip.dbus.service.Object):
default_polkit_auth_required = "org.atomic.readwrite"
class Args():
def __init__(self, image):
self.image = image
self.recurse = False
def __init__(self, *p, **k):
slip.dbus.service.Object.__init__(*p, **k)
self.atomic = Atomic()
"""
The version method takes in an image name and returns its version
information
"""
@slip.dbus.polkit.require_auth("org.atomic.read")
@dbus.service.method("org.atomic", in_signature='asb',
out_signature='aa{sv}')
def version(self, images, recurse=False):
versions = []
for image in images:
args = self.Args(str(image))
args.recurse = recurse
self.atomic.set_args(args)
versions.append({"Image": image,
"Version": self.atomic.version()})
return versions
"""
The verify method takes in an image name and returns whether or not the
image should be updated
"""
@slip.dbus.polkit.require_auth("org.atomic.read")
@dbus.service.method("org.atomic", in_signature='as', out_signature='av')
def verify(self, images):
verifications = []
for image in images:
args = self.Args(str(image))
self.atomic.set_args(args)
verifications.append({"Image": image,
"Verification": self.atomic.verify()})
return verifications
if __name__ == "__main__":
mainloop = GLib.MainLoop()
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
system_bus = dbus.SystemBus()
name = dbus.service.BusName("org.atomic", system_bus)
object = atomic_dbus(system_bus, "/org/atomic/object")
slip.dbus.service.set_mainloop(mainloop)
mainloop.run()