Merge lp:~jamesh/snappy-hub/test-snapd-dbus-service into lp:~snappy-dev/snappy-hub/test-snapd-dbus-service

Proposed by James Henstridge
Status: Merged
Approved by: Zygmunt Krynicki
Approved revision: no longer in the source branch.
Merged at revision: 2
Proposed branch: lp:~jamesh/snappy-hub/test-snapd-dbus-service
Merge into: lp:~snappy-dev/snappy-hub/test-snapd-dbus-service
Diff against target: 125 lines (+59/-21)
3 files modified
bin/test-snapd-dbus-service (+25/-9)
setup.py (+11/-0)
snapcraft.yaml (+23/-12)
To merge this branch: bzr merge lp:~jamesh/snappy-hub/test-snapd-dbus-service
Reviewer Review Type Date Requested Status
Zygmunt Krynicki Approve
Review via email: mp+360118@code.launchpad.net

Commit message

Description of the change

Integrate changes from https://github.com/snapcore/snapd/pull/6258.

Namely:

 * switch from "service: true" to "activatable: true"
 * Provide both a system and session service
 * make the system service a daemon
 * use a setup.py script so environment is set up correctly for the script.
 * update service so it can connect to either bus

To post a comment you must log in.
Revision history for this message
Zygmunt Krynicki (zyga) wrote :

Looks good, +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bin/test-snapd-dbus-service'
--- bin/test-snapd-dbus-service 2017-01-16 16:31:25 +0000
+++ bin/test-snapd-dbus-service 2018-12-05 12:13:07 +0000
@@ -1,7 +1,7 @@
1#!/usr/bin/python31#!/usr/bin/python3
22
3import os3import os
4import os.path4import sys
5import glob5import glob
6# ensure that typelib path points to the right directory,6# ensure that typelib path points to the right directory,
7# eg. $SNAP/usr/lib/x86_64-linux-gnu/girepository-1.0 on amd647# eg. $SNAP/usr/lib/x86_64-linux-gnu/girepository-1.0 on amd64
@@ -15,18 +15,34 @@
15from dbus.mainloop.glib import DBusGMainLoop15from dbus.mainloop.glib import DBusGMainLoop
16DBusGMainLoop(set_as_default=True)16DBusGMainLoop(set_as_default=True)
1717
18BUS_NAME = 'io.snapcraft.SnapDbusService'
19OBJECT_PATH = '/io/snapcraft/SnapDbusService'
20
1821
19class ServerObject(dbus.service.Object):22class ServerObject(dbus.service.Object):
20 def __init__(self):
21 bus_name = dbus.service.BusName(
22 'io.snapcraft.SnapDbusService',bus=dbus.SessionBus())
23 dbus.service.Object.__init__(self, bus_name, '/io/snapcraft/SnapDbusService')
24 @dbus.service.method('io.snapcraft.ExampleInterface')23 @dbus.service.method('io.snapcraft.ExampleInterface')
25 def ExampleMethod(self):24 def ExampleMethod(self):
26 return "hello world"25 return "hello world"
2726
2827
29if __name__ == "__main__":28if __name__ == "__main__":
30 server = ServerObject()29 if sys.argv[1] == 'session':
31 loop = GLib.MainLoop()30 bus = dbus.SessionBus()
32 loop.run()31 elif sys.argv[1] == 'system':
32 bus = dbus.SystemBus()
33 else:
34 sys.stderr.write("Unknown D-Bus bus: {}\n".format(sys.argv[1]))
35 sys.exit(1)
36
37 main_loop = GLib.MainLoop()
38 # Make sure we quit when the bus shuts down
39 bus.add_signal_receiver(
40 main_loop.quit, signal_name="Disconnected",
41 path="/org/freedesktop/DBus/Local",
42 dbus_interface="org.freedesktop.DBus.Local")
43
44 server = ServerObject(bus, OBJECT_PATH)
45 bus_name = dbus.service.BusName(
46 BUS_NAME, bus, allow_replacement=True, replace_existing=True,
47 do_not_queue=True)
48 main_loop.run()
3349
=== added file 'setup.py'
--- setup.py 1970-01-01 00:00:00 +0000
+++ setup.py 2018-12-05 12:13:07 +0000
@@ -0,0 +1,11 @@
1#!/usr/bin/env python3
2
3import setuptools
4
5setuptools.setup(
6 name="test-snapd-dbus-serice",
7 version="1.0",
8 scripts=[
9 "bin/test-snapd-dbus-service"
10 ],
11)
012
=== modified file 'snapcraft.yaml'
--- snapcraft.yaml 2017-01-16 16:31:25 +0000
+++ snapcraft.yaml 2018-12-05 12:13:07 +0000
@@ -3,26 +3,37 @@
3summary: Python based example dbus service3summary: Python based example dbus service
4description: ...4description: ...
5slots:5slots:
6 test-snapd-dbus-service-slot:6 dbus-session-slot:
7 interface: dbus7 interface: dbus
8 bus: session8 bus: session
9 service: true9 activatable: true
10 name: io.snapcraft.SnapDbusService
11 dbus-system-slot:
12 interface: dbus
13 bus: system
14 activatable: true
10 name: io.snapcraft.SnapDbusService15 name: io.snapcraft.SnapDbusService
11apps:16apps:
12 test-snapd-dbus-service:17 session:
13 command: bin/test-snapd-dbus-service18 command: bin/test-snapd-dbus-service session
14 plugs:19 plugs:
15 - network20 - network
16 - network-bind21 slots:
17 slots:22 - dbus-session-slot
18 - test-snapd-dbus-service-slot23 system:
24 command: bin/test-snapd-dbus-service system
25 passthrough:
26 daemon: dbus
27 bus-name: io.snapcraft.SnapDbusService
28 plugs:
29 - network
30 slots:
31 - dbus-system-slot
19parts:32parts:
20 test-snapd-dbus-service:33 test-snapd-dbus-service:
34 source: .
21 plugin: python335 plugin: python3
22 stage-packages:36 stage-packages:
23 - python3-dbus37 - python3-dbus
24 - python3-gi38 - python3-gi
25 - gir1.2-glib-2.039 - gir1.2-glib-2.0
26 copy:
27 plugin: dump
28 source: .

Subscribers

People subscribed via source and target branches