Merge lp:~pete-woods/libqtdbusmock/new-templates-in-common-package into lp:libqtdbusmock

Proposed by Pete Woods
Status: Merged
Approved by: Pete Woods
Approved revision: 52
Merged at revision: 48
Proposed branch: lp:~pete-woods/libqtdbusmock/new-templates-in-common-package
Merge into: lp:libqtdbusmock
Diff against target: 399 lines (+288/-2)
10 files modified
CMakeLists.txt (+1/-0)
debian/changelog (+8/-0)
debian/control (+12/-1)
debian/libqtdbusmock1-common.install (+1/-0)
debian/libqtdbusmock1.symbols (+2/-0)
src/libqtdbusmock/DBusMock.cpp (+28/-1)
src/libqtdbusmock/DBusMock.h (+4/-0)
templates/CMakeLists.txt (+8/-0)
templates/org.freedesktop.hostname1.py (+53/-0)
templates/org.freedesktop.login1.py (+171/-0)
To merge this branch: bzr merge lp:~pete-woods/libqtdbusmock/new-templates-in-common-package
Reviewer Review Type Date Requested Status
Xavi Garcia (community) Approve
Review via email: mp+319972@code.launchpad.net

Commit message

Add new templates to new -common package

Description of the change

Add new templates to new -common package

To post a comment you must log in.
49. By Pete Woods

Remove duplicate property entry

Revision history for this message
Xavi Garcia (xavi-garcia-mena) wrote :

Looks good to me, thanks!

Just 1 ultra ultra ultra minor thing that is not going to block approving this:

In...
 #include <NetworkManager.h>
90 #include <QJsonDocument>
91 +#include <QFile>
92 +#include <QStandardPaths>

QFile should go before QJsonDocument if we follow alphabetical order.

review: Approve
50. By Pete Woods

Remove multiarch and shlibs depends

51. By Pete Woods

Fix Xavi's review comment

52. By Pete Woods

