[go: up one dir, main page]

File: client.py

package info (click to toggle)
comitup 1.43-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,252 kB
  • sloc: python: 3,093; javascript: 1,261; sh: 95; makefile: 34
file content (57 lines) | stat: -rwxr-xr-x 1,568 bytes parent folder | download
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
#!/usr/bin/python3
# Copyright (c) 2017-2019 David Steele <dsteele@gmail.com>
#
# SPDX-License-Identifier: GPL-2.0-or-later
# License-Filename: LICENSE

#
# Copyright 2016-2017 David Steele <steele@debian.org>
# This file is part of comitup
# Available under the terms of the GNU General Public License version 2
# or later
#

import sys

import dbus

from comitup.blink import blink, can_blink  # noqa


class CiuClient(object):
    # Make the dbus functions late binding, to facilitate testing.

    # These are the methods supported, with the corresponding dbus
    # endpoint name.
    methods = {
        "ciu_info": "get_info",
        "ciu_state": "state",
        "ciu_points": "access_points",
        "ciu_connect": "connect",
        "ciu_delete": "delete_connection",
        "ciu_nuke": "nuke",
    }

    def __init__(self):
        self.service = None

    def __getattr__(self, name):
        if name not in self.methods:
            raise AttributeError("Attribute {} not found".format(name))

        try:
            if not self.service:
                bus = dbus.SystemBus()
                self.service = bus.get_object(
                    "com.github.davesteele.comitup",
                    "/com/github/davesteele/comitup",
                )
            func = self.service.get_dbus_method(
                self.methods[name], "com.github.davesteele.comitup"
            )
        except dbus.exceptions.DBusException:
            sys.exit(1)

        # connect as an unbound function
        self.__setattr__(name, func)
        return func