Python dbus 模块,Interface() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用dbus.Interface()

项目:PyDbusNetworkManager    作者:stoic1979    | 项目源码 | 文件源码
def enable_networking(self, val):
        """
        function enables/disables networking depending upon the 'val' argument
        if val is True, networking is enabled
        if val is False, networking is disabled
        """
        try:
            bus = dbus.SystemBus()
            wifi = bus.get_object('org.freedesktop.NetworkManager', '/org/freedesktop/NetworkManager')

            iface = dbus.Interface(wifi, dbus_interface='org.freedesktop.NetworkManager')

            # enabling/disabling networking
            m = iface.get_dbus_method("Enable", dbus_interface=None)
            m(val)
        except:
            pass
项目:PyDbusNetworkManager    作者:stoic1979    | 项目源码 | 文件源码
def get_active_connection_info(self, ac_path):
        bus = dbus.SystemBus()
        wifi = bus.get_object('org.freedesktop.NetworkManager', ac_path)

        iface = dbus.Interface(wifi, dbus_interface='org.freedesktop.DBus.Properties')

        # creating proxy 'Get' method
        m = iface.get_dbus_method("Get", dbus_interface=None)

        # getting Id of active connection
        Id = m("org.freedesktop.NetworkManager.Connection.Active", "Id")

        # getting Type of active connection
        Type = m("org.freedesktop.NetworkManager.Connection.Active", "Type")

        # getting Uuid of active connection
        Uuid = m("org.freedesktop.NetworkManager.Connection.Active", "Uuid")

        # getting State of active connection
        State = m("org.freedesktop.NetworkManager.Connection.Active", "State")

        # NOTE:
        # this function only returns properties like Id, Type, Uuid, State of an active connection
        # However, other properties like Dhcp4Config, Dhcp6Config, Ip4Config, Ip6Config etc. can also be obtained
        return (str(Id), str(Type), str(Uuid), int(State))
项目:PyDbusNetworkManager    作者:stoic1979    | 项目源码 | 文件源码
def get_access_point_brief_info(self, ap_path):

        bus = dbus.SystemBus()
        obj = bus.get_object('org.freedesktop.NetworkManager', ap_path)

        iface = dbus.Interface(obj, dbus_interface='org.freedesktop.DBus.Properties')

        m = iface.get_dbus_method("Get", dbus_interface=None)

        # getting Ssid
        dbusArray = m("org.freedesktop.NetworkManager.AccessPoint", "Ssid")
        Ssid = ''.join([chr(character) for character in dbusArray])

        # getting Strength
        Strength = m("org.freedesktop.NetworkManager.AccessPoint", "Strength")

        # getting HwAddress
        HwAddress = m("org.freedesktop.NetworkManager.AccessPoint", "HwAddress")

        # getting Mode
        Mode = m("org.freedesktop.NetworkManager.AccessPoint", "Mode")

        return (Ssid, int(Strength), str(HwAddress), int(Mode))
项目:my-weather-indicator    作者:atareao    | 项目源码 | 文件源码
def __init__(self, object_path=None):
        if isinstance(object_path, NMDbusInterface):
            object_path = object_path.object_path
        self.object_path = self.object_path or object_path
        self.proxy = self.bus.get_object(self.dbus_service, self.object_path)
        self.interface = dbus.Interface(self.proxy, self.interface_name)

        properties = []
        try:
            properties = self.proxy.GetAll(self.interface_name,
                                           dbus_interface='org.freedesktop.DBus.Properties')
        except dbus.exceptions.DBusException as e:
            if e.get_dbus_name() != 'org.freedesktop.DBus.Error.UnknownMethod':
                raise
        for p in properties:
            p = str(p)
            if not hasattr(self.__class__, p):
                setattr(self.__class__, p, self._make_property(p))
项目:OpenXCAccessory    作者:openxc    | 项目源码 | 文件源码
def find_device_in_objects(objects, device_address, adapter_pattern=None):
    bus = dbus.SystemBus()
    path_prefix = ""
    if adapter_pattern:
        adapter = find_adapter_in_objects(objects, adapter_pattern)
        path_prefix = adapter.object_path
    for path, ifaces in objects.iteritems():
        device = ifaces.get(DEVICE_INTERFACE)
        if device is None:
            continue
        if (device["Address"] == device_address and
                        path.startswith(path_prefix)):
            obj = bus.get_object(SERVICE_NAME, path)
            return dbus.Interface(obj, DEVICE_INTERFACE)

    raise Exception("Bluetooth device not found")