Improve changelog message

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2016-12-12 12:02:52 +0000
+++ CMakeLists.txt 2017-03-16 10:30:45 +0000
@@ -59,6 +59,7 @@
5959
60add_subdirectory("src")60add_subdirectory("src")
61add_subdirectory("data")61add_subdirectory("data")
62add_subdirectory("templates")
6263
63enable_testing()64enable_testing()
64add_subdirectory(tests)65add_subdirectory(tests)
6566
=== modified file 'debian/changelog'
--- debian/changelog 2017-01-06 10:44:45 +0000
+++ debian/changelog 2017-03-16 10:30:45 +0000
@@ -1,3 +1,11 @@
1libqtdbusmock (0.7-0ubuntu1) UNRELEASED; urgency=medium
2
3 * Add hostname1 and login1 templates to new binary package
4 libqtdbusmock1-common.
5 * Search /usr/share/libqtdbusmock/templates for templates.
6
7 -- Pete <pete.woods@canonical.com> Wed, 15 Mar 2017 18:17:19 +0000
8
1libqtdbusmock (0.6+17.04.20170106-0ubuntu1) zesty; urgency=medium9libqtdbusmock (0.6+17.04.20170106-0ubuntu1) zesty; urgency=medium
210
3 * Compatibility with unversioned cmake-extras modules (LP: #1563573)11 * Compatibility with unversioned cmake-extras modules (LP: #1563573)
412
=== modified file 'debian/control'
--- debian/control 2016-12-12 12:02:52 +0000
+++ debian/control 2017-03-16 10:30:45 +0000
@@ -12,7 +12,7 @@
12 pkg-config,12 pkg-config,
13 python3-dbusmock (>= 0.16),13 python3-dbusmock (>= 0.16),
14 qtbase5-dev,14 qtbase5-dev,
15Standards-Version: 3.9.415Standards-Version: 3.9.7
16Homepage: https://launchpad.net/libqtdbustest16Homepage: https://launchpad.net/libqtdbustest
17# If you aren't a member of ~unity-team but need to upload packaging changes,17# If you aren't a member of ~unity-team but need to upload packaging changes,
18# just go ahead. ~unity-team will notice and sync up the code again.18# just go ahead. ~unity-team will notice and sync up the code again.
@@ -24,6 +24,7 @@
24Multi-Arch: same24Multi-Arch: same
25Pre-Depends: ${misc:Pre-Depends},25Pre-Depends: ${misc:Pre-Depends},
26Depends: python3-dbusmock (>= 0.16),26Depends: python3-dbusmock (>= 0.16),
27 libqtdbusmock1-common (= ${binary:Version}),
27 ${misc:Depends},28 ${misc:Depends},
28 ${shlibs:Depends},29 ${shlibs:Depends},
29Description: Library for mocking DBus interactions using Qt30Description: Library for mocking DBus interactions using Qt
@@ -41,3 +42,13 @@
41 A simple library for mocking DBus services with a Qt API42 A simple library for mocking DBus services with a Qt API
42 .43 .
43 This package contains files that are needed to build.44 This package contains files that are needed to build.
45
46Package: libqtdbusmock1-common
47Section: libs
48Architecture: all
49Pre-Depends: ${misc:Pre-Depends},
50Depends: ${misc:Depends},
51Description: Library for mocking DBus interactions using Qt
52 A simple library for mocking DBus services with a Qt API
53 .
54 This package contains extra dbusmock templates.
4455
=== added file 'debian/libqtdbusmock1-common.install'
--- debian/libqtdbusmock1-common.install 1970-01-01 00:00:00 +0000
+++ debian/libqtdbusmock1-common.install 2017-03-16 10:30:45 +0000
@@ -0,0 +1,1 @@
1usr/share
02
=== modified file 'debian/libqtdbusmock1.symbols'
--- debian/libqtdbusmock1.symbols 2016-12-06 12:09:09 +0000
+++ debian/libqtdbusmock1.symbols 2017-03-16 10:30:45 +0000
@@ -47,6 +47,8 @@
47 (c++)"QtDBusMock::DBusMock::registerURfkill(QMap<QString, QVariant> const&)@Base" 0.5+15.10.2015100947 (c++)"QtDBusMock::DBusMock::registerURfkill(QMap<QString, QVariant> const&)@Base" 0.5+15.10.20151009
48 (c++)"QtDBusMock::DBusMock::registerTemplate(QString const&, QString const&, QMap<QString, QVariant> const&, QDBusConnection::BusType)@Base" 0.5+15.10.2015100948 (c++)"QtDBusMock::DBusMock::registerTemplate(QString const&, QString const&, QMap<QString, QVariant> const&, QDBusConnection::BusType)@Base" 0.5+15.10.20151009
49 (c++)"QtDBusMock::DBusMock::registerTimeDate(QMap<QString, QVariant> const&)@Base" 0.5+15.10.2015100949 (c++)"QtDBusMock::DBusMock::registerTimeDate(QMap<QString, QVariant> const&)@Base" 0.5+15.10.20151009
50 (c++)"QtDBusMock::DBusMock::registerLogin1(QMap<QString, QVariant> const&)@Base" 0replaceme
51 (c++)"QtDBusMock::DBusMock::registerHostname1(QMap<QString, QVariant> const&)@Base" 0replaceme
50 (c++)"QtDBusMock::DBusMock::registerPolicyKit(QMap<QString, QVariant> const&)@Base" 0.5+15.10.2015100952 (c++)"QtDBusMock::DBusMock::registerPolicyKit(QMap<QString, QVariant> const&)@Base" 0.5+15.10.20151009
51 (c++)"QtDBusMock::DBusMock::registerNetworkManager(QMap<QString, QVariant> const&)@Base" 0.5+15.10.2015100953 (c++)"QtDBusMock::DBusMock::registerNetworkManager(QMap<QString, QVariant> const&)@Base" 0.5+15.10.20151009
52 (c++)"QtDBusMock::DBusMock::registerGnomeScreensaver(QMap<QString, QVariant> const&)@Base" 0.5+15.10.2015100954 (c++)"QtDBusMock::DBusMock::registerGnomeScreensaver(QMap<QString, QVariant> const&)@Base" 0.5+15.10.20151009
5355
=== modified file 'src/libqtdbusmock/DBusMock.cpp'
--- src/libqtdbusmock/DBusMock.cpp 2016-11-25 13:35:18 +0000
+++ src/libqtdbusmock/DBusMock.cpp 2017-03-16 10:30:45 +0000
@@ -20,7 +20,9 @@
20#include <libqtdbustest/QProcessDBusService.h>20#include <libqtdbustest/QProcessDBusService.h>
2121
22#include <NetworkManager.h>22#include <NetworkManager.h>
23#include <QFile>
23#include <QJsonDocument>24#include <QJsonDocument>
25#include <QStandardPaths>
2426
25using namespace QtDBusTest;27using namespace QtDBusTest;
2628
@@ -84,7 +86,22 @@
84 QDBusConnection::BusType busType) {86 QDBusConnection::BusType busType) {
85 QStringList arguments;87 QStringList arguments;
86 arguments << "-m" << "dbusmock";88 arguments << "-m" << "dbusmock";
87 arguments << "--template" << templateName;89
90 bool found = false;
91 if (!templateName.contains(QDir::separator())) {
92 auto dirs = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
93 for (const auto & dir : dirs) {
94 auto path = QDir(QDir(QDir(dir).filePath("libqtdbusmock")).filePath("templates")).filePath(templateName + ".py");
95 if (QFileInfo::exists(path)) {
96 arguments << "--template" << path;
97 found = true;
98 break;
99 }
100 }
101 }
102 if (!found) {
103 arguments << "--template" << templateName;
104 }
88105
89 if (!parameters.isEmpty())106 if (!parameters.isEmpty())
90 {107 {
@@ -155,6 +172,16 @@
155 QDBusConnection::SystemBus);172 QDBusConnection::SystemBus);
156}173}
157174
175void DBusMock::registerHostname1(const QVariantMap& parameters) {
176 registerTemplate("org.freedesktop.hostname1", "org.freedesktop.hostname1", parameters,
177 QDBusConnection::SystemBus);
178}
179
180void DBusMock::registerLogin1(const QVariantMap& parameters) {
181 registerTemplate("org.freedesktop.login1", "org.freedesktop.login1", parameters,
182 QDBusConnection::SystemBus);
183}
184
158void DBusMock::registerURfkill() {185void DBusMock::registerURfkill() {
159 registerURfkill(QVariantMap());186 registerURfkill(QVariantMap());
160}187}
161188
=== modified file 'src/libqtdbusmock/DBusMock.h'
--- src/libqtdbusmock/DBusMock.h 2016-11-25 13:35:18 +0000
+++ src/libqtdbusmock/DBusMock.h 2017-03-16 10:30:45 +0000
@@ -77,6 +77,10 @@
7777
78 virtual void registerTimeDate(const QVariantMap& parameters = QVariantMap());78 virtual void registerTimeDate(const QVariantMap& parameters = QVariantMap());
7979
80 virtual void registerHostname1(const QVariantMap& parameters = QVariantMap());
81
82 virtual void registerLogin1(const QVariantMap& parameters = QVariantMap());
83
80 virtual void registerURfkill();84 virtual void registerURfkill();
8185
82 virtual void registerURfkill(const QVariantMap& parameters);86 virtual void registerURfkill(const QVariantMap& parameters);
8387
=== added directory 'templates'
=== added file 'templates/CMakeLists.txt'
--- templates/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ templates/CMakeLists.txt 2017-03-16 10:30:45 +0000
@@ -0,0 +1,8 @@
1
2install(
3 FILES
4 "org.freedesktop.hostname1.py"
5 "org.freedesktop.login1.py"
6 DESTINATION
7 "${CMAKE_INSTALL_DATADIR}/libqtdbusmock/templates/"
8)
09
=== added file 'templates/org.freedesktop.hostname1.py'
--- templates/org.freedesktop.hostname1.py 1970-01-01 00:00:00 +0000
+++ templates/org.freedesktop.hostname1.py 2017-03-16 10:30:45 +0000
@@ -0,0 +1,53 @@
1'''Hostname1 mock template
2'''
3
4# This program is free software; you can redistribute it and/or modify it under
5# the terms of the GNU Lesser General Public License as published by the Free
6# Software Foundation; either version 3 of the License, or (at your option) any
7# later version. See http://www.gnu.org/copyleft/lgpl.html for the full text
8# of the license.
9
10__author__ = 'Pete Woods'
11__email__ = 'pete.woods@canonical.com'
12__copyright__ = '(c) 2016 Canonical Ltd.'
13__license__ = 'LGPL 3+'
14
15import dbus
16import uuid
17import binascii
18
19from dbusmock import MOCK_IFACE
20import dbusmock
21
22
23BUS_NAME = 'org.freedesktop.hostname1'
24MAIN_IFACE = 'org.freedesktop.hostname1'
25MAIN_OBJ = '/org/freedesktop/hostname1'
26SYSTEM_BUS = True
27
28
29def load(mock, parameters):
30 mock.AddProperties(MAIN_IFACE, {
31 'Hostname': parameters.get('Hostname', 'my-computer'),
32 'StaticHostname': parameters.get('StaticHostname', 'ubuntu'),
33 'PrettyHostname': parameters.get('PrettyHostname', ''),
34 'IconName': parameters.get('IconName', 'computer-vm'), # e.g. "computer-laptop", "computer-desktop"
35 'Chassis': parameters.get('Chassis', 'vm'), # currently defined set: "desktop", "laptop", "server", "tablet", "handset", "vm" and "container"
36 'Deployment': parameters.get('Deployment', ''),
37 'Location': parameters.get('Location', ''),
38 'KernelName': parameters.get('KernelName', 'Linux'),
39 'KernelRelease': parameters.get('KernelRelease', '4.4.0-53-generic'),
40 'KernelVersion': parameters.get('KernelVersion', '#74-Ubuntu SMP Fri Dec 2 15:59:10 UTC 2016'),
41 'OperatingSystemPrettyName': parameters.get('OperatingSystemPrettyName', 'Ubuntu 16.04.1 LTS'),
42 'OperatingSystemCPEName': parameters.get('OperatingSystemCPEName', ''),
43 })
44
45 mock.AddMethods(MAIN_IFACE, [
46 ('SetHostname', 'sb', '', "ret = self.Set('%s', 'Hostname', args[0])" % MAIN_IFACE),
47 ('SetStaticHostname', 'sb', '', "ret = self.Set('%s', 'StaticHostname', args[0])" % MAIN_IFACE),
48 ('SetPrettyHostname', 'sb', '', "ret = self.Set('%s', 'PrettyHostname', args[0])" % MAIN_IFACE),
49 ('SetIconName', 'sb', '', "ret = self.Set('%s', 'IconName', args[0])" % MAIN_IFACE),
50 ('SetChassis', 'sb', '', "ret = self.Set('%s', 'Chassis', args[0])" % MAIN_IFACE),
51 ('SetDeployment', 'sb', '', "ret = self.Set('%s', 'Deployment', args[0])" % MAIN_IFACE),
52 ('SetLocation', 'sb', '', "ret = self.Set('%s', 'Location', args[0])" % MAIN_IFACE),
53 ])
054
=== added file 'templates/org.freedesktop.login1.py'
--- templates/org.freedesktop.login1.py 1970-01-01 00:00:00 +0000
+++ templates/org.freedesktop.login1.py 2017-03-16 10:30:45 +0000
@@ -0,0 +1,171 @@
1'''Login1 mock template
2'''
3
4# This program is free software; you can redistribute it and/or modify it under
5# the terms of the GNU Lesser General Public License as published by the Free
6# Software Foundation; either version 3 of the License, or (at your option) any
7# later version. See http://www.gnu.org/copyleft/lgpl.html for the full text
8# of the license.
9
10__author__ = 'Pete Woods'
11__email__ = 'pete.woods@canonical.com'
12__copyright__ = '(c) 2017 Canonical Ltd.'
13__license__ = 'LGPL 3+'
14
15import dbus
16import uuid
17import binascii
18
19from dbusmock import MOCK_IFACE
20import dbusmock
21
22
23BUS_NAME = 'org.freedesktop.login1'
24MAIN_IFACE = 'org.freedesktop.login1.Manager'
25MAIN_OBJ = '/org/freedesktop/login1'
26SYSTEM_BUS = True
27
28SEAT_IFACE = 'org.freedesktop.login1.Seat'
29SEAT_PATH = '/org/freedesktop/login1/seat/'
30
31def load(mock, parameters):
32 mock.seats = {}
33
34 add_seat(mock, parameters.get('DefaultSeat', {}), True)
35
36 mock.list_seats = list_seats
37 mock.get_seat = get_seat
38
39 mock.AddProperties(MAIN_IFACE, {
40 'EnableWallMessages': parameters.get('EnableWallMessages', False),
41 'WallMessage': parameters.get('WallMessage', ''),
42 'NAutoVTs': parameters.get('NAutoVTs', dbus.UInt32(6)),
43 'KillOnlyUsers': parameters.get('KillOnlyUsers', dbus.Array([], signature='s')),
44 'KillExcludeUsers': parameters.get('KillExcludeUsers', dbus.Array(['root'], signature='s')),
45 'KillUserProcesses': parameters.get('KillUserProcesses', False),
46 'RebootToFirmwareSetup': parameters.get('RebootToFirmwareSetup', False),
47 'IdleHint': parameters.get('IdleHint', False),
48 'IdleSinceHint': parameters.get('IdleSinceHint', dbus.UInt64(1489580452083866)),
49 'IdleSinceHintMonotonic': parameters.get('IdleSinceHintMonotonic', dbus.UInt64(8134597164)),
50 'BlockInhibited': parameters.get('BlockInhibited', 'handle-power-key:handle-suspend-key:handle-hibernate-key:handle-lid-switch'),
51 'DelayInhibited': parameters.get('DelayInhibited', 'sleep'),
52 'InhibitDelayMaxUSec': parameters.get('InhibitDelayMaxUSec', dbus.UInt64(5000000)),
53 'HandlePowerKey': parameters.get('HandlePowerKey', 'poweroff'),
54 'HandleSuspendKey': parameters.get('HandleSuspendKey', 'suspend'),
55 'HandleHibernateKey': parameters.get('HandleHibernateKey', 'hibernate'),
56 'HandleLidSwitch': parameters.get('HandleLidSwitch', 'suspend'),
57 'HandleLidSwitchDocked': parameters.get('HandleLidSwitchDocked', 'ignore'),
58 'HoldoffTimeoutUSec': parameters.get('HoldoffTimeoutUSec', dbus.UInt64(30000000)),
59 'IdleAction': parameters.get('IdleAction', 'ignore'),
60 'IdleActionUSec': parameters.get('IdleActionUSec', dbus.UInt64(1800000000)),
61 'PreparingForShutdown': parameters.get('PreparingForShutdown', False),
62 'PreparingForSleep': parameters.get('PreparingForSleep', False),
63 'ScheduledShutdown': parameters.get('ScheduledShutdown', dbus.Struct(('', 0), signature='st')),
64 'Docked': parameters.get('Docked', False),
65 })
66
67 mock.AddMethods(MAIN_IFACE, [
68 ('GetSession', 's', 'o', "ret = dbus.ObjectPath('/')"),
69 ('GetSessionByPID', 'u', 'o', "ret = dbus.ObjectPath('/')"),
70 ('GetUser', 'u', 'o', "ret = dbus.ObjectPath('/')"),
71 ('GetUserByPID', 'u', 'o', "ret = dbus.ObjectPath('/')"),
72 ('GetSeat', 's', 'o', "ret = self.get_seat(self, args[0])"),
73
74 ('ListSessions', '', 'a(susso)', ""),
75 ('ListUsers', '', 'a(uso)', ""),
76 ('ListSeats', '', 'a(so)', "ret = self.list_seats(self)"),
77 ('ListInhibitors', '', 'a(ssssuu)', ""),
78
79 ('CreateSession', 'uusssssussbssa(sv)', 'soshusub', ""),
80 ('ReleaseSession', 's', '', ""),
81 ('ActivateSession', 's', '', ""),
82 ('ActivateSessionOnSeat', 'ss', '', ""),
83 ('LockSession', 's', '', ""),
84 ('UnlockSession', 's', '', ""),
85 ('LockSessions', '', '', ""),
86 ('UnlockSessions', '', '', ""),
87 ('KillSession', 'ssi', '', ""),
88 ('KillUser', 'ui', '', ""),
89 ('TerminateSession', 's', '', ""),
90 ('TerminateUser', 'u', '', ""),
91 ('TerminateSeat', 's', '', ""),
92 ('SetUserLinger', 'ubb', '', ""),
93 ('AttachDevice', 'ssb', '', ""),
94 ('FlushDevices', 'b', '', ""),
95 ('PowerOff', 'b', '', ""),
96 ('Reboot', 'b', '', ""),
97 ('Suspend', 'b', '', ""),
98 ('Hibernate', 'b', '', ""),
99 ('HybridSleep', 'b', '', ""),
100 ('CanPowerOff', '', 's', "ret = ''"),
101 ('CanReboot', '', 's', "ret = ''"),
102 ('CanSuspend', '', 's', "ret = ''"),
103 ('CanHibernate', '', 's', "ret = ''"),
104 ('CanHybridSleep', '', 's', "ret = ''"),
105 ('ScheduleShutdown', 'st', '', ""),
106 ('CancelScheduledShutdown', '', 'b', "ret = False"),
107 ('Inhibit', 'ssss', 'h', "ret = ?"),
108 ('CanRebootToFirmwareSetup', '', 's', "ret = ''"),
109 ('SetRebootToFirmwareSetup', 'b', '', ""),
110 ('SetWallMessage', 'sb', '', ""),
111 ])
112
113def add_seat(self, properties, is_self):
114 # find a new name
115 count = 0
116 while True:
117 id = 'seat%d' % count
118 if id not in self.seats:
119 break
120 count += 1
121
122 path = dbus.ObjectPath(SEAT_PATH + id)
123
124 seat_props = {
125 'Id': id,
126 'ActiveSession': properties.get('ActiveSession', dbus.Struct(('c2', '/org/freedesktop/login1/session/c2'), signature='so')),
127 'CanMultiSession': properties.get('CanMultiSession', True),
128 'CanTTY': properties.get('CanTTY', True),
129 'CanGraphical': properties.get('CanGraphical', True),
130 'Sessions': properties.get('Sessions', dbus.Array([('c2', '/org/freedesktop/login1/session/c2')], signature='(so)')),
131 'IdleHint': properties.get('IdleHint', False),
132 'IdleSinceHint': properties.get('IdleSinceHint', dbus.UInt64(1489590854604069)),
133 'IdleSinceHintMonotonic': properties.get('IdleSinceHintMonotonic', dbus.UInt64(18537117367)),
134 }
135
136 seat_methods = [
137 ('Terminate', '', '', ""),
138 ('ActivateSession', 's', '', ""),
139 ('SwitchTo', 'u', '', ""),
140 ('SwitchToNext', '', '', ""),
141 ('SwitchToPrevious', '', '', ""),
142 ]
143
144 self.seats[id] = self.AddObject(path,
145 SEAT_IFACE,
146 seat_props,
147 seat_methods)
148
149 if is_self:
150 self_path = dbus.ObjectPath(SEAT_PATH + 'self')
151 try:
152 self.RemoveObject(self_path)
153 except dbus.exceptions.DBusException:
154 pass
155 self.AddObject(self_path,
156 SEAT_IFACE,
157 seat_props,
158 seat_methods)
159
160 return path
161
162def get_seat(self, id):
163 if id in self.seats:
164 return SEAT_PATH + id
165 raise dbus.exceptions.DBusException()
166
167def list_seats(self):
168 result = dbus.Array([], signature='(so)')
169 for id in self.seats:
170 result.append((id, SEAT_PATH + id))
171 return result

Subscribers

People subscribed via source and target branches

to all changes: