Beispiel #1
0
 def initialize_portal(self):
     from jeepney import DBusAddress, MessageType, Properties
     self.address = DBusAddress(
         '/org/freedesktop/portal/desktop',
         bus_name='org.freedesktop.portal.Desktop',
         interface='org.freedesktop.portal.Notification')
     p = Properties(self.address)
     msg = p.get('version')
     reply = self.connection.send_and_get_reply(msg)
     return bool(reply
                 and reply.header.message_type is MessageType.method_return
                 and reply.body[0][1] >= 1)
Beispiel #2
0
    def __init__(self):
        from jeepney import DBusAddress, Properties, new_method_call
        # Prefer desktop portal interface here since it can theoretically
        # work with network management solutions other than NetworkManager
        # and is controlled by the current desktop session
        #
        # There is no difference in terms of “features” provided between
        # the two APIs from our point of view.
        self.xdp_call = lambda: new_method_call(
            DBusAddress('/org/freedesktop/portal/desktop',
                        bus_name='org.freedesktop.portal.Desktop',
                        interface="org.freedesktop.portal.NetworkMonitor"),
            'GetConnectivity')
        self.nm_call = lambda: Properties(
            DBusAddress('/org/freedesktop/NetworkManager',
                        bus_name='org.freedesktop.NetworkManager',
                        interface="org.freedesktop.NetworkManager")).get(
                            'Connectivity')

        if self.xdp() is not None:
            self.get_connectivity = self.xdp
        elif self.nm() is not None:
            self.get_connectivity = self.nm
        else:
            self.get_connectivity = lambda: 4
Beispiel #3
0
def get_info_mpris2(name):
    """
    Get the current playing song from an mpris2 compliant player.
    """
    # qdbus org.mpris.MediaPlayer2.<name> /org/mpris/MediaPlayer2\
    # org.freedesktop.DBus.Properties.Get org.mpris.MediaPlayer2.Player Metadat
    bus_name = 'org.mpris.MediaPlayer2.' + name
    path = '/org/mpris/MediaPlayer2'
    interface = 'org.mpris.MediaPlayer2.Player'
    address = DBusAddress(path, bus_name=bus_name, interface=interface)
    msg = Properties(address).get('Metadata')
    connection = connect_and_authenticate()
    response = connection.send_and_get_reply(msg)
    metadata = dict(response[0][1])
    keys = ['album', 'title', 'artist', 'albumartist']

    info = {}
    metadata = {k: v for k, v in metadata.items() if 'xesam:' in k}
    for key, value in metadata.items():
        name = key.split(':')[1].lower()
        value = value[1]
        if name not in keys or name in info:
            continue
        if isinstance(value, list):
            value = value[0]
        info[name] = value

    if 'albumartist' in info:
        info['artist'] = info['albumartist']
        del info['albumartist']

    return Song(**info)
Beispiel #4
0
 def drive_for_device(self, device_node_path):
     from jeepney import Properties
     devname = self.device(device_node_path)
     a = self.address(f'block_devices/{devname}', self.BLOCK)
     msg = Properties(a).get('Drive')
     r = self.send(msg)
     return r.body[0][1]
Beispiel #5
0
 def prop(self, addr, name):
     return self.send(Properties(addr).get(name))
Beispiel #6
0
 def set_property(self, name: str, signature: str, value: Any) -> None:
     msg = Properties(self).set(name, signature, value)
     self.send_and_get_reply(msg)
Beispiel #7
0
 def get_property(self, name: str) -> Any:
     msg = Properties(self).get(name)
     (signature, value), = self.send_and_get_reply(msg)
     return value
Beispiel #8
0
 def get_device_node_path(self, devname):
     from jeepney import Properties
     p = Properties(self.address(f'block_devices/{devname}', self.BLOCK))
     r = self.send(p.get('Device'))
     return bytearray(r.body[0][1]).replace(b'\x00', b'').decode('utf-8')