项目:python-gatt-server    作者:Jumperr-labs    | 项目源码 | 文件源码
def advertising_main(mainloop, bus, adapter_name):
    adapter = adapters.find_adapter(bus, LE_ADVERTISING_MANAGER_IFACE, adapter_name)
    print('adapter: %s' % (adapter,))
    if not adapter:
        raise Exception('LEAdvertisingManager1 interface not found')

    adapter_props = dbus.Interface(bus.get_object(BLUEZ_SERVICE_NAME, adapter),
                                   "org.freedesktop.DBus.Properties")

    adapter_props.Set("org.bluez.Adapter1", "Powered", dbus.Boolean(1))

    ad_manager = dbus.Interface(bus.get_object(BLUEZ_SERVICE_NAME, adapter),
                                LE_ADVERTISING_MANAGER_IFACE)

    test_advertisement = TestAdvertisement(bus, 0)

    ad_manager.RegisterAdvertisement(test_advertisement.get_path(), {},
                                     reply_handler=register_ad_cb,
                                     error_handler=functools.partial(register_ad_error_cb, mainloop))
项目:python-gatt-server    作者:Jumperr-labs    | 项目源码 | 文件源码
def gatt_server_main(mainloop, bus, adapter_name):
    adapter = adapters.find_adapter(bus, GATT_MANAGER_IFACE, adapter_name)
    if not adapter:
        raise Exception('GattManager1 interface not found')

    service_manager = dbus.Interface(
            bus.get_object(BLUEZ_SERVICE_NAME, adapter),
            GATT_MANAGER_IFACE)

    app = Application(bus)

    print('Registering GATT application...')

    service_manager.RegisterApplication(app.get_path(), {},
                                    reply_handler=register_app_cb,
                                    error_handler=functools.partial(register_app_error_cb, mainloop))
项目:gatt-python    作者:getsenic    | 项目源码 | 文件源码
def __init__(self, adapter_name):
        self.listener = None
        self.adapter_name = adapter_name

        self._bus = dbus.SystemBus()
        try:
            adapter_object = self._bus.get_object('org.bluez', '/org/bluez/' + adapter_name)
        except dbus.exceptions.DBusException as e:
            raise _error_from_dbus_error(e)
        object_manager_object = self._bus.get_object("org.bluez", "/")
        self._adapter = dbus.Interface(adapter_object, 'org.bluez.Adapter1')
        self._adapter_properties = dbus.Interface(self._adapter, 'org.freedesktop.DBus.Properties')
        self._object_manager = dbus.Interface(object_manager_object, "org.freedesktop.DBus.ObjectManager")
        self._device_path_regex = re.compile('^/org/bluez/' + adapter_name + '/dev((_[A-Z0-9]{2}){6})$')
        self._devices = {}
        self._discovered_devices = {}
        self._interface_added_signal = None
        self._properties_changed_signal = None
        self._main_loop = None

        self.update_devices()
项目:backlight-indicator    作者:atareao    | 项目源码 | 文件源码
def __init__(self):
        self.bm = BacklightManagerForGNOME()
        self.desktop = os.getenv('DESKTOP_SESSION', 'gnome')
        properties = DBUS_PROPS[self.desktop]
        self.callback = None
        self.bus = dbus.SessionBus()
        bus = dbus.SessionBus()
        proxy = bus.get_object(properties['service'], properties['path'])
        self.properties_manager = dbus.Interface(
            proxy, 'org.freedesktop.DBus.Properties')
        self.dbus_interface = dbus.Interface(
            proxy, dbus_interface=properties['interface'])
        self.get_value = self.dbus_interface.get_dbus_method(
            properties['method-get'])
        self.set_value = self.dbus_interface.get_dbus_method(
            properties['method-set'])
        self.callback = None
项目:dotfiles    作者:nfischer    | 项目源码 | 文件源码
def notify(summary, body='', app_name='', app_icon='',
           timeout=3000, actions=[], hints=[], replaces_id=0):
    """Send a system notification"""
    _bus_name = 'org.freedesktop.Notifications'
    _object_path = '/org/freedesktop/Notifications'
    _interface_name = _bus_name

    session_bus = dbus.SessionBus()
    obj = session_bus.get_object(_bus_name, _object_path)
    interface = dbus.Interface(obj, _interface_name)
    interface.Notify(app_name, replaces_id, app_icon,
                     summary, body, actions, hints, timeout)


## Main ##

# Call battery_check shell script to get info
项目:dotfiles    作者:nfischer    | 项目源码 | 文件源码
def notify(summary, body='', app_name='', app_icon='',
           timeout=3000, actions=[], hints=[], replaces_id=0):
    """Send a system notification"""
    _bus_name = 'org.freedesktop.Notifications'
    _object_path = '/org/freedesktop/Notifications'
    _interface_name = _bus_name

    session_bus = dbus.SessionBus()
    obj = session_bus.get_object(_bus_name, _object_path)
    interface = dbus.Interface(obj, _interface_name)
    interface.Notify(app_name, replaces_id, app_icon,
                     summary, body, actions, hints, timeout)


