Skip to content

Commit

Permalink
Started with systemd proxies collection
Browse files Browse the repository at this point in the history
  • Loading branch information
igo95862 committed Feb 11, 2021
1 parent 7b5cd03 commit e78c76d
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/sdbus/_proxies_common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from __future__ import annotations

from pathlib import Path
from typing import Any, Dict, Optional, Tuple, Union
from typing import Any, Dict, Optional, Tuple, Union, NamedTuple


class NotificationsHelper:
Expand Down Expand Up @@ -102,3 +102,16 @@ def create_hints(
hints_dict['y'] = ('i', xy_pos[1])

return hints_dict


class SystemdUnitListTuple(NamedTuple):
primary_name: str
description: str
load_state: str
active_state: str
sub_state: str
followed_unit: str
unit_path: str
job_id: int
job_type: str
job_path: str
2 changes: 2 additions & 0 deletions src/sdbus/async_proxies/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@

from .freedesktop import (FreedesktopDbus, FreedesktopNotifications,
NotificationsInterface)
from .systemd import SystemdManager, SystemdUnitListTuple

__all__ = [
'FreedesktopDbus', 'FreedesktopNotifications',
'NotificationsInterface',
'SystemdManager', 'SystemdUnitListTuple',
]
66 changes: 66 additions & 0 deletions src/sdbus/async_proxies/systemd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# SPDX-License-Identifier: LGPL-2.1-or-later

# Copyright (C) 2020, 2021 igo95862

# This file is part of python-sdbus

# This library 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 2.1 of the License, or (at your option) any later version.

# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.

# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
from __future__ import annotations

from typing import Optional, Tuple, List, AsyncGenerator

from ..dbus_proxy_async import (DbusInterfaceCommonAsync, dbus_method_async,
dbus_property_async, dbus_signal_async)
from ..sd_bus_internals import SdBus
from .._proxies_common import SystemdUnitListTuple


class SystemdManager(
DbusInterfaceCommonAsync,
interface_name='org.freedesktop.systemd1.Manager'):

def __init__(self, bus: Optional[SdBus] = None):
super().__init__()
self._connect(
'org.freedesktop.systemd1',
'/org/freedesktop/systemd1',
bus,
)

@dbus_method_async()
async def list_units(self) -> List[
Tuple[str, str, str, str, str, str, str, int, str, str]]:

raise NotImplementedError

async def list_units_named(self
) -> AsyncGenerator[SystemdUnitListTuple, None]:
for x in await self.list_units():
yield SystemdUnitListTuple(*x)

@dbus_property_async()
def version(self) -> str:
raise NotImplementedError

@dbus_signal_async()
def unit_new(self) -> Tuple[str, str]:
raise NotImplementedError

@dbus_signal_async()
def unit_removed(self) -> Tuple[str, str]:
raise NotImplementedError


__all__ = ('SystemdManager', 'SystemdUnitListTuple')

0 comments on commit e78c76d

Please sign in to comment.