Python dbus.ObjectPath() Examples

The following are 30 code examples of dbus.ObjectPath(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module dbus , or try the search function .
Example #1
Source File: networkmanayer.py    From my-weather-indicator with MIT License 6 votes vote down vote up
def unwrap(self, val):
        if isinstance(val, dbus.ByteArray):
            return "".join([str(x) for x in val])
        if isinstance(val, (dbus.Array, list, tuple)):
            return [self.unwrap(x) for x in val]
        if isinstance(val, (dbus.Dictionary, dict)):
            return dict([(self.unwrap(x), self.unwrap(y)) for x, y in val.items()])
        if isinstance(val, dbus.ObjectPath):
            if val.startswith('/org/freedesktop/NetworkManager/'):
                classname = val.split('/')[4]
                classname = {
                    'Settings': 'Connection',
                    'Devices': 'Device',
                }.get(classname, classname)
                return globals()[classname](val)
        if isinstance(val, (dbus.Signature, dbus.String)):
            return unicode(val)
        if isinstance(val, dbus.Boolean):
            return bool(val)
        if isinstance(val, (dbus.Int16, dbus.UInt16, dbus.Int32, dbus.UInt32, dbus.Int64, dbus.UInt64)):
            return int(val)
        if isinstance(val, dbus.Byte):
            return bytes([int(val)])
        return val 
Example #2
Source File: test_bt_bus.py    From bt-manager with GNU General Public License v3.0 6 votes vote down vote up
def test_sbc_caps_conversion(self, patched_system_bus):

        mock_system_bus = mock.MagicMock()
        patched_system_bus.return_value = mock_system_bus
        mock_system_bus.get_object.return_value = dbus.ObjectPath('/org/bluez')

        media = bt_manager.SBCAudioCodec(uuid='uuid', path='/endpoint/test')
        config = bt_manager.SBCCodecConfig(bt_manager.SBCChannelMode.ALL,
                                           bt_manager.SBCSamplingFrequency.ALL,
                                           bt_manager.SBCAllocationMethod.ALL,
                                           bt_manager.SBCSubbands.ALL,
                                           bt_manager.SBCBlocks.ALL,
                                           2,
                                           64)
        dbus_config = media._make_config(config)
        self.assertEqual(dbus_config, dbus.Array([dbus.Byte(0xFF),
                                                  dbus.Byte(0xFF),
                                                  dbus.Byte(2),
                                                  dbus.Byte(64)]))
        self.assertEqual(media._parse_config(dbus_config), config) 
Example #3
Source File: test_bt_bus.py    From bt-manager with GNU General Public License v3.0 6 votes vote down vote up
def test_agent_corner_cases(self, patched_system_bus):
        mock_system_bus = mock.MagicMock()
        patched_system_bus.return_value = mock_system_bus
        mock_system_bus.get_object.return_value = dbus.ObjectPath('/org/bluez')
        agent = bt_manager.BTAgent(default_pin_code=None,
                                   default_pass_key=None)

        obj = dbus.ObjectPath('/org/bluez/985/hci0/dev_00_11_67_D2_AB_EE')

        try:
            exception_raised = False
            agent.RequestPinCode(obj)
        except bt_manager.BTRejectedException:
            exception_raised = True
        self.assertTrue(exception_raised)

        try:
            exception_raised = False
            agent.RequestPasskey(obj)
        except bt_manager.BTRejectedException:
            exception_raised = True
        self.assertTrue(exception_raised) 
Example #4
Source File: test_bt_bus.py    From bt-manager with GNU General Public License v3.0 6 votes vote down vote up
def test_agent_with_defaults(self, patched_system_bus):
        mock_system_bus = mock.MagicMock()
        patched_system_bus.return_value = mock_system_bus
        mock_system_bus.get_object.return_value = dbus.ObjectPath('/org/bluez')
        agent = bt_manager.BTAgent()

        obj = dbus.ObjectPath('/org/bluez/985/hci0/dev_00_11_67_D2_AB_EE')
        uuid = dbus.String(u'00001108-0000-1000-8000-00805f9b34fb')
        pin_code = dbus.String('0000')
        pass_key = dbus.UInt32(0)
        mode = 'Mode'

        self.assertEqual(agent.Release(), None)
        self.assertEqual(agent.Authorize(obj, uuid), None)
        self.assertEqual(agent.RequestPinCode(obj), pin_code)
        self.assertEqual(agent.RequestPasskey(obj), pass_key)
        self.assertEqual(agent.DisplayPasskey(obj, pass_key), None)
        self.assertEqual(agent.RequestConfirmation(obj, pass_key), None)
        self.assertEqual(agent.ConfirmModeChange(mode), None)
        self.assertEqual(agent.Cancel(), None) 
Example #5
Source File: peripheral.py    From python-bluezero with MIT License 5 votes vote down vote up
def get_path(self):
        """Return the D-Bus object path."""
        return dbus.ObjectPath(self.path) 
Example #6
Source File: service.py    From cputemp with MIT License 5 votes vote down vote up
def get_path(self):
        return dbus.ObjectPath(self.path) 
Example #7
Source File: service.py    From cputemp with MIT License 5 votes vote down vote up
def get_path(self):
        return dbus.ObjectPath(self.path) 
Example #8
Source File: service.py    From cputemp with MIT License 5 votes vote down vote up
def get_path(self):
        return dbus.ObjectPath(self.path) 
Example #9
Source File: upower.py    From cpu-g with GNU General Public License v3.0 5 votes vote down vote up
def convert(dbus_obj):
    """Converts dbus_obj from dbus type to python type.
    :param dbus_obj: dbus object.
    :returns: dbus_obj in python type.
    """
    _isinstance = partial(isinstance, dbus_obj)
    ConvertType = namedtuple('ConvertType', 'pytype dbustypes')

    pyint = ConvertType(int, (dbus.Byte, dbus.Int16, dbus.Int32, dbus.Int64,
                              dbus.UInt16, dbus.UInt32, dbus.UInt64))
    pybool = ConvertType(bool, (dbus.Boolean, ))
    pyfloat = ConvertType(float, (dbus.Double, ))
    pylist = ConvertType(lambda _obj: list(map(convert, dbus_obj)),
                         (dbus.Array, ))
    pytuple = ConvertType(lambda _obj: tuple(map(convert, dbus_obj)),
                          (dbus.Struct, ))
    types_str = (dbus.ObjectPath, dbus.Signature, dbus.String)
    pystr = ConvertType(str, types_str)

    pydict = ConvertType(
        lambda _obj: dict(zip(map(convert, dbus_obj.keys()),
                              map(convert, dbus_obj.values())
                              )
                          ),
        (dbus.Dictionary, )
    )

    for conv in (pyint, pybool, pyfloat, pylist, pytuple, pystr, pydict):
        if any(map(_isinstance, conv.dbustypes)):
            return conv.pytype(dbus_obj)
        return dbus_obj 
Example #10
Source File: advertisement.py    From python-bluezero with MIT License 5 votes vote down vote up
def get_path(self):
        """Return the DBus object path"""
        return dbus.ObjectPath(self.path) 
Example #11
Source File: peripheral.py    From python-bluezero with MIT License 5 votes vote down vote up
def get_path(self):
        """Return the D-Bus object path."""
        return dbus.ObjectPath(self.path) 
Example #12
Source File: peripheral.py    From python-bluezero with MIT License 5 votes vote down vote up
def get_path(self):
        """Return the D-Bus object path."""
        return dbus.ObjectPath(self.path) 
Example #13
Source File: NetworkManager.py    From AstroBox with GNU Affero General Public License v3.0 5 votes vote down vote up
def base_to_python(val):
				if isinstance(val, dbus.ByteArray):
						return "".join([str(x) for x in val])
				if isinstance(val, (dbus.Array, list, tuple)):
						return [fixups.base_to_python(x) for x in val]
				if isinstance(val, (dbus.Dictionary, dict)):
						return dict([(fixups.base_to_python(x), fixups.base_to_python(y)) for x,y in val.items()])
				if isinstance(val, dbus.ObjectPath):
						for obj in (NetworkManager, Settings, AgentManager):
								if val == obj.object_path:
										return obj
						if val.startswith('/org/freedesktop/NetworkManager/'):
								classname = val.split('/')[4]
								classname = {
									 'Settings': 'Connection',
									 'Devices': 'Device',
								}.get(classname, classname)
								return globals()[classname](val)
						if val == '/':
								return None
				if isinstance(val, (dbus.Signature, dbus.String)):
						return six.text_type(val)
				if isinstance(val, dbus.Boolean):
						return bool(val)
				if isinstance(val, (dbus.Int16, dbus.UInt16, dbus.Int32, dbus.UInt32, dbus.Int64, dbus.UInt64)):
						return int(val)
				if isinstance(val, dbus.Byte):
						return six.int2byte(int(val))
				return val 
Example #14
Source File: peripheral.py    From python-bluezero with MIT License 5 votes vote down vote up
def get_path(self):
        """Return the D-Bus object path."""
        return dbus.ObjectPath(self.path) 
Example #15
Source File: localGATT.py    From python-bluezero with MIT License 5 votes vote down vote up
def get_path(self):
        """Return the DBus object path"""
        return dbus.ObjectPath(self.path) 
Example #16
Source File: localGATT.py    From python-bluezero with MIT License 5 votes vote down vote up
def get_path(self):
        """Return the DBus object path"""
        return dbus.ObjectPath(self.path) 
Example #17
Source File: localGATT.py    From python-bluezero with MIT License 5 votes vote down vote up
def get_path(self):
        """Return the DBus object path"""
        return dbus.ObjectPath(self.path) 
Example #18
Source File: localGATT.py    From python-bluezero with MIT License 5 votes vote down vote up
def get_path(self):
        """Return the DBus object path"""
        return dbus.ObjectPath(self.path) 
Example #19
Source File: i3-appmenu-service.py    From i3-hud-menu with MIT License 5 votes vote down vote up
def GetMenuForWindow(self, windowId):
    if windowId in self.window_dict:
      sender, menuObjectPath = self.window_dict[windowId]
      return [dbus.String(sender), dbus.ObjectPath(menuObjectPath)] 
Example #20
Source File: ipaddress.py    From my-weather-indicator with MIT License 5 votes vote down vote up
def convert(dbus_obj):
    """Converts dbus_obj from dbus type to python type.
    :param dbus_obj: dbus object.
    :returns: dbus_obj in python type.
    """
    _isinstance = partial(isinstance, dbus_obj)
    ConvertType = namedtuple('ConvertType', 'pytype dbustypes')

    pyint = ConvertType(int, (dbus.Byte, dbus.Int16, dbus.Int32, dbus.Int64,
                              dbus.UInt16, dbus.UInt32, dbus.UInt64))
    pybool = ConvertType(bool, (dbus.Boolean, ))
    pyfloat = ConvertType(float, (dbus.Double, ))
    pylist = ConvertType(lambda _obj: list(map(convert, dbus_obj)),
                         (dbus.Array, ))
    pytuple = ConvertType(lambda _obj: tuple(map(convert, dbus_obj)),
                          (dbus.Struct, ))
    types_str = (dbus.ObjectPath, dbus.Signature, dbus.String)
    pystr = ConvertType(str, types_str)

    pydict = ConvertType(
        lambda _obj: dict(list(zip(list(map(convert, dbus_obj.keys())),
                                   list(map(convert, dbus_obj.values()))
                                   ))
                          ),
        (dbus.Dictionary, )
    )

    for conv in (pyint, pybool, pyfloat, pylist, pytuple, pystr, pydict):
        if any(map(_isinstance, conv.dbustypes)):
            return conv.pytype(dbus_obj)
    else:
        return dbus_obj 
Example #21
Source File: other_nm.py    From python-eduvpn-client with GNU General Public License v3.0 5 votes vote down vote up
def base_to_python(val):
        if isinstance(val, dbus.ByteArray):
            return "".join([str(x) for x in val])
        if isinstance(val, (dbus.Array, list, tuple)):
            return [fixups.base_to_python(x) for x in val]
        if isinstance(val, (dbus.Dictionary, dict)):
            return dict([(fixups.base_to_python(x), fixups.base_to_python(y)) for x, y in val.items()])
        if isinstance(val, dbus.ObjectPath):
            for obj in (NetworkManager, Settings, AgentManager):
                if val == obj.object_path:
                    return obj
            if val.startswith('/org/freedesktop/NetworkManager/'):
                classname = val.split('/')[4]
                classname = {
                    'Settings': 'Connection',
                    'Devices': 'Device',
                }.get(classname, classname)
                try:
                    return globals()[classname](val)
                except ObjectVanished:
                    return None
            if val == '/':
                return None
        if isinstance(val, (dbus.Signature, dbus.String)):
            return six.text_type(val)
        if isinstance(val, dbus.Boolean):
            return bool(val)
        if isinstance(val, (dbus.Int16, dbus.UInt16, dbus.Int32, dbus.UInt32, dbus.Int64, dbus.UInt64)):
            return int(val)
        if isinstance(val, dbus.Byte):
            return six.int2byte(int(val))
        return val 
Example #22
Source File: test_bt_bus.py    From bt-manager with GNU General Public License v3.0 5 votes vote down vote up
def setUp(self):
        patcher = mock.patch('dbus.Interface', MockDBusInterface)
        patcher.start()
        self.addCleanup(patcher.stop)
        patcher = mock.patch('dbus.SystemBus')
        patched_system_bus = patcher.start()
        self.addCleanup(patcher.stop)
        mock_system_bus = mock.MagicMock()
        patched_system_bus.return_value = mock_system_bus
        mock_system_bus.get_object.return_value = dbus.ObjectPath('/org/bluez')
        self.mock_system_bus = mock_system_bus 
Example #23
Source File: CameraStream.py    From rpisurv with GNU General Public License v2.0 5 votes vote down vote up
def hide_stream(self):
        logger.debug('CameraStream: Hide stream instruction ' + self.name + ' received from dbus interface')
        if platform.system() == "Linux":
            if self.dbusconnection is not None:
                self.dbusconnection.player_interface.SetAlpha(ObjectPath('/not/used'), Int64(0))
            else:
                logger.error('CameraStream: ' + self.name + ' has no dbus connection, probably because omxplayer crashed because it can not connect to this stream. As a result we could not hide this stream at this time.') 
Example #24
Source File: CameraStream.py    From rpisurv with GNU General Public License v2.0 5 votes vote down vote up
def unhide_stream(self):
        logger.debug('CameraStream: Unhide stream instruction ' + self.name + ' received from dbus interface')
        if platform.system() == "Linux":
            if self.dbusconnection is not None:
                self.dbusconnection.player_interface.SetAlpha(ObjectPath('/not/used'), Int64(255))
            else:
                logger.error('CameraStream: ' + self.name + ' has no dbus connection, probably because omxplayer crashed because it can not connect to this stream. As a result we could not unhide this stream at this time.') 
Example #25
Source File: player.py    From python-omxplayer-wrapper with GNU Lesser General Public License v3.0 5 votes vote down vote up
def _from_dbus_type(fn):
    def from_dbus_type(dbusVal):
        def from_dbus_dict(dbusDict):
            d = dict()
            for dbusKey, dbusVal in dbusDict.items():
                d[from_dbus_type(dbusKey)] = from_dbus_type(dbusVal)
            return d

        typeUnwrapper = {
            dbus.types.Dictionary: from_dbus_dict,
            dbus.types.Array: lambda x: list(map(from_dbus_type, x)),
            dbus.types.Double: float,
            dbus.types.Boolean: bool,
            dbus.types.Byte: int,
            dbus.types.Int16: int,
            dbus.types.Int32: int,
            dbus.types.Int64: int,
            dbus.types.UInt32: int,
            dbus.types.UInt64: int,
            dbus.types.ByteArray: str,
            dbus.types.ObjectPath: str,
            dbus.types.Signature: str,
            dbus.types.String: str
        }
        try:
            return typeUnwrapper[type(dbusVal)](dbusVal)
        except KeyError:
            return dbusVal

    def wrapped(fn, self, *args, **kwargs):
            return from_dbus_type(fn(self, *args, **kwargs))

    return decorator(wrapped, fn)


# CLASSES 
Example #26
Source File: player.py    From python-omxplayer-wrapper with GNU Lesser General Public License v3.0 5 votes vote down vote up
def set_position(self, position):
        """
        Set the video to playback position to `position` seconds from the start of the video

        Args:
            position (float): The position in seconds.
        """
        self._player_interface.SetPosition(ObjectPath("/not/used"), Int64(position * 1000.0 * 1000))
        self.positionEvent(self, position) 
Example #27
Source File: player.py    From python-omxplayer-wrapper with GNU Lesser General Public License v3.0 5 votes vote down vote up
def set_alpha(self, alpha):
        """
        Set the transparency of the video overlay

        Args:
            alpha (float): The transparency (0..255)
        """
        self._player_interface.SetAlpha(ObjectPath('/not/used'), Int64(alpha)) 
Example #28
Source File: player.py    From python-omxplayer-wrapper with GNU Lesser General Public License v3.0 5 votes vote down vote up
def set_aspect_mode(self, mode):
        """
        Set the aspect mode of the video

        Args:
            mode (str): One of ("letterbox" | "fill" | "stretch")
        """
        self._player_interface.SetAspectMode(ObjectPath('/not/used'), String(mode)) 
Example #29
Source File: player.py    From python-omxplayer-wrapper with GNU Lesser General Public License v3.0 5 votes vote down vote up
def set_video_pos(self, x1, y1, x2, y2):
        """
        Set the video position on the screen

        Args:
            x1 (int): Top left x coordinate (px)
            y1 (int): Top left y coordinate (px)
            x2 (int): Bottom right x coordinate (px)
            y2 (int): Bottom right y coordinate (px)
        """
        position = "%s %s %s %s" % (str(x1),str(y1),str(x2),str(y2))
        self._player_interface.VideoPos(ObjectPath('/not/used'), String(position)) 
Example #30
Source File: player.py    From python-omxplayer-wrapper with GNU Lesser General Public License v3.0 5 votes vote down vote up
def set_video_crop(self, x1, y1, x2, y2):
        """
        Args:
            x1 (int): Top left x coordinate (px)
            y1 (int): Top left y coordinate (px)
            x2 (int): Bottom right x coordinate (px)
            y2 (int): Bottom right y coordinate (px)
        """
        crop = "%s %s %s %s" % (str(x1),str(y1),str(x2),str(y2))
        self._player_interface.SetVideoCropPos(ObjectPath('/not/used'), String(crop))