## Main ##

# Call battery_check shell script to get info
项目:dotfiles    作者:nfischer    | 项目源码 | 文件源码
def notify(summary, body='', app_name='', app_icon='',
           timeout=5000, actions=[], hints=[], replaces_id=0):
    """Send a system notification"""
    _bus_name = 'org.freedesktop.Notifications'
    _object_path = '/org/freedesktop/Notifications'
    _interface_name = _bus_name

    session_bus = dbus.SessionBus()
    obj = session_bus.get_object(_bus_name, _object_path)
    interface = dbus.Interface(obj, _interface_name)
    interface.Notify(app_name, replaces_id, app_icon,
                     summary, body, actions, hints, timeout)


## Main ##

# Call battery_check shell script to get info

# TODO(nate): parse text more cleanly
项目:pywificontrol    作者:emlid    | 项目源码 | 文件源码
def _initialize(self):
        systemd_obj = self.bus.get_object(SYSTEMD_DBUS_SERVICE,
                                          SYSTEMD_DBUS_OPATH)
        self.sysd_manager = dbus.Interface(systemd_obj,
                                           dbus_interface=SYSTEMD_MANAGER_DBUS_IFACE)
        self.sysd_manager.Subscribe()

        self.bus.add_signal_receiver(self._wpa_props_changed,
                                     dbus_interface=WPAS_INTERFACE_DBUS_IFACE,
                                     signal_name="PropertiesChanged",
                                     path=WPAS_INTERFACE_DBUS_OPATH)

        self.bus.add_signal_receiver(self._host_props_changed,
                                     dbus_interface=DBUS_PROPERTIES_IFACE,
                                     signal_name="PropertiesChanged",
                                     path=HOSTAPD_DBUS_UNIT_OPATH)

        self._register_local_callbacks()
        self._set_initial_state()
项目:ubuntu-cleaner    作者:gerardpuig    | 项目源码 | 文件源码
def _check_permission(self, sender, action):
        '''
        Verifies if the specified action is permitted, and raises
        an AccessDeniedException if not.

        The caller should use ObtainAuthorization() to get permission.
        '''

        try:
            if sender:
                kit = dbus.SystemBus().get_object('org.freedesktop.PolicyKit1', '/org/freedesktop/PolicyKit1/Authority')
                kit = dbus.Interface(kit, 'org.freedesktop.PolicyKit1.Authority')

                (granted, _, details) = kit.CheckAuthorization(
                                ('system-bus-name', {'name': sender}),
                                action, {}, dbus.UInt32(1), '', timeout=600)

                if not granted:
                    raise AccessDeniedException('Session not authorized by PolicyKit')

        except AccessDeniedException:
            raise

        except dbus.DBusException, ex:
            raise AccessDeniedException(ex.message)
项目:dell-recovery    作者:dell    | 项目源码 | 文件源码
def backend(self):
        '''Return D-BUS backend client interface.

        This gets initialized lazily.
        '''
        if self._dbus_iface is None:
            try:
                bus = dbus.SystemBus()
                self._dbus_iface = dbus.Interface(bus.get_object(DBUS_BUS_NAME,
                                                  '/RecoveryMedia'),
                                                  DBUS_INTERFACE_NAME)
            except dbus.DBusException as msg:
                self.dbus_exception_handler(msg)
                sys.exit(1)
            except Exception as msg:
                self.show_alert(Gtk.MessageType.ERROR, "Exception", str(msg),
                           transient_for=self.tool_widgets.get_object('tool_selector'))

        return self._dbus_iface
项目:python-bluezero    作者:ukBaz    | 项目源码 | 文件源码
def props_changed_cb(self, iface, changed_props, invalidated_props):
        """
        Callback indicating that properties have changed.

        :param iface: Interface associated with the callback.
        :param changed_props: Properties changed that triggered the callback.
        :param invalidated_props: Unused.
        """
        if iface != constants.GATT_CHRC_IFACE:
            return

        if not len(changed_props):
            return

        value = changed_props.get('Value', None)
        if not value:
            return

        logger.debug('Properties changed: ', value)
项目:python-bluezero    作者:ukBaz    | 项目源码 | 文件源码
def __init__(self, adapter_addr, device_addr, profile_uuid):
        """
        Remote GATT Profile Initialisation.

        :param profile_path: dbus path to the profile.
        """
        self.profile_path = dbus_tools.get_profile_path(adapter_addr,
                                                        device_addr,
                                                        profile_uuid)
        self.bus = dbus.SystemBus()
        self.profile_object = self.bus.get_object(
            constants.BLUEZ_SERVICE_NAME,
            self.profile_path)
        self.profile_methods = dbus.Interface(
            self.profile_object,
            constants.GATT_PROFILE_IFACE)
        self.profile_props = dbus.Interface(self.profile_object,
                                            dbus.PROPERTIES_IFACE)
