Ejemplo n.º 1
0
    def test_service(self):
        """Test the DBus service object."""
        bus = Mock()
        service = DBusServiceIdentifier(namespace=("a", "b", "c"),
                                        message_bus=bus)
        self.assert_namespace(service, ("a", "b", "c"))
        self.assert_interface(service, "a.b.c")
        self.assert_object(service, "/a/b/c")
        self.assert_service(service, "a.b.c")

        service = DBusServiceIdentifier(namespace=("a", "b", "c"),
                                        service_version=3,
                                        interface_version=5,
                                        object_version=7,
                                        message_bus=bus)
        self.assert_namespace(service, ("a", "b", "c"))
        self.assert_interface(service, "a.b.c5")
        self.assert_object(service, "/a/b/c7")
        self.assert_service(service, "a.b.c3")

        service = DBusServiceIdentifier(basename="d",
                                        namespace=("a", "b", "c"),
                                        service_version=3,
                                        interface_version=5,
                                        object_version=7,
                                        message_bus=bus)
        self.assert_namespace(service, ("a", "b", "c", "d"))
        self.assert_interface(service, "a.b.c.d5")
        self.assert_object(service, "/a/b/c/d7")
        self.assert_service(service, "a.b.c.d3")
Ejemplo n.º 2
0
    def test_get_proxy(self):
        """Test getting a proxy."""
        bus = Mock()
        namespace = ("a", "b", "c")

        service = DBusServiceIdentifier(namespace=namespace, message_bus=bus)

        obj = DBusObjectIdentifier(basename="object", namespace=namespace)

        service.get_proxy()
        bus.get_proxy.assert_called_with("a.b.c", "/a/b/c", None)
        bus.reset_mock()

        service.get_proxy("/a/b/c/object")
        bus.get_proxy.assert_called_with("a.b.c", "/a/b/c/object", None)
        bus.reset_mock()

        service.get_proxy(obj)
        bus.get_proxy.assert_called_with("a.b.c", "/a/b/c/object", None)
        bus.reset_mock()
Ejemplo n.º 3
0
    def test_get_proxy_for_interface(self):
        """Test getting a proxy for an interface."""
        bus = Mock()
        namespace = ("a", "b", "c")

        service = DBusServiceIdentifier(namespace=namespace, message_bus=bus)

        interface = DBusInterfaceIdentifier(basename="interface",
                                            namespace=namespace)

        service.get_proxy(interface_name="a.b.c.interface")
        bus.get_proxy.assert_called_with("a.b.c", "/a/b/c", "a.b.c.interface")
        bus.reset_mock()

        service.get_proxy(interface_name=interface)
        bus.get_proxy.assert_called_with("a.b.c", "/a/b/c", "a.b.c.interface")
        bus.reset_mock()
Ejemplo n.º 4
0
    def test_get_proxy_with_bus_arguments(self):
        """Test getting a proxy with an additional arguments."""
        bus = Mock()
        error_mapper = Mock()
        namespace = ("a", "b", "c")

        service = DBusServiceIdentifier(namespace=namespace, message_bus=bus)

        service.get_proxy(error_mapper=error_mapper)
        bus.get_proxy.assert_called_with("a.b.c",
                                         "/a/b/c",
                                         None,
                                         error_mapper=error_mapper)
        bus.reset_mock()

        service.get_proxy(interface_name=service, error_mapper=error_mapper)
        bus.get_proxy.assert_called_with("a.b.c",
                                         "/a/b/c",
                                         "a.b.c",
                                         error_mapper=error_mapper)
        bus.reset_mock()
Ejemplo n.º 5
0
#
# The common definitions
#
from dasbus.connection import SessionMessageBus
from dasbus.identifier import DBusServiceIdentifier

# Define the message bus.
SESSION_BUS = SessionMessageBus()

# Define services and objects.
NOTIFICATIONS = DBusServiceIdentifier(namespace=("org", "freedesktop",
                                                 "Notifications"),
                                      message_bus=SESSION_BUS)
