Debian Codegraph @

src/sdbus_block/dbus_daemon/__init__.py

raw symbols SCIP
1 # SPDX-License-Identifier: LGPL-2.1-or-later
2
3 # Copyright (C) 2020, 2021 igo95862
4
5 # This file is part of python-sdbus
6
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
11
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
16
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 from __future__ import annotations
21
22 from typing import Optional
23
24 from sdbus import DbusInterfaceCommon, SdBus, dbus_method, dbus_property
25
26
27 class FreedesktopDbus(DbusInterfaceCommon,
28 interface_name='org.freedesktop.DBus'):
29 """D-Bus daemon."""
30
31 def __init__(self, bus: Optional[SdBus] = None):
32 """This is the D-Bus daemon interface. Used for querying D-Bus state.
33
34 D-Bus interface object path and service name is
35 predetermined.
36 (at ``'org.freedesktop.DBus'``, ``'/org/freedesktop/DBus'``)
37
38 :param SdBus bus:
39 Optional D-Bus connection.
40 If not passed the default D-Bus will be used.
41 """
42 super().__init__(
43 'org.freedesktop.DBus',
44 '/org/freedesktop/DBus',
45 bus,
46 )
47
48 @dbus_method('s', method_name='GetConnectionUnixProcessID')
49 def get_connection_pid(self, service_name: str) -> int:
50 """Get process ID that owns a specified name.
51
52 :param str service_name: Service name to query.
53 :return: PID of name owner
54 :raises DbusNameHasNoOwnerError: Nobody owns that name
55 """
56 raise NotImplementedError
57
58 @dbus_method('s', method_name='GetConnectionUnixUser')
59 def get_connection_uid(self, service_name: str) -> int:
60 """Get process user ID that owns a specified name.
61
62 :param str service_name: Service name to query.
63 :return: User ID of name owner
64 :raises DbusNameHasNoOwnerError: Nobody owns that name
65 """
66 raise NotImplementedError
67
68 @dbus_method()
69 def get_id(self) -> str:
70 """Returns machine id where bus is run. (stored in ``/etc/machine-id``)
71
72 :return: Machine id
73 """
74 raise NotImplementedError
75
76 @dbus_method('s')
77 def get_name_owner(self, service_name: str) -> str:
78 """Returns unique bus name (i.e. ``':1.94'``) for given service name.
79
80 :param str service_name: Service name to query.
81 :return: Unique bus name.
82 :raises DbusNameHasNoOwnerError: Nobody owns that name
83 """
84 raise NotImplementedError
85
86 @dbus_method()
87 def list_activatable_names(self) -> list[str]:
88 """Lists all activatable services names.
89
90 :return: List of all names.
91 """
92 raise NotImplementedError
93
94 @dbus_method()
95 def list_names(self) -> list[str]:
96 """List all services and connections currently of the bus.
97
98 :return: List of all current names.
99 """
100 raise NotImplementedError
101
102 @dbus_method('s')
103 def name_has_owner(self, service_name: str) -> bool:
104 """Return True if someone already owns the name, False if nobody does.
105
106 :param str service_name: Service name to query.
107 :return: Is the name owned?
108 """
109 raise NotImplementedError
110
111 @dbus_method('su')
112 def start_service_by_name(
113 self,
114 service_name: str,
115 flags: int = 0) -> int:
116 """Starts a specified service.
117
118 Flags parameter is not used currently and should be
119 omitted or set to 0.
120
121 :param str service_name: Service name to start.
122 :param int flags: Not used. Omit or pass 0.
123 :return: 1 on success, 2 if already started.
124 """
125 raise NotImplementedError
126
127 @dbus_property('as')
128 def features(self) -> list[str]:
129 """List of D-Bus daemon features.
130
131 Features include:
132
133 * 'AppArmor' - Messages filtered by AppArmor on this bus.
134 * 'HeaderFiltering' - Messages are filtered if they have incorrect \
135 header fields.
136 * 'SELinux' - Messages filtered by SELinux on this bus.
137 * 'SystemdActivation' - services activated by systemd if their \
138 .service file specifies a D-Bus name.
139 """
140 raise NotImplementedError
141
142 @dbus_property('as')
143 def interfaces(self) -> list[str]:
144 """Extra D-Bus daemon interfaces"""
145 raise NotImplementedError