项目:python-bluezero    作者:ukBaz    | 项目源码 | 文件源码
def __init__(self, adapter_addr):
        """
        GATT Manager Initialisation.

        :param manager_path: dbus path to the GATT Manager.
        """
        self.manager_path = dbus_tools.get_dbus_path(adapter_addr)
        self.bus = dbus.SystemBus()
        self.manager_obj = self.bus.get_object(
            constants.BLUEZ_SERVICE_NAME,
            self.manager_path)
        self.manager_methods = dbus.Interface(
            self.manager_obj,
            constants.GATT_MANAGER_IFACE)
        self.manager_props = dbus.Interface(self.manager_obj,
                                            dbus.PROPERTIES_IFACE)
项目:python-bluezero    作者:ukBaz    | 项目源码 | 文件源码
def list_adapters():
    """Return list of adapters address available on system."""
    paths = []
    addresses = []
    bus = dbus.SystemBus()
    manager = dbus.Interface(
        bus.get_object(constants.BLUEZ_SERVICE_NAME, '/'),
        constants.DBUS_OM_IFACE)
    manager_obj = manager.GetManagedObjects()
    for path, ifaces in manager_obj.items():
        if constants.ADAPTER_INTERFACE in ifaces:
            paths.append(path)
            addresses.append(
                manager_obj[path][constants.ADAPTER_INTERFACE]['Address'])
    if len(paths) < 1:
        raise AdapterError('No Bluetooth adapter found')
    else:
        return addresses
项目:eos-data-distribution    作者:endlessm    | 项目源码 | 文件源码
def add_service_type(self, type):
        interface, protocol, domain = (
            self.interface, self.protocol, self.domain)
        # Are we already browsing this domain for this type?
        if self.already_browsing(type):
            return

        logger.info("Browsing for services of type '%s' in domain '%s' on %s.%i ..." %
                    (type, domain, self.siocgifname(interface), protocol))

        browser = self.server.ServiceBrowserNew(
            interface, protocol, type, domain, dbus.UInt32(0))
        bus = dbus.Interface(self.system_bus.get_object(
            avahi.DBUS_NAME, browser), avahi.DBUS_INTERFACE_SERVICE_BROWSER)
        bus.connect_to_signal('ItemNew', self.service_add)
        bus.connect_to_signal('ItemRemove', self.service_remove)

        self.service_browsers[(interface, protocol, type, domain)] = bus
项目:eos-data-distribution    作者:endlessm    | 项目源码 | 文件源码
def _start(self):
        try:
            self.server = dbus.Interface(self.system_bus.get_object(
                avahi.DBUS_NAME, avahi.DBUS_PATH_SERVER), avahi.DBUS_INTERFACE_SERVER)
        except:
            logger.info("Check that the Avahi daemon is running!")
            return

        try:
            self.use_host_names = self.server.IsNSSSupportAvailable()
        except:
            self.use_host_names = False

        self.domain = self.server.GetDomainName()
        logger.info("Starting discovery")

        for service in self.services:
            self.add_service_type(service)
项目:bluetool    作者:emlid    | 项目源码 | 文件源码
def pair(self, address):
        try:
            device = bluezutils.find_device(address)
        except (bluezutils.BluezUtilError,
                dbus.exceptions.DBusException) as error:
            print_error(str(error) + "\n")
            return False

        try:
            props = dbus.Interface(
                self._bus.get_object("org.bluez", device.object_path),
                "org.freedesktop.DBus.Properties")

            if not props.Get("org.bluez.Device1", "Paired"):
                device.Pair()
        except dbus.exceptions.DBusException as error:
            print_error(str(error) + "\n")
            return False

        return True
项目:bluetool    作者:emlid    | 项目源码 | 文件源码
def disconnect(self, address):
        try:
            device = bluezutils.find_device(address)
        except (bluezutils.BluezUtilError,
                dbus.exceptions.DBusException) as error:
            print_error(str(error) + "\n")
            return False

        try:
            props = dbus.Interface(
                self._bus.get_object("org.bluez", device.object_path),
                "org.freedesktop.DBus.Properties")

            if props.Get("org.bluez.Device1", "Connected"):
                device.Disconnect()
        except dbus.exceptions.DBusException as error:
            print_error(str(error) + "\n")
            return False

        return True