Ejemplo n.º 6
0
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions of
# the GNU General Public License v.2, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY expressed or implied, including the implied warranties of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
# Public License for more details.  You should have received a copy of the
# GNU General Public License along with this program; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.  Any Red Hat trademarks that are incorporated in the
# source code or documentation are not subject to the GNU General Public
# License and may only be used or replicated with the express permission of
# Red Hat, Inc.
#
"""This module contains constants that are used by various parts of the addon."""

from dasbus.identifier import DBusServiceIdentifier
from pyanaconda.core.dbus import DBus
from pyanaconda.modules.common.constants.namespaces import ADDONS_NAMESPACE

# These define location of the addon's service on D-Bus. See also the data/*.conf file.

HELLO_WORLD_NAMESPACE = (*ADDONS_NAMESPACE, "HelloWorld")

HELLO_WORLD = DBusServiceIdentifier(namespace=HELLO_WORLD_NAMESPACE,
                                    message_bus=DBus)

# It's better to store paths without the initial slash "/" because of os.path.join behavior.
HELLO_WORLD_FILE_PATH = "root/hello_world.txt"
Ejemplo n.º 7
0
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
from pyanaconda.core.dbus import SystemBus, DBus
from dasbus.identifier import DBusServiceIdentifier
from pyanaconda.modules.common.constants.namespaces import BOSS_NAMESPACE, TIMEZONE_NAMESPACE, \
    NETWORK_NAMESPACE, LOCALIZATION_NAMESPACE, SECURITY_NAMESPACE, USERS_NAMESPACE, BAZ_NAMESPACE, \
    PAYLOADS_NAMESPACE, STORAGE_NAMESPACE, SERVICES_NAMESPACE

# Anaconda services.

BOSS = DBusServiceIdentifier(namespace=BOSS_NAMESPACE, message_bus=DBus)

BAZ = DBusServiceIdentifier(namespace=BAZ_NAMESPACE, message_bus=DBus)

TIMEZONE = DBusServiceIdentifier(namespace=TIMEZONE_NAMESPACE,
                                 message_bus=DBus)

NETWORK = DBusServiceIdentifier(namespace=NETWORK_NAMESPACE, message_bus=DBus)

LOCALIZATION = DBusServiceIdentifier(namespace=LOCALIZATION_NAMESPACE,
                                     message_bus=DBus)

SECURITY = DBusServiceIdentifier(namespace=SECURITY_NAMESPACE,
                                 message_bus=DBus)

USERS = DBusServiceIdentifier(namespace=USERS_NAMESPACE, message_bus=DBus)
Ejemplo n.º 8
0
#    This program 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 General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to
#    the Free Software Foundation, Inc.,
#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

from dasbus.connection import SessionMessageBus
from dasbus.identifier import DBusServiceIdentifier

# Constants
XFCONF = DBusServiceIdentifier(
    namespace=("org", "xfce", "Xfconf"),
    message_bus=SessionMessageBus()
)

# Classes


class Xfconf:
    """Wrapper class for the org.xfce.Xfconf Dbus object"""

    def __init__(self):
        self.proxy = XFCONF.get_proxy()

    def get_property(self, channel: str, property: str):
        """ Read a Xfconf property"""
        return self.proxy.GetProperty(channel, property)
Ejemplo n.º 9
0
#
"""This module contains constants that are used by various parts of the addon."""

from dasbus.identifier import DBusServiceIdentifier
from pyanaconda.core.dbus import DBus
from pyanaconda.modules.common.constants.namespaces import ADDONS_NAMESPACE

# These define location of the addon's service on D-Bus. See also the data/*.conf file.

PACKAGE_REMOVE_NAMESPACE = (*ADDONS_NAMESPACE, "PackageRemove")

# ROSA_ANACONDA_NAMESPACE = (
#     "org", "rosa", "Anaconda"
# )

# ROSA_ADDONS_NAMESPACE = (
#     *ROSA_ANACONDA_NAMESPACE,
#     "Addons"
# )

