File: timedated.py

package info (click to toggle)
python-dbusmock 0.11.4-1%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 556 kB
  • ctags: 639
  • sloc: python: 4,442; sh: 5; makefile: 4
file content (48 lines) | stat: -rw-r--r-- 1,843 bytes parent folder | download | duplicates (2)
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
'''systemd timedated mock template

This creates the expected methods and properties of the main
org.freedesktop.timedate object. You can specify D-BUS property values like
"Timezone" or "NTP" in "parameters".
'''

# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option) any
# later version.  See http://www.gnu.org/copyleft/lgpl.html for the full text
# of the license.

__author__ = 'Iain Lane'
__email__ = 'iain.lane@canonical.com'
__copyright__ = '(c) 2013 Canonical Ltd.'
__license__ = 'LGPL 3+'

import dbus

BUS_NAME = 'org.freedesktop.timedate1'
MAIN_OBJ = '/org/freedesktop/timedate1'
MAIN_IFACE = 'org.freedesktop.timedate1'
SYSTEM_BUS = True


def setProperty(prop):
    return 'self.Set("%s", "%s", args[0]); self.EmitSignal("%s", \
            "PropertiesChanged", "sa{sv}as", ["%s", {"%s":args[0]},["%s"]])' \
            % (MAIN_IFACE, prop, dbus.PROPERTIES_IFACE, MAIN_IFACE, prop, prop)


def load(mock, parameters):
    mock.AddMethods(MAIN_IFACE, [
        # There's nothing this can usefully do, but provide it for compatibility
        ('SetTime', 'xbb', '', ''),
        ('SetTimezone', 'sb', '', setProperty('Timezone')),
        ('SetLocalRTC', 'bbb', '', setProperty('LocalRTC')),
        ('SetNTP', 'bb', '', setProperty('NTP'))
    ])

    mock.AddProperties(MAIN_IFACE,
                       dbus.Dictionary({
                           'Timezone': parameters.get('Timezone', 'Etc/Utc'),
                           'LocalRTC': parameters.get('LocalRTC', False),
                           'NTP': parameters.get('NTP', True),
                           'CanNTP': parameters.get('CanNTP', True)
                       }, signature='sv'))