项目:bluetool    作者:emlid    | 项目源码 | 文件源码
def trust(self, address):
        try:
            device = bluezutils.find_device(address)
        except (bluezutils.BluezUtilError,
                dbus.exceptions.DBusException) as error:
            print_error(str(error) + "\n")
            return False

        try:
            props = dbus.Interface(
                self._bus.get_object("org.bluez", device.object_path),
                "org.freedesktop.DBus.Properties")

            if not props.Get("org.bluez.Device1", "Trusted"):
                props.Set("org.bluez.Device1", "Trusted", dbus.Boolean(1))
        except dbus.exceptions.DBusException as error:
            print_error(str(error) + "\n")
            return False

        return True
项目:bluetool    作者:emlid    | 项目源码 | 文件源码
def set_adapter_property(self, prop, value):
        try:
            adapter = bluezutils.find_adapter()
        except (bluezutils.BluezUtilError,
                dbus.exceptions.DBusException) as error:
            print_error(str(error) + "\n")
            return False

        try:
            props = dbus.Interface(
                self._bus.get_object("org.bluez", adapter.object_path),
                "org.freedesktop.DBus.Properties")

            if props.Get("org.bluez.Adapter1", prop) != value:
                props.Set("org.bluez.Adapter1", prop, value)
        except dbus.exceptions.DBusException as error:
            print_error(str(error) + "\n")
            return False

        return True
项目:bluetool    作者:emlid    | 项目源码 | 文件源码
def get_adapter_property(self, prop):
        try:
            adapter = bluezutils.find_adapter()
        except (bluezutils.BluezUtilError,
                dbus.exceptions.DBusException) as error:
            print_error(str(error) + "\n")
            return None

        try:
            props = dbus.Interface(
                self._bus.get_object("org.bluez", adapter.object_path),
                "org.freedesktop.DBus.Properties")

            return props.Get("org.bluez.Adapter1", prop)
        except dbus.exceptions.DBusException as error:
            print_error(str(error) + "\n")
            return None
项目:bluetool    作者:emlid    | 项目源码 | 文件源码
def set_device_property(self, address, prop, value):
        try:
            device = bluezutils.find_device(address)
        except (bluezutils.BluezUtilError,
                dbus.exceptions.DBusException) as error:
            print_error(str(error) + "\n")
            return False

        try:
            props = dbus.Interface(
                self._bus.get_object("org.bluez", device.object_path),
                "org.freedesktop.DBus.Properties")

            if props.Get("org.bluez.Device1", prop) != value:
                props.Set("org.bluez.Device1", prop, value)
        except dbus.exceptions.DBusException as error:
            print_error(str(error) + "\n")
            return False

        return True
项目:bluetool    作者:emlid    | 项目源码 | 文件源码
def find_device_in_objects(objects, device_address, adapter_pattern=None):
    bus = dbus.SystemBus()
    path_prefix = ""

    if adapter_pattern:
        adapter = find_adapter_in_objects(objects, adapter_pattern)
        path_prefix = adapter.object_path

    for path, ifaces in objects.items():
        device = ifaces.get(DEVICE_INTERFACE)

        if device is None:
            continue

        if (device["Address"] == device_address and path.startswith(
                path_prefix)):
            obj = bus.get_object(SERVICE_NAME, path)
            return dbus.Interface(obj, DEVICE_INTERFACE)

    raise BluezUtilError("Bluetooth device not found")
项目:gnome-hud    作者:hardpixel    | 项目源码 | 文件源码
def activate_menu_item(self, selection):
        if not selection:
            return

        action = self.menu_actions.get(selection, 'sys.quit')

        if 'sys.' in action:
            self.window.close()

        elif 'app.' in action:
            app_object = self.session.get_object(self.window.bus_name, self.window.app_path)
            app_iface = dbus.Interface(app_object, dbus_interface='org.gtk.Actions')

            app_iface.Activate(action.replace('app.', ''), [], dict())

        elif 'win.' in action:
            win_object = self.session.get_object(self.window.bus_name, self.window.win_path)
            win_iface = dbus.Interface(win_object, dbus_interface='org.gtk.Actions')

            win_iface.Activate(action.replace('win.', ''), [], dict())
项目:crisscross    作者:bhaveshAn    | 项目源码 | 文件源码
def _notify(self, **kwargs):
        summary = kwargs.get('title', "title")
        body = kwargs.get('message', "body")
        app_name = kwargs.get('app_name', '')
        app_icon = kwargs.get('app_icon', '')
        timeout = kwargs.get('timeout', 10)
        actions = kwargs.get('actions', [])
        hints = kwargs.get('hints', [])
        replaces_id = kwargs.get('replaces_id', 0)

        _bus_name = 'org.freedesktop.Notifications'
        _object_path = '/org/freedesktop/Notifications'
        _interface_name = _bus_name

        import dbus
        session_bus = dbus.SessionBus()
        obj = session_bus.get_object(_bus_name, _object_path)
        interface = dbus.Interface(obj, _interface_name)
        interface.Notify(app_name, replaces_id, app_icon,
            summary, body, actions, hints, timeout * 1000)