# PACKAGE_REMOVE_NAMESPACE = (
#     *ROSA_ADDONS_NAMESPACE,
#     "PackageRemove"
# )

PACKAGE_REMOVE = DBusServiceIdentifier(namespace=PACKAGE_REMOVE_NAMESPACE,
                                       message_bus=DBus)

PACKAGES_LIST_FILE_PATH = "/etc/anaconda/removable_pkgs.list"
REMOVABLE_PACKAGES_FILE_PATH = "etc/anaconda/pkgs_to_remove.list"
Ejemplo n.º 10
0
#
# Show the current hostname.
#
from dasbus.connection import SystemMessageBus
from dasbus.identifier import DBusServiceIdentifier

# Define the message bus.
SYSTEM_BUS = SystemMessageBus()

# Define services and objects.
HOSTNAME = DBusServiceIdentifier(namespace=("org", "freedesktop", "hostname"),
                                 service_version=1,
                                 object_version=1,
                                 interface_version=1,
                                 message_bus=SYSTEM_BUS)

if __name__ == "__main__":
    # Create a proxy of the object /org/freedesktop/hostname1
    # provided by the service org.freedesktop.hostname1.
    proxy = HOSTNAME.get_proxy()

    # Print a value of the DBus property Hostname.
    print(proxy.Hostname)
Ejemplo n.º 11
0
    "archive",
    "scap-security-guide",
)

SUPPORTED_URL_PREFIXES = (
    "http://",
    "https://",
    "ftp://",  # LABEL:?, hdaX:?,
)

# buffer size for reading and writing out data (in bytes)
IO_BUF_SIZE = 2 * 1024 * 1024

# DBus constants
KDUMP = DBusServiceIdentifier(namespace=ADDONS_NAMESPACE,
                              basename="Kdump",
                              message_bus=DBus)


class OSCAPaddonError(Exception):
    """Exception class for OSCAP addon related errors."""

    pass


class OSCAPaddonNetworkError(OSCAPaddonError):
    """Exception class for OSCAP addon related network errors."""

    pass

Ejemplo n.º 12
0
        SESSION_BUS.disconnect()
        logging.debug("session bus disconnected")
    if LOOP:
        logging.debug("quitting loop")
        LOOP.quit()
        logging.debug("loop quitted")
    else:
        print("no loop to quit")


signal.signal(signal.SIGTERM, term_handler)
signal.signal(signal.SIGINT, term_handler)

SESSION_BUS = SessionMessageBus()

SYSEVENTD = DBusServiceIdentifier(namespace=("net", "cephalopo", "Syseventd"),
                                  message_bus=SESSION_BUS)

NOTIFICATION_PROXY = SESSION_BUS.get_proxy("org.freedesktop.Notifications",
                                           "/org/freedesktop/Notifications")


def _pulse_session():
    pulseses = pulsectl.Pulse(__name__, connect=False, threading_lock=False)
    pulseses.connect(autospawn=False)
    return pulseses


