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
1=== modified file 'bin/test-snapd-dbus-service'
2--- bin/test-snapd-dbus-service 2017-01-16 16:31:25 +0000
3+++ bin/test-snapd-dbus-service 2018-12-05 12:13:07 +0000
4@@ -1,7 +1,7 @@
5 #!/usr/bin/python3
6
7 import os
8-import os.path
9+import sys
10 import glob
11 # ensure that typelib path points to the right directory,
12 # eg. $SNAP/usr/lib/x86_64-linux-gnu/girepository-1.0 on amd64
13@@ -15,18 +15,34 @@
14 from dbus.mainloop.glib import DBusGMainLoop
15 DBusGMainLoop(set_as_default=True)
16
17+BUS_NAME = 'io.snapcraft.SnapDbusService'
18+OBJECT_PATH = '/io/snapcraft/SnapDbusService'
19+
20
21 class ServerObject(dbus.service.Object):
22- def __init__(self):
23- bus_name = dbus.service.BusName(
24- 'io.snapcraft.SnapDbusService',bus=dbus.SessionBus())
25- dbus.service.Object.__init__(self, bus_name, '/io/snapcraft/SnapDbusService')
26 @dbus.service.method('io.snapcraft.ExampleInterface')
27 def ExampleMethod(self):
28- return "hello world"
29+ return "hello world"
30
31
32 if __name__ == "__main__":
33- server = ServerObject()
34- loop = GLib.MainLoop()
35- loop.run()
36+ if sys.argv[1] == 'session':
37+ bus = dbus.SessionBus()
38+ elif sys.argv[1] == 'system':
39+ bus = dbus.SystemBus()
40+ else:
41+ sys.stderr.write("Unknown D-Bus bus: {}\n".format(sys.argv[1]))
42+ sys.exit(1)
43+
44+ main_loop = GLib.MainLoop()
45+ # Make sure we quit when the bus shuts down
46+ bus.add_signal_receiver(
47+ main_loop.quit, signal_name="Disconnected",
48+ path="/org/freedesktop/DBus/Local",
49+ dbus_interface="org.freedesktop.DBus.Local")
50+
51+ server = ServerObject(bus, OBJECT_PATH)
52+ bus_name = dbus.service.BusName(
53+ BUS_NAME, bus, allow_replacement=True, replace_existing=True,
54+ do_not_queue=True)
55+ main_loop.run()
56
57=== added file 'setup.py'
58--- setup.py 1970-01-01 00:00:00 +0000
59+++ setup.py 2018-12-05 12:13:07 +0000
60@@ -0,0 +1,11 @@
61+#!/usr/bin/env python3
62+
63+import setuptools
64+
65+setuptools.setup(
66+ name="test-snapd-dbus-serice",
67+ version="1.0",
68+ scripts=[
69+ "bin/test-snapd-dbus-service"
70+ ],
71+)
72
73=== modified file 'snapcraft.yaml'
74--- snapcraft.yaml 2017-01-16 16:31:25 +0000
75+++ snapcraft.yaml 2018-12-05 12:13:07 +0000
76@@ -3,26 +3,37 @@
77 summary: Python based example dbus service
78 description: ...
79 slots:
80- test-snapd-dbus-service-slot:
81+ dbus-session-slot:
82 interface: dbus
83 bus: session
84- service: true
85+ activatable: true
86+ name: io.snapcraft.SnapDbusService
87+ dbus-system-slot:
88+ interface: dbus
89+ bus: system
90+ activatable: true
91 name: io.snapcraft.SnapDbusService
92 apps:
93- test-snapd-dbus-service:
94- command: bin/test-snapd-dbus-service
95- plugs:
96- - network
97- - network-bind
98- slots:
99- - test-snapd-dbus-service-slot
100+ session:
101+ command: bin/test-snapd-dbus-service session
102+ plugs:
103+ - network
104+ slots:
105+ - dbus-session-slot
106+ system:
107+ command: bin/test-snapd-dbus-service system
108+ passthrough:
109+ daemon: dbus
110+ bus-name: io.snapcraft.SnapDbusService
111+ plugs:
112+ - network
113+ slots:
114+ - dbus-system-slot
115 parts:
116 test-snapd-dbus-service:
117+ source: .
118 plugin: python3
119 stage-packages:
120 - python3-dbus
121 - python3-gi
122 - gir1.2-glib-2.0
123- copy:
124- plugin: dump
125- source: .

Subscribers

People subscribed via source and target branches