项目:BlueDot    作者:martinohanlon    | 项目源码 | 文件源码
def get_paired_devices(device_name):
    paired_devices = []

    bus = dbus.SystemBus()
    adapter_path = find_adapter(device_name).object_path
    om = dbus.Interface(bus.get_object(SERVICE_NAME, "/"), "org.freedesktop.DBus.ObjectManager")
    objects = om.GetManagedObjects()

    for path, interfaces in objects.items():
        if DEVICE_INTERFACE not in interfaces:
            continue
        properties = interfaces[DEVICE_INTERFACE]
        if properties["Adapter"] != adapter_path:
            continue

        paired_devices.append((str(properties["Address"]), str(properties["Alias"])))

    return paired_devices
项目:BMW-RPi-iBUS    作者:KLUSEK    | 项目源码 | 文件源码
def player_control(self, action):
        iface = dbus.Interface(self.bus.get_object(bluezutils.SERVICE_NAME, self._player_object_path), bluezutils.MEDIAPLAYER_INTERFACE)

        try:
            if action == "play":
                iface.Play()
            elif action == "pause":
                iface.Pause()
            elif action == "stop":
                iface.Stop()
            elif action == "prev":
                iface.Previous()
            elif action == "next":
                iface.Next()
            elif action == "forward":
                iface.FastForward()
            elif action == "rewind":
                iface.Rewind()
            else:
                return False
        except Exception as ex:
            print("Player communicate error: '{0}'".format(ex.message))
            return False
项目:BMW-RPi-iBUS    作者:KLUSEK    | 项目源码 | 文件源码
def show_adapter_info():
    bus = dbus.SystemBus()
    om = dbus.Interface(bus.get_object(SERVICE_NAME, "/"), "org.freedesktop.DBus.ObjectManager")
    objects = om.GetManagedObjects()
    for path, interfaces in objects.iteritems():
        if ADAPTER_INTERFACE not in interfaces:
            continue

        print(" [ %s ]" % (path))
        props = interfaces[ADAPTER_INTERFACE]

        for (key, value) in props.items():
            if (key == "Class"):
                print("    %s = 0x%06x" % (key, value))
            elif (key == "UUIDs"):
                continue                
            else:
                print("    %s = %s" % (key, value))
        print()
项目:BMW-RPi-iBUS    作者:KLUSEK    | 项目源码 | 文件源码
def find_device_in_objects(objects, device_address, adapter_pattern=None):
    bus = dbus.SystemBus()
    path_prefix = ""
    if adapter_pattern:
        adapter = find_adapter_in_objects(objects, adapter_pattern)
        path_prefix = adapter.object_path
    for path, ifaces in objects.iteritems():
        device = ifaces.get(DEVICE_INTERFACE)
        if device is None:
            continue
        if (device["Address"] == device_address and
                        path.startswith(path_prefix)):
            obj = bus.get_object(SERVICE_NAME, path)
            return dbus.Interface(obj, DEVICE_INTERFACE)

    raise Exception("Bluetooth device not found")
项目:SkiffOS    作者:paralin    | 项目源码 | 文件源码
def find_device_in_objects(objects, device_address, adapter_pattern=None):
    bus = dbus.SystemBus()
    path_prefix = ""
    if adapter_pattern:
        adapter = find_adapter_in_objects(objects, adapter_pattern)
        path_prefix = adapter.object_path
    for path, ifaces in objects.iteritems():
        device = ifaces.get(DEVICE_INTERFACE)
        if device is None:
            continue
        if (device["Address"] == device_address and
                        path.startswith(path_prefix)):
            obj = bus.get_object(SERVICE_NAME, path)
            return dbus.Interface(obj, DEVICE_INTERFACE)

    raise Exception("Bluetooth device not found")
项目:mpradio    作者:morrolinux    | 项目源码 | 文件源码
def find_device_in_objects(objects, device_address, adapter_pattern=None):
    bus = dbus.SystemBus()
    path_prefix = ""
    if adapter_pattern:
        adapter = find_adapter_in_objects(objects, adapter_pattern)
        path_prefix = adapter.object_path
    for path, ifaces in objects.iteritems():
        device = ifaces.get(DEVICE_INTERFACE)
        if device is None:
            continue
        if (device["Address"] == device_address and
                        path.startswith(path_prefix)):
            obj = bus.get_object(SERVICE_NAME, path)
            return dbus.Interface(obj, DEVICE_INTERFACE)

    raise Exception("Bluetooth device not found")