# icon names without URI path should be according to
# https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
def _send_notify(icon_name, urgency_level, body):
    id = NOTIFICATION_PROXY.Notify(
Ejemplo n.º 13
0
def get_dbus_service_identifier(message_bus):
    return DBusServiceIdentifier(namespace=TMP_SERVICE_IDENTIFIER.namespace,
                                 message_bus=message_bus)
Ejemplo n.º 14
0
from dasbus.identifier import DBusServiceIdentifier
from dasbus.loop import EventLoop
from dasbus.server.interface import dbus_interface, dbus_signal
from dasbus.typing import Str, List, Dict, Bool, Int

from bsrv.tools import gen_json
from .logger import Logger

if TYPE_CHECKING:
    from .job import Scheduler

SYSTEM_BUS = SystemMessageBus()
SESSION_BUS = SessionMessageBus()

TMP_SERVICE_IDENTIFIER = DBusServiceIdentifier(namespace=("de", "alxg",
                                                          "bsrvd"),
                                               message_bus=None)

pool = concurrent.futures.ThreadPoolExecutor(max_workers=2)


def get_dbus_service_identifier(message_bus):
    return DBusServiceIdentifier(namespace=TMP_SERVICE_IDENTIFIER.namespace,
                                 message_bus=message_bus)


@dbus_interface(TMP_SERVICE_IDENTIFIER.interface_name)
class DBusInterface(object):
    def __init__(self, scheduler):
        self.scheduler = scheduler
        super(DBusInterface, self).__init__()
Ejemplo n.º 15
0
from dasbus.error import DBusError, ErrorMapper, get_error_decorator
from dasbus.identifier import DBusServiceIdentifier
from dasbus.structure import DBusData
from dasbus.typing import Str, Int

# Define the error mapper.
ERROR_MAPPER = ErrorMapper()

# Define the message bus.
SESSION_BUS = SessionMessageBus(error_mapper=ERROR_MAPPER)

# Define namespaces.
REGISTER_NAMESPACE = ("org", "example", "Register")

# Define services and objects.
REGISTER = DBusServiceIdentifier(namespace=REGISTER_NAMESPACE,
                                 message_bus=SESSION_BUS)

# The decorator for DBus errors.
dbus_error = get_error_decorator(ERROR_MAPPER)


# Define errors.
@dbus_error("InvalidUserError", namespace=REGISTER_NAMESPACE)
class InvalidUser(DBusError):
    """The user is invalid."""
    pass


# Define structures.
class User(DBusData):
    """The user data."""
Ejemplo n.º 16
0
# Copyright (C) 2014 Red Hat, Inc.
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions of
# the GNU General Public License v.2, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY expressed or implied, including the implied warranties of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
# Public License for more details.  You should have received a copy of the
# GNU General Public License along with this program; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.  Any Red Hat trademarks that are incorporated in the
# source code or documentation are not subject to the GNU General Public
# License and may only be used or replicated with the express permission of
# Red Hat, Inc.
#
# Red Hat Author(s): David Shea <*****@*****.**>
#
from dasbus.identifier import DBusServiceIdentifier

from pyanaconda.core.dbus import DBus
from pyanaconda.modules.common.constants.namespaces import ADDONS_NAMESPACE

# The constants
FADUMP_CAPABLE_FILE = "/proc/device-tree/rtas/ibm,configure-kernel-dump"

# DBus constants
KDUMP_NAMESPACE = (*ADDONS_NAMESPACE, "Kdump")

KDUMP = DBusServiceIdentifier(namespace=KDUMP_NAMESPACE, message_bus=DBus)
Ejemplo n.º 17
0
#
# The common definitions
#
from dasbus.connection import SessionMessageBus
from dasbus.identifier import DBusServiceIdentifier

# Define the message bus.
SESSION_BUS = SessionMessageBus()

# Define services and objects.
HELLO_WORLD = DBusServiceIdentifier(namespace=("org", "example", "HelloWorld"),
                                    message_bus=SESSION_BUS)
Ejemplo n.º 18
0
#
# The common definitions
#
from dasbus.connection import SessionMessageBus
from dasbus.identifier import DBusServiceIdentifier, DBusInterfaceIdentifier
from dasbus.server.container import DBusContainer

# Define the message bus.
SESSION_BUS = SessionMessageBus()

# Define namespaces.
CHAT_NAMESPACE = ("org", "example", "Chat")
ROOMS_NAMESPACE = (*CHAT_NAMESPACE, "Rooms")

# Define services and objects.
CHAT = DBusServiceIdentifier(namespace=CHAT_NAMESPACE, message_bus=SESSION_BUS)

ROOM = DBusInterfaceIdentifier(namespace=CHAT_NAMESPACE, basename="Room")

# Define containers.
ROOM_CONTAINER = DBusContainer(namespace=ROOMS_NAMESPACE,
                               message_bus=SESSION_BUS)