项目:Jackal_Velodyne_Duke    作者:MengGuo    | 项目源码 | 文件源码
def publish(self):
        bus = dbus.SystemBus()
        server = dbus.Interface(
            bus.get_object(
                avahi.DBUS_NAME,
                avahi.DBUS_PATH_SERVER
            ),
            avahi.DBUS_INTERFACE_SERVER
        )

        g = dbus.Interface(
            bus.get_object(
                avahi.DBUS_NAME,
                server.EntryGroupNew()
            ),
            avahi.DBUS_INTERFACE_ENTRY_GROUP
        )

        g.AddService(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, dbus.UInt32(0),
                     self.name, self.stype, self.domain, self.host,
                     dbus.UInt16(self.port), self.text)

        g.Commit()
        self.group = g
项目:senic-hub    作者:getsenic    | 项目源码 | 文件源码
def _find_adapter(self):
        """
        Tries to find a bluetooth adapter with the required functions.
        :return: path to an adapter or None
        """
        required_interfaces = [GATT_MANAGER_IFACE, LE_ADVERTISING_MANAGER_IFACE]
        object_manager = dbus.Interface(self.bus.get_object(BLUEZ_SERVICE_NAME, '/'), DBUS_OM_IFACE)
        objects = object_manager.GetManagedObjects()

        for object_path, properties in objects.items():
            missing_interfaces = [i for i in required_interfaces if i not in properties.keys()]
            if missing_interfaces:
                continue
            return object_path.rsplit('/', 1)[1]

        return None
项目:btc-fpga-miner    作者:marsohod4you    | 项目源码 | 文件源码
def publish(self):
        bus = dbus.SystemBus()
        server = dbus.Interface(
            bus.get_object(
                avahi.DBUS_NAME,
                avahi.DBUS_PATH_SERVER
            ),
            avahi.DBUS_INTERFACE_SERVER
        )

        g = dbus.Interface(
            bus.get_object(
                avahi.DBUS_NAME,
                server.EntryGroupNew()
            ),
            avahi.DBUS_INTERFACE_ENTRY_GROUP
        )

        g.AddService(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, dbus.UInt32(0),
                     self.name, self.stype, self.domain, self.host,
                     dbus.UInt16(self.port), self.text)

        g.Commit()
        self.group = g
项目:phony    作者:littlecraft    | 项目源码 | 文件源码
def _call_added(self, path, properties):
    call = dbus.Interface(
      self._bus.get_object(Ofono.SERVICE_NAME, path),
      Ofono.VOICE_CALL_INTERFACE
    )

    self._calls[call.object_path] = call

    properties = call.GetProperties()

    state = properties['State']
    number = properties['LineIdentification']

    self.log().info('%s: %s' % (state, number))

    listeners = []
    if state == 'incoming' or state == 'waiting':
      listeners = self._on_incoming_call_listeners
    elif state == 'active' or state == 'dialing':
      listeners = self._on_call_began_listeners

    for listener in listeners:
      listener(path)
项目:phony    作者:littlecraft    | 项目源码 | 文件源码
def attach_audio_gateway(self, adapter, device, listener):

    path, properties = self._find_child_hfp_modem(adapter, device)

    if path:
      modem = dbus.Interface(
        self._bus.get_object(self.SERVICE_NAME, path),
        self.MODEM_INTERFACE
      )

      if properties['Online']:
        self._transition_to(State.modem_came_online(modem, listener))
      else:
        self._transition_to(State.modem_found(modem, listener))
    else:
      self._transition_to(State.modem_not_found(adapter, device, listener))
项目:phony    作者:littlecraft    | 项目源码 | 文件源码
def _modem_found(self, path, properties):
    if self._state.is_waiting_for_modem_appearance():
      if Ofono._is_child_hfp_modem(self._state.adapter, self._state.device, path, properties):
        modem = dbus.Interface(
          self._bus.get_object(self.SERVICE_NAME, path),
          self.MODEM_INTERFACE
        )

        if properties['Online']:
          self._transition_to(
            State.modem_came_online(
              modem,
              self._state.audio_gateway_ready_listener
            )
          )
        else:
          self._transition_to(
            State.modem_found(
              modem,
              self._state.audio_gateway_ready_listener
            )
          )
项目:IceCash2    作者:redeyser    | 项目源码 | 文件源码
def check_ding(account, sender, message, conv, flags):
    sender = sender.encode('utf-8')
    message = message.encode('utf-8')
    obj = bus.get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject")
    purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")
    title = purple.PurpleConversationGetTitle(conv).encode('utf-8')
    if not title:
        title = conv
    if len(dingregex.findall(message)) > 0:
        pass
        #pynotify.init("Basics")
        #notify = pynotify.Notification("DING DING DING","{} called for DING DING DING in {}".format(sender,title),"emblem-danger")
        #notify.set_timeout(pynotify.EXPIRES_NEVER)
        #notify.show()

    if DEBUG:
        print "sender: {} message: {}, account: {}, conversation: {}, flags: {}, title: {}".format(sender,message,account,conv,flags,title)
    f=open("_","w")
    f.write(message)
    f.close()
    os.system("echo '%s' | python _sendFAX.py localhost 10111 Star +bw" % sender)
    os.system("cat _ | python _sendFAX.py localhost 10111 Star -")
项目:DirtyTooth-RaspberryPi    作者:ElevenPaths    | 项目源码 | 文件源码
def find_device_in_objects(objects, device_address, adapter_pattern=None):
    bus = dbus.SystemBus()
    path_prefix = ""
    if adapter_pattern:
        adapter = find_adapter_in_objects(objects, adapter_pattern)
        path_prefix = adapter.object_path
    for path, ifaces in objects.iteritems():
        device = ifaces.get(DEVICE_INTERFACE)
        if device is None:
            continue
        if (device["Address"] == device_address and
                        path.startswith(path_prefix)):
            obj = bus.get_object(SERVICE_NAME, path)
            return dbus.Interface(obj, DEVICE_INTERFACE)

    raise Exception("Bluetooth device not found")
项目:toggl2shotgun    作者:jfboismenu    | 项目源码 | 文件源码
def connected(self, service):
        if self.handle >= 0:
            return True
        bus = dbus.SessionBus()
        wId = 0
        try:
            remote_obj = bus.get_object(self.bus_name, self.object_path)
            self.iface = dbus.Interface(remote_obj, 'org.kde.KWallet')
            self.handle = self.iface.open(
                        self.iface.networkWallet(), wId, self.appid)
        except dbus.DBusException:
            self.handle = -1
        if self.handle < 0:
            return False
        self._migrate(service)
        return True
项目:PyDbusNetworkManager    作者:stoic1979    | 项目源码 | 文件源码
def get_introspection(self):
        bus = dbus.SystemBus()
        obj = bus.get_object('org.freedesktop.NetworkManager', '/org/freedesktop/NetworkManager')

        iface = dbus.Interface(obj, dbus_interface='org.freedesktop.DBus.Introspectable')

        # getting introspection xml
        m = iface.get_dbus_method("Introspect", dbus_interface=None)
        return m()
项目:PyDbusNetworkManager    作者:stoic1979    | 项目源码 | 文件源码
def get_devices(self):
        bus = dbus.SystemBus()
        wifi = bus.get_object('org.freedesktop.NetworkManager', '/org/freedesktop/NetworkManager')

        iface = dbus.Interface(wifi, dbus_interface='org.freedesktop.NetworkManager')

        # getting all devices
        m = iface.get_dbus_method("GetDevices", dbus_interface=None)
        devs = []
        for dev in m():
            devs.append("%s" % dev)
        return devs
项目:PyDbusNetworkManager    作者:stoic1979    | 项目源码 | 文件源码
def get_active_connections(self):
        bus = dbus.SystemBus()
        wifi = bus.get_object('org.freedesktop.NetworkManager', '/org/freedesktop/NetworkManager')

        iface = dbus.Interface(wifi, dbus_interface='org.freedesktop.DBus.Properties')

        m = iface.get_dbus_method("Get", dbus_interface=None)
        return [ str(ac) for ac in m("org.freedesktop.NetworkManager", "ActiveConnections") ]
项目:PyDbusNetworkManager    作者:stoic1979    | 项目源码 | 文件源码
def get_wifi_access_points_by_dev(self, device_path):
        bus = dbus.SystemBus()
        obj = bus.get_object('org.freedesktop.NetworkManager', device_path)

        iface = dbus.Interface(obj, dbus_interface='org.freedesktop.NetworkManager.Device.Wireless')

        # getting all wireless access points
        m = iface.get_dbus_method("GetAccessPoints", dbus_interface=None)

        return [str(ap) for ap in m()]
项目:PyDbusNetworkManager    作者:stoic1979    | 项目源码 | 文件源码
def get_access_point_all_info(self, ap_path):

        bus = dbus.SystemBus()
        obj = bus.get_object('org.freedesktop.NetworkManager', ap_path)

        iface = dbus.Interface(obj, dbus_interface='org.freedesktop.DBus.Properties')

        m = iface.get_dbus_method("GetAll", dbus_interface=None)

        # getting all ppoperties like Ssid, Strength, HwAddress etc.
        props = m("org.freedesktop.NetworkManager.AccessPoint")
        for k,v in props.iteritems():
            print k,v

        return props