Exemplo n.º 1
0
 def DataLv(self):
     return dbus.ObjectPath(self._data_lv)
Exemplo n.º 2
0
def AddWiFiConnection(self, dev_path, connection_name, ssid_name, key_mgmt):
    '''Add an available connection to an existing WiFi device and access point.

    You have to specify WiFi Device path, Connection object name,
    SSID and key management.

    The SSID must match one of the previously created access points.

    Please note that this does not set any global properties.

    Returns the new object path.
    '''

    dev_obj = dbusmock.get_object(dev_path)
    connection_path = '/org/freedesktop/NetworkManager/Settings/' + connection_name
    connections = dev_obj.Get(DEVICE_IFACE, 'AvailableConnections')

    settings_obj = dbusmock.get_object(SETTINGS_OBJ)
    main_connections = settings_obj.ListConnections()

    ssid = ssid_name.encode('UTF-8')

    # Find the access point by ssid
    access_point = None
    access_points = dev_obj.access_points
    for ap_path in access_points:
        ap = dbusmock.get_object(ap_path)
        if ap.Get(ACCESS_POINT_IFACE, 'Ssid') == ssid:
            access_point = ap
            break

    if not access_point:
        raise dbus.exceptions.DBusException(
            'Access point with SSID [%s] could not be found' % (ssid_name),
            name=MAIN_IFACE + '.DoesNotExist')

    hw_address = access_point.Get(ACCESS_POINT_IFACE, 'HwAddress')
    mode = access_point.Get(ACCESS_POINT_IFACE, 'Mode')
    security = access_point.Get(ACCESS_POINT_IFACE, 'WpaFlags')

    if connection_path in connections or connection_path in main_connections:
        raise dbus.exceptions.DBusException(
            'Connection %s on device %s already exists' % (connection_name, dev_path),
            name=MAIN_IFACE + '.AlreadyExists')

    # Parse mac address string into byte array
    mac_bytes = binascii.unhexlify(hw_address.replace(':', ''))

    settings = {
        '802-11-wireless': {
            'seen-bssids': [hw_address],
            'ssid': dbus.ByteArray(ssid),
            'mac-address': dbus.ByteArray(mac_bytes),
            'mode': InfrastructureMode.NAME_MAP[mode]
        },
        'connection': {
            'timestamp': dbus.UInt64(1374828522),
            'type': '802-11-wireless',
            'id': ssid_name,
            'uuid': str(uuid.uuid4())
        },
    }

    if security != NM80211ApSecurityFlags.NM_802_11_AP_SEC_NONE:
        settings['802-11-wireless']['security'] = '802-11-wireless-security'
        settings['802-11-wireless-security'] = NM80211ApSecurityFlags.NAME_MAP[security]

    self.AddObject(connection_path,
                   CSETTINGS_IFACE,
                   {
                       'Unsaved': False
                   },
                   [
                       ('Delete', '', '', 'self.ConnectionDelete(self)'),
                       ('GetSettings', '', 'a{sa{sv}}', 'ret = self.ConnectionGetSettings(self)'),
                       ('GetSecrets', 's', 'a{sa{sv}}', 'ret = self.ConnectionGetSecrets(self, args[0])'),
                       ('Update', 'a{sa{sv}}', '', 'self.ConnectionUpdate(self, args[0])'),
                   ])

    connection_obj = dbusmock.get_object(connection_path)
    connection_obj.settings = settings
    connection_obj.connection_path = connection_path
    connection_obj.ConnectionDelete = ConnectionDelete
    connection_obj.ConnectionGetSettings = ConnectionGetSettings
    connection_obj.ConnectionGetSecrets = ConnectionGetSecrets
    connection_obj.ConnectionUpdate = ConnectionUpdate

    connections.append(dbus.ObjectPath(connection_path))
    dev_obj.Set(DEVICE_IFACE, 'AvailableConnections', connections)

    main_connections.append(connection_path)
    settings_obj.Set(SETTINGS_IFACE, 'Connections', main_connections)

    settings_obj.EmitSignal(SETTINGS_IFACE, 'NewConnection', 'o', [ap_path])

    return connection_path
Exemplo n.º 3
0
 def __init__(self, obj, addr):
     self.addr = addr
     self.agent = None
     if (self.addr == 'net.connman.Manager'):
         self._props = dbus.Dictionary(
             {
                 dbus.String(u'State'):
                 dbus.String(u'online', variant_level=1),
                 dbus.String(u'OfflineMode'):
                 dbus.Boolean(False, variant_level=1),
                 dbus.String(u'SessionMode'):
                 dbus.Boolean(False, variant_level=1)
             },
             signature=dbus.Signature('sv'))  # noqa
         self._technologies = dbus.Array(
             [
                 dbus.Struct(
                     (dbus.ObjectPath('/net/connman/technology/wifi'),
                      dbus.Dictionary(
                          {
                              dbus.String(u'Connected'):
                              dbus.Boolean(False, variant_level=1),
                              dbus.String(u'Tethering'):
                              dbus.Boolean(False, variant_level=1),
                              dbus.String(u'Type'):
                              dbus.String(u'wifi', variant_level=1),
                              dbus.String(u'Name'):
                              dbus.String(u'WiFi', variant_level=1),
                              dbus.String(u'Powered'):
                              dbus.Boolean(True, variant_level=1)
                          },
                          signature=dbus.Signature('sv'))),
                     signature=None),
                 dbus.Struct(
                     (dbus.ObjectPath('/net/connman/technology/ethernet'),
                      dbus.Dictionary(
                          {
                              dbus.String(u'Connected'):
                              dbus.Boolean(True, variant_level=1),
                              dbus.String(u'Tethering'):
                              dbus.Boolean(False, variant_level=1),
                              dbus.String(u'Type'):
                              dbus.String(u'ethernet', variant_level=1),
                              dbus.String(u'Name'):
                              dbus.String(u'Wired', variant_level=1),
                              dbus.String(u'Powered'):
                              dbus.Boolean(True, variant_level=1)
                          },
                          signature=dbus.Signature('sv'))),
                     signature=None)
             ],
             signature=dbus.Signature('(oa{sv})'))  # noqa
         self._services = dbus.Array([
             dbus.Struct(
                 (dbus.ObjectPath(
                     '/net/connman/service/ethernet_b827ebaf24d8_cable'),
                  dbus.Dictionary(
                      {
                          dbus.String(u'IPv6.Configuration'):
                          dbus.Dictionary(
                              {
                                  dbus.String(u'Method'):
                                  dbus.String(u'auto', variant_level=1),
                                  dbus.String(u'Privacy'):
                                  dbus.String(u'disabled', variant_level=1)
                              },
                              signature=dbus.Signature('sv'),
                              variant_level=1),
                          dbus.String(u'AutoConnect'):
                          dbus.Boolean(True, variant_level=1),
                          dbus.String(u'Name'):
                          dbus.String(u'Wired', variant_level=1),
                          dbus.String(u'Nameservers'):
                          dbus.Array([dbus.String(u'192.168.1.254')],
                                     signature=dbus.Signature('s'),
                                     variant_level=1),
                          dbus.String(u'Provider'):
                          dbus.Dictionary({},
                                          signature=dbus.Signature('sv'),
                                          variant_level=1),
                          dbus.String(u'Favorite'):
                          dbus.Boolean(True, variant_level=1),
                          dbus.String(u'Domains.Configuration'):
                          dbus.Array([],
                                     signature=dbus.Signature('s'),
                                     variant_level=1),
                          dbus.String(u'Timeservers.Configuration'):
                          dbus.Array([],
                                     signature=dbus.Signature('s'),
                                     variant_level=1),
                          dbus.String(u'State'):
                          dbus.String(u'online', variant_level=1),
                          dbus.String(u'Proxy'):
                          dbus.Dictionary(
                              {
                                  dbus.String(u'Method'):
                                  dbus.String(u'direct', variant_level=1)
                              },
                              signature=dbus.Signature('sv'),
                              variant_level=1),
                          dbus.String(u'Nameservers.Configuration'):
                          dbus.Array([],
                                     signature=dbus.Signature('s'),
                                     variant_level=1),
                          dbus.String(u'IPv4'):
                          dbus.Dictionary(
                              {
                                  dbus.String(u'Netmask'):
                                  dbus.String(u'255.255.255.0',
                                              variant_level=1),
                                  dbus.String(u'Gateway'):
                                  dbus.String(u'192.168.1.254',
                                              variant_level=1),
                                  dbus.String(u'Method'):
                                  dbus.String(u'dhcp', variant_level=1),
                                  dbus.String(u'Address'):
                                  dbus.String(u'192.168.1.79',
                                              variant_level=1)
                              },
                              signature=dbus.Signature('sv'),
                              variant_level=1),
                          dbus.String(u'Timeservers'):
                          dbus.Array([dbus.String(u'192.168.1.254')],
                                     signature=dbus.Signature('s'),
                                     variant_level=1),
                          dbus.String(u'IPv6'):
                          dbus.Dictionary({},
                                          signature=dbus.Signature('sv'),
                                          variant_level=1),
                          dbus.String(u'Domains'):
                          dbus.Array([dbus.String(u'home')],
                                     signature=dbus.Signature('s'),
                                     variant_level=1),
                          dbus.String(u'Ethernet'):
                          dbus.Dictionary(
                              {
                                  dbus.String(u'Interface'):
                                  dbus.String(u'eth0', variant_level=1),
                                  dbus.String(u'MTU'):
                                  dbus.UInt16(1500, variant_level=1),
                                  dbus.String(u'Method'):
                                  dbus.String(u'auto', variant_level=1),
                                  dbus.String(u'Address'):
                                  dbus.String(u'B8:27:EB:AF:24:D8',
                                              variant_level=1)
                              },
                              signature=dbus.Signature('sv'),
                              variant_level=1),
                          dbus.String(u'Security'):
                          dbus.Array([],
                                     signature=dbus.Signature('s'),
                                     variant_level=1),
                          dbus.String(u'Proxy.Configuration'):
                          dbus.Dictionary({},
                                          signature=dbus.Signature('sv'),
                                          variant_level=1),
                          dbus.String(u'Type'):
                          dbus.String(u'ethernet', variant_level=1),
                          dbus.String(u'Immutable'):
                          dbus.Boolean(False, variant_level=1),
                          dbus.String(u'IPv4.Configuration'):
                          dbus.Dictionary(
                              {
                                  dbus.String(u'Method'):
                                  dbus.String(u'dhcp', variant_level=1)
                              },
                              signature=dbus.Signature('sv'),
                              variant_level=1)
                      },
                      signature=dbus.Signature('sv'))),
                 signature=None),
             dbus.Struct((dbus.ObjectPath(
                 '/net/connman/service/wifi_000f1330203f_4254576946692d776974682d464f4e_managed_none'
             ),
                          dbus.Dictionary(
                              {
                                  dbus.String(u'Strength'):
                                  dbus.Byte(73, variant_level=1),
                                  dbus.String(u'Nameservers'):
                                  dbus.Array([],
                                             signature=dbus.Signature('s'),
                                             variant_level=1),
                                  dbus.String(u'State'):
                                  dbus.String(u'idle', variant_level=1),
                                  dbus.String(u'Provider'):
                                  dbus.Dictionary(
                                      {},
                                      signature=dbus.Signature('sv'),
                                      variant_level=1),
                                  dbus.String(u'Type'):
                                  dbus.String(u'wifi', variant_level=1),
                                  dbus.String(u'Security'):
                                  dbus.Array([dbus.String(u'none')],
                                             signature=dbus.Signature('s'),
                                             variant_level=1),
                                  dbus.String(u'AutoConnect'):
                                  dbus.Boolean(False, variant_level=1),
                                  dbus.String(u'Immutable'):
                                  dbus.Boolean(False, variant_level=1),
                                  dbus.String(u'Proxy'):
                                  dbus.Dictionary(
                                      {},
                                      signature=dbus.Signature('sv'),
                                      variant_level=1),
                                  dbus.String(u'IPv4.Configuration'):
                                  dbus.Dictionary(
                                      {
                                          dbus.String(u'Method'):
                                          dbus.String(u'dhcp',
                                                      variant_level=1)
                                      },
                                      signature=dbus.Signature('sv'),
                                      variant_level=1),
                                  dbus.String(u'IPv6.Configuration'):
                                  dbus.Dictionary(
                                      {
                                          dbus.String(u'Method'):
                                          dbus.String(u'auto',
                                                      variant_level=1),
                                          dbus.String(u'Privacy'):
                                          dbus.String(u'disabled',
                                                      variant_level=1)
                                      },
                                      signature=dbus.Signature('sv'),
                                      variant_level=1),
                                  dbus.String(u'Name'):
                                  dbus.String(u'BTWiFi-with-FON',
                                              variant_level=1),
                                  dbus.String(u'Favorite'):
                                  dbus.Boolean(False, variant_level=1),
                                  dbus.String(u'Timeservers'):
                                  dbus.Array([],
                                             signature=dbus.Signature('s'),
                                             variant_level=1),
                                  dbus.String(u'Domains'):
                                  dbus.Array([],
                                             signature=dbus.Signature('s'),
                                             variant_level=1),
                                  dbus.String(u'Ethernet'):
                                  dbus.Dictionary(
                                      {
                                          dbus.String(u'Interface'):
                                          dbus.String(u'wlan0',
                                                      variant_level=1),
                                          dbus.String(u'Method'):
                                          dbus.String(u'auto',
                                                      variant_level=1),
                                          dbus.String(u'Address'):
                                          dbus.String(u'00:0F:13:30:20:3F',
                                                      variant_level=1)
                                      },
                                      signature=dbus.Signature('sv'),
                                      variant_level=1),
                                  dbus.String(u'Nameservers.Configuration'):
                                  dbus.Array([],
                                             signature=dbus.Signature('s'),
                                             variant_level=1),
                                  dbus.String(u'Proxy.Configuration'):
                                  dbus.Dictionary(
                                      {},
                                      signature=dbus.Signature('sv'),
                                      variant_level=1),
                                  dbus.String(u'Domains.Configuration'):
                                  dbus.Array([],
                                             signature=dbus.Signature('s'),
                                             variant_level=1),
                                  dbus.String(u'Timeservers.Configuration'):
                                  dbus.Array([],
                                             signature=dbus.Signature('s'),
                                             variant_level=1),
                                  dbus.String(u'IPv4'):
                                  dbus.Dictionary(
                                      {},
                                      signature=dbus.Signature('sv'),
                                      variant_level=1),
                                  dbus.String(u'IPv6'):
                                  dbus.Dictionary(
                                      {},
                                      signature=dbus.Signature('sv'),
                                      variant_level=1)
                              },
                              signature=dbus.Signature('sv'))),
                         signature=None),
             dbus.Struct((dbus.ObjectPath(
                 '/net/connman/service/wifi_000f1330203f_4254487562352d4e473657_managed_psk'
             ),
                          dbus.Dictionary(
                              {
                                  dbus.String(u'Strength'):
                                  dbus.Byte(73, variant_level=1),
                                  dbus.String(u'Nameservers'):
                                  dbus.Array([],
                                             signature=dbus.Signature('s'),
                                             variant_level=1),
                                  dbus.String(u'State'):
                                  dbus.String(u'idle', variant_level=1),
                                  dbus.String(u'Provider'):
                                  dbus.Dictionary(
                                      {},
                                      signature=dbus.Signature('sv'),
                                      variant_level=1),
                                  dbus.String(u'Type'):
                                  dbus.String(u'wifi', variant_level=1),
                                  dbus.String(u'Security'):
                                  dbus.Array([
                                      dbus.String(u'psk'),
                                      dbus.String(u'wps')
                                  ],
                                             signature=dbus.Signature('s'),
                                             variant_level=1),
                                  dbus.String(u'AutoConnect'):
                                  dbus.Boolean(False, variant_level=1),
                                  dbus.String(u'Immutable'):
                                  dbus.Boolean(False, variant_level=1),
                                  dbus.String(u'Proxy'):
                                  dbus.Dictionary(
                                      {},
                                      signature=dbus.Signature('sv'),
                                      variant_level=1),
                                  dbus.String(u'IPv4.Configuration'):
                                  dbus.Dictionary(
                                      {
                                          dbus.String(u'Method'):
                                          dbus.String(u'dhcp',
                                                      variant_level=1)
                                      },
                                      signature=dbus.Signature('sv'),
                                      variant_level=1),
                                  dbus.String(u'IPv6.Configuration'):
                                  dbus.Dictionary(
                                      {
                                          dbus.String(u'Method'):
                                          dbus.String(u'auto',
                                                      variant_level=1),
                                          dbus.String(u'Privacy'):
                                          dbus.String(u'disabled',
                                                      variant_level=1)
                                      },
                                      signature=dbus.Signature('sv'),
                                      variant_level=1),
                                  dbus.String(u'Name'):
                                  dbus.String(u'BTHub5-NG6W',
                                              variant_level=1),
                                  dbus.String(u'Favorite'):
                                  dbus.Boolean(False, variant_level=1),
                                  dbus.String(u'Timeservers'):
                                  dbus.Array([],
                                             signature=dbus.Signature('s'),
                                             variant_level=1),
                                  dbus.String(u'Domains'):
                                  dbus.Array([],
                                             signature=dbus.Signature('s'),
                                             variant_level=1),
                                  dbus.String(u'Ethernet'):
                                  dbus.Dictionary(
                                      {
                                          dbus.String(u'Interface'):
                                          dbus.String(u'wlan0',
                                                      variant_level=1),
                                          dbus.String(u'Method'):
                                          dbus.String(u'auto',
                                                      variant_level=1),
                                          dbus.String(u'Address'):
                                          dbus.String(u'00:0F:13:30:20:3F',
                                                      variant_level=1)
                                      },
                                      signature=dbus.Signature('sv'),
                                      variant_level=1),
                                  dbus.String(u'Nameservers.Configuration'):
                                  dbus.Array([],
                                             signature=dbus.Signature('s'),
                                             variant_level=1),
                                  dbus.String(u'Proxy.Configuration'):
                                  dbus.Dictionary(
                                      {},
                                      signature=dbus.Signature('sv'),
                                      variant_level=1),
                                  dbus.String(u'Domains.Configuration'):
                                  dbus.Array([],
                                             signature=dbus.Signature('s'),
                                             variant_level=1),
                                  dbus.String(u'Timeservers.Configuration'):
                                  dbus.Array([],
                                             signature=dbus.Signature('s'),
                                             variant_level=1),
                                  dbus.String(u'IPv4'):
                                  dbus.Dictionary(
                                      {},
                                      signature=dbus.Signature('sv'),
                                      variant_level=1),
                                  dbus.String(u'IPv6'):
                                  dbus.Dictionary(
                                      {},
                                      signature=dbus.Signature('sv'),
                                      variant_level=1)
                              },
                              signature=dbus.Signature('sv'))),
                         signature=None),
             dbus.Struct((dbus.ObjectPath(
                 '/net/connman/service/wifi_000f1330203f_544e434150374345434535_managed_psk'
             ),
                          dbus.Dictionary(
                              {
                                  dbus.String(u'Strength'):
                                  dbus.Byte(49, variant_level=1),
                                  dbus.String(u'Nameservers'):
                                  dbus.Array([],
                                             signature=dbus.Signature('s'),
                                             variant_level=1),
                                  dbus.String(u'State'):
                                  dbus.String(u'idle', variant_level=1),
                                  dbus.String(u'Provider'):
                                  dbus.Dictionary(
                                      {},
                                      signature=dbus.Signature('sv'),
                                      variant_level=1),
                                  dbus.String(u'Type'):
                                  dbus.String(u'wifi', variant_level=1),
                                  dbus.String(u'Security'):
                                  dbus.Array([
                                      dbus.String(u'psk'),
                                      dbus.String(u'wps')
                                  ],
                                             signature=dbus.Signature('s'),
                                             variant_level=1),
                                  dbus.String(u'AutoConnect'):
                                  dbus.Boolean(False, variant_level=1),
                                  dbus.String(u'Immutable'):
                                  dbus.Boolean(False, variant_level=1),
                                  dbus.String(u'Proxy'):
                                  dbus.Dictionary(
                                      {},
                                      signature=dbus.Signature('sv'),
                                      variant_level=1),
                                  dbus.String(u'IPv4.Configuration'):
                                  dbus.Dictionary(
                                      {
                                          dbus.String(u'Method'):
                                          dbus.String(u'dhcp',
                                                      variant_level=1)
                                      },
                                      signature=dbus.Signature('sv'),
                                      variant_level=1),
                                  dbus.String(u'IPv6.Configuration'):
                                  dbus.Dictionary(
                                      {
                                          dbus.String(u'Method'):
                                          dbus.String(u'auto',
                                                      variant_level=1),
                                          dbus.String(u'Privacy'):
                                          dbus.String(u'disabled',
                                                      variant_level=1)
                                      },
                                      signature=dbus.Signature('sv'),
                                      variant_level=1),
                                  dbus.String(u'Name'):
                                  dbus.String(u'TNCAP7CECE5',
                                              variant_level=1),
                                  dbus.String(u'Favorite'):
                                  dbus.Boolean(False, variant_level=1),
                                  dbus.String(u'Timeservers'):
                                  dbus.Array([],
                                             signature=dbus.Signature('s'),
                                             variant_level=1),
                                  dbus.String(u'Domains'):
                                  dbus.Array([],
                                             signature=dbus.Signature('s'),
                                             variant_level=1),
                                  dbus.String(u'Ethernet'):
                                  dbus.Dictionary(
                                      {
                                          dbus.String(u'Interface'):
                                          dbus.String(u'wlan0',
                                                      variant_level=1),
                                          dbus.String(u'Method'):
                                          dbus.String(u'auto',
                                                      variant_level=1),
                                          dbus.String(u'Address'):
                                          dbus.String(u'00:0F:13:30:20:3F',
                                                      variant_level=1)
                                      },
                                      signature=dbus.Signature('sv'),
                                      variant_level=1),
                                  dbus.String(u'Nameservers.Configuration'):
                                  dbus.Array([],
                                             signature=dbus.Signature('s'),
                                             variant_level=1),
                                  dbus.String(u'Proxy.Configuration'):
                                  dbus.Dictionary(
                                      {},
                                      signature=dbus.Signature('sv'),
                                      variant_level=1),
                                  dbus.String(u'Domains.Configuration'):
                                  dbus.Array([],
                                             signature=dbus.Signature('s'),
                                             variant_level=1),
                                  dbus.String(u'Timeservers.Configuration'):
                                  dbus.Array([],
                                             signature=dbus.Signature('s'),
                                             variant_level=1),
                                  dbus.String(u'IPv4'):
                                  dbus.Dictionary(
                                      {},
                                      signature=dbus.Signature('sv'),
                                      variant_level=1),
                                  dbus.String(u'IPv6'):
                                  dbus.Dictionary(
                                      {},
                                      signature=dbus.Signature('sv'),
                                      variant_level=1)
                              },
                              signature=dbus.Signature('sv'))),
                         signature=None)
         ],
                                     signature=dbus.Signature(
                                         '(oa{sv})'))  # noqa
     elif (self.addr == 'net.connman.Technology'):
         self._props = dbus.Dictionary(
             {
                 dbus.String(u'Connected'): dbus.Boolean(False,
                                                         variant_level=1),
                 dbus.String(u'Tethering'): dbus.Boolean(False,
                                                         variant_level=1),
                 dbus.String(u'Type'): dbus.String(u'wifi',
                                                   variant_level=1),
                 dbus.String(u'Name'): dbus.String(u'WiFi',
                                                   variant_level=1),
                 dbus.String(u'Powered'): dbus.Boolean(True,
                                                       variant_level=1)
             },
             signature=dbus.Signature('sv'))  # noqa
     elif (self.addr == 'net.connman.Service'):
         self._props = dbus.Dictionary(
             {
                 dbus.String(u'IPv6.Configuration'):
                 dbus.Dictionary(
                     {
                         dbus.String(u'Method'):
                         dbus.String(u'auto', variant_level=1),
                         dbus.String(u'Privacy'):
                         dbus.String(u'disabled', variant_level=1)
                     },
                     signature=dbus.Signature('sv'),
                     variant_level=1),
                 dbus.String(u'AutoConnect'):
                 dbus.Boolean(True, variant_level=1),
                 dbus.String(u'Name'):
                 dbus.String(u'Wired', variant_level=1),
                 dbus.String(u'Nameservers'):
                 dbus.Array([dbus.String(u'192.168.1.254')],
                            signature=dbus.Signature('s'),
                            variant_level=1),
                 dbus.String(u'Provider'):
                 dbus.Dictionary(
                     {}, signature=dbus.Signature('sv'), variant_level=1),
                 dbus.String(u'Favorite'):
                 dbus.Boolean(True, variant_level=1),
                 dbus.String(u'Domains.Configuration'):
                 dbus.Array(
                     [], signature=dbus.Signature('s'), variant_level=1),
                 dbus.String(u'Timeservers.Configuration'):
                 dbus.Array(
                     [], signature=dbus.Signature('s'), variant_level=1),
                 dbus.String(u'State'):
                 dbus.String(u'online', variant_level=1),
                 dbus.String(u'Proxy'):
                 dbus.Dictionary(
                     {
                         dbus.String(u'Method'):
                         dbus.String(u'direct', variant_level=1)
                     },
                     signature=dbus.Signature('sv'),
                     variant_level=1),
                 dbus.String(u'Nameservers.Configuration'):
                 dbus.Array(
                     [], signature=dbus.Signature('s'), variant_level=1),
                 dbus.String(u'IPv4'):
                 dbus.Dictionary(
                     {
                         dbus.String(u'Netmask'):
                         dbus.String(u'255.255.255.0', variant_level=1),
                         dbus.String(u'Gateway'):
                         dbus.String(u'192.168.1.254', variant_level=1),
                         dbus.String(u'Method'):
                         dbus.String(u'dhcp', variant_level=1),
                         dbus.String(u'Address'):
                         dbus.String(u'192.168.1.79', variant_level=1)
                     },
                     signature=dbus.Signature('sv'),
                     variant_level=1),
                 dbus.String(u'Timeservers'):
                 dbus.Array([dbus.String(u'192.168.1.254')],
                            signature=dbus.Signature('s'),
                            variant_level=1),
                 dbus.String(u'IPv6'):
                 dbus.Dictionary(
                     {}, signature=dbus.Signature('sv'), variant_level=1),
                 dbus.String(u'Domains'):
                 dbus.Array([dbus.String(u'home')],
                            signature=dbus.Signature('s'),
                            variant_level=1),
                 dbus.String(u'Ethernet'):
                 dbus.Dictionary(
                     {
                         dbus.String(u'Interface'):
                         dbus.String(u'eth0', variant_level=1),
                         dbus.String(u'MTU'):
                         dbus.UInt16(1500, variant_level=1),
                         dbus.String(u'Method'):
                         dbus.String(u'auto', variant_level=1),
                         dbus.String(u'Address'):
                         dbus.String(u'B8:27:EB:AF:24:D8', variant_level=1)
                     },
                     signature=dbus.Signature('sv'),
                     variant_level=1),
                 dbus.String(u'Security'):
                 dbus.Array(
                     [], signature=dbus.Signature('s'), variant_level=1),
                 dbus.String(u'Proxy.Configuration'):
                 dbus.Dictionary(
                     {}, signature=dbus.Signature('sv'), variant_level=1),
                 dbus.String(u'Type'):
                 dbus.String(u'ethernet', variant_level=1),
                 dbus.String(u'Immutable'):
                 dbus.Boolean(False, variant_level=1),
                 dbus.String(u'IPv4.Configuration'):
                 dbus.Dictionary(
                     {
                         dbus.String(u'Method'):
                         dbus.String(u'dhcp', variant_level=1)
                     },
                     signature=dbus.Signature('sv'),
                     variant_level=1)
             },
             signature=dbus.Signature('sv'))  # noqa
Exemplo n.º 4
0
 def get_path(self):
     """Return the DBus object path"""
     return dbus.ObjectPath(self.path)
Exemplo n.º 5
0
 def GetPath(self):
     return dbus.ObjectPath(self.__session_path)
Exemplo n.º 6
0
    def setproperty(self, name, val):
        """
            Properly sets properties on player interface

            don't use this method from dbus interface, all values should
            be set from player (to keep them correct)
        """
        if name == 'pause':
            oldval = self.properties[PLAYER_INTERFACE]['read_only'][
                'PlaybackStatus']
            newval = None
            if val:
                newval = 'Paused'
            else:
                newval = 'Playing'

            if newval != oldval:
                self.properties[PLAYER_INTERFACE]['read_only'][
                    'PlaybackStatus'] = newval
                self.PropertiesChanged(PLAYER_INTERFACE,
                                       {'PlaybackStatus': newval}, [])

        elif name == 'stop':
            oldval = self.properties[PLAYER_INTERFACE]['read_only'][
                'PlaybackStatus']
            newval = None
            if val:
                newval = 'Stopped'
            else:
                newval = 'Playing'

            if newval != oldval:
                self.properties[PLAYER_INTERFACE]['read_only'][
                    'PlaybackStatus'] = newval
                self.PropertiesChanged(PLAYER_INTERFACE,
                                       {'PlaybackStatus': newval},
                                       ['Metadata', 'Position'])

        elif name == 'volume' and val is not None:
            oldval = self.properties[PLAYER_INTERFACE]['read_write']['Volume']
            newval = float(val) / 100

            if newval != oldval:
                self.properties[PLAYER_INTERFACE]['read_write'][
                    'Volume'] = newval
                self.PropertiesChanged(PLAYER_INTERFACE, {'Volume': newval},
                                       [])

        elif name == 'time-pos' and val:
            oldval = self.properties[PLAYER_INTERFACE]['read_only']['Position']
            newval = dbus.Int64(val * 10**6)

            if newval != oldval:
                self.properties[PLAYER_INTERFACE]['read_only'][
                    'Position'] = newval
            if abs(newval - oldval) >= 4 * 10**6:
                self.Seeked(newval)

        elif name == 'metadata' and val:
            trackid, title, length, arturl = val
            # sanitize ytid - it uses '-_' which are not valid in dbus paths
            trackid = re.sub('[^a-zA-Z0-9]', '', trackid)

            oldval = self.properties[PLAYER_INTERFACE]['read_only']['Metadata']
            newval = {
                'mpris:trackid':
                dbus.ObjectPath('/CurrentPlaylist/ytid/' + trackid,
                                variant_level=1),
                'mpris:length':
                dbus.Int64(length * 10**6, variant_level=1),
                'mpris:artUrl':
                dbus.String(arturl, variant_level=1),
                'xesam:title':
                dbus.String(title, variant_level=1)
            }

            if newval != oldval:
                self.properties[PLAYER_INTERFACE]['read_only'][
                    'Metadata'] = newval
                self.PropertiesChanged(PLAYER_INTERFACE, {'Metadata': newval},
                                       [])

        elif name == 'seeking':
            # send signal to keep time-pos synced between player and client
            if not val:
                self.Seeked(
                    self.properties[PLAYER_INTERFACE]['read_only']['Position'])
Exemplo n.º 7
0
 def set_video_geometry(self, x1, y1, x2, y2):
     self.dbusif_player.VideoPos(dbus.ObjectPath('/not/used'), str(x1) + ' ' + str(y1) + ' ' + str(x2)+ ' ' + str(y2))
 def set_fallback_source(self, fallback_source):
     try:
         self.set_property("FallbackSource", dbus.ObjectPath(fallback_source))
     except:
         traceback.print_exc()
 def get_path(self):
     """ This method gets called to get the Object path of the interface dbus used for the characteristic. """
     return dbus.ObjectPath(self.path)
Exemplo n.º 10
0
 def set_active_profile(self, active_profile):
     self.set_property("ActiveProfile", dbus.ObjectPath(active_profile))
Exemplo n.º 11
0
 def set_fallback_sink(self, fallback_sink):
     try:
         self.set_property("FallbackSink", dbus.ObjectPath(fallback_sink))
     except:
         traceback.print_exc()
Exemplo n.º 12
0
def AddSession(self, session_id, seat, uid, username, active):
    '''Convenience method to add a session.

    If the given seat and/or user do not exit, they will be created.

    Return the object path of the new session.
    '''
    seat_path = dbus.ObjectPath('/org/freedesktop/login1/seat/' + seat)
    if seat_path not in mockobject.objects:
        self.AddSeat(seat)

    user_path = dbus.ObjectPath('/org/freedesktop/login1/user/%i' % uid)
    if user_path not in mockobject.objects:
        self.AddUser(uid, username, active)

    session_path = dbus.ObjectPath('/org/freedesktop/login1/session/' +
                                   session_id)
    if session_path in mockobject.objects:
        raise dbus.exceptions.DBusException('Session %s already exists' %
                                            session_id,
                                            name=MOCK_IFACE + '.SessionExists')

    self.AddObject(
        session_path, 'org.freedesktop.login1.Session', {
            'Controllers': dbus.Array([], signature='s'),
            'ResetControllers': dbus.Array([], signature='s'),
            'Active': active,
            'IdleHint': False,
            'KillProcesses': False,
            'Remote': False,
            'Class': 'user',
            'DefaultControlGroup': 'systemd:/user/%s/%s' %
            (username, session_id),
            'Display': os.getenv('DISPLAY', ''),
            'Id': session_id,
            'Name': username,
            'RemoteHost': '',
            'RemoteUser': '',
            'Service': 'dbusmock',
            'State': (active and 'active' or 'online'),
            'TTY': '',
            'Type': 'test',
            'Seat': (seat, seat_path),
            'User': (dbus.UInt32(uid), user_path),
            'Audit': dbus.UInt32(0),
            'Leader': dbus.UInt32(1),
            'VTNr': dbus.UInt32(1),
            'IdleSinceHint': dbus.UInt64(0),
            'IdleSinceHintMonotonic': dbus.UInt64(0),
            'Timestamp': dbus.UInt64(42),
            'TimestampMonotonic': dbus.UInt64(42),
        }, [
            ('Activate', '', '', ''),
            ('Kill', 'ss', '', ''),
            ('Lock', '', '', ''),
            ('SetIdleHint', 'b', '', ''),
            ('Terminate', '', '', ''),
            ('Unlock', '', '', ''),
        ])

    # add session to seat
    obj_seat = mockobject.objects[seat_path]
    cur_sessions = obj_seat.Get('org.freedesktop.login1.Seat', 'Sessions')
    cur_sessions.append((session_id, session_path))
    obj_seat.Set('org.freedesktop.login1.Seat', 'Sessions', cur_sessions)
    obj_seat.Set('org.freedesktop.login1.Seat', 'ActiveSession',
                 (session_id, session_path))

    # add session to user
    obj_user = mockobject.objects[user_path]
    cur_sessions = obj_user.Get('org.freedesktop.login1.User', 'Sessions')
    cur_sessions.append((session_id, session_path))
    obj_user.Set('org.freedesktop.login1.User', 'Sessions', cur_sessions)

    return session_path
Exemplo n.º 13
0
 def CachePool(self):
     return dbus.ObjectPath(self.state.PoolLv)
Exemplo n.º 14
0
 def MetaDataLv(self):
     return dbus.ObjectPath(self._metadata_lv)
Exemplo n.º 15
0
		# Convert the byte-array for SSID and BSSID to printable strings
		bssid = ""
		for item in props["bssid"]:
			bssid = bssid + ":%02x" % item
		bssid = bssid[1:]
		ssid = byte_array_to_string(props["ssid"])
		wpa = "no"
		if props.has_key("wpaie"):
			wpa = "yes"
		wpa2 = "no"
		if props.has_key("rsnie"):
			wpa2 = "yes"
		freq = 0
		if props.has_key("frequency"):
			freq = props["frequency"]
		caps = props["capabilities"]
		qual = props["quality"]
		level = props["level"]
		noise = props["noise"]
		maxrate = props["maxrate"] / 1000000

		print "  %s  ::  ssid='%s'  wpa=%s  wpa2=%s  quality=%d%%  rate=%d  freq=%d" % (bssid, ssid, wpa, wpa2, qual, maxrate, freq)

	wpas.removeInterface(dbus.ObjectPath(path))
	# Should fail here with unknown interface error
	iface.scan()

if __name__ == "__main__":
	main()

 def get_path(self):
     """ This method gets called to get the Object path of the dbus used for the BLE service. """
     return dbus.ObjectPath(self.path)
Exemplo n.º 17
0
 def GetMenuForWindow(self, windowId):
   if windowId in self.window_dict:
     sender, menuObjectPath = self.window_dict[windowId]
     return [dbus.String(sender), dbus.ObjectPath(menuObjectPath)]
Exemplo n.º 18
0
import dbus
from ctypes import c_longlong

bus = dbus.SessionBus()

parole = bus.get_object('org.Parole.Media.Player', '/org/Parole/Media/Player')

iface = dbus.Interface(parole, 'org.mpris.MediaPlayer2')

print parole.Introspect()
print iface.Introspect()

parole.SetPosition(
    dbus.ObjectPath("/org/mpris/MediaPlayer2/TrackList/0x7f7c5a8dd100"),
    dbus.Int64(50000000))
Exemplo n.º 19
0
 def set_position(self, secs):
     return self.dbusif_player.SetPosition(dbus.ObjectPath('/not/used'), long(secs*1000000))
Exemplo n.º 20
0
	def Result(self):
		return dbus.ObjectPath(self.state.Result)
Exemplo n.º 21
0
 def set_aspect_mode(self, mode):
     '''Use any of the OMXPlayer.AM_??? constants as <mode>'''
     self.dbusif_player.SetAspectMode(dbus.ObjectPath('/not/used'), mode)
Exemplo n.º 22
0
 def __get_current_track_id(self):
     path = "/net/sacredchao/QuodLibet"
     if not app.player.info:
         return dbus.ObjectPath(path + "/" + "NoTrack")
     return dbus.ObjectPath(path + "/" + str(id(app.player.info)))
Exemplo n.º 23
0
class OMXPlayerTests(unittest.TestCase):
    TEST_FILE_NAME = "./test.mp4"
    TEST_URL = "rtmp://192.168.0.1/live/mystream"

    def test_opens_file_in_omxplayer(self, popen, *args):
        self.patch_and_run_omxplayer()
        devnull = MOCK_OPEN()
        popen.assert_called_once_with(
            ['omxplayer', './test.mp4'],
            preexec_fn=os.setsid,
            stdin=devnull,
            stdout=devnull)

    @patch('time.sleep')
    def test_tries_to_open_dbus_again_if_it_cant_connect(self, *args):
        # TODO: Shouldn't this be DBusConnectionError not SystemError
        with self.assertRaises(SystemError):
            dbus_connection = Mock(side_effect=DBusConnectionError)
            self.patch_and_run_omxplayer(Connection=dbus_connection)
            self.assertEqual(50, self.player.tries)

    @parameterized.expand([
        ['can_quit', 'CanQuit', [], []],
        ['can_set_fullscreen', 'CanSetFullscreen', [], []],
        ['identity', 'Identity', [], []]
    ])
    def test_root_interface_commands(self, popen, sleep, isfile, killpg, command_name,
                                     interface_command_name, *args):
        self.patch_and_run_omxplayer()
        self.patch_interface_and_run_command('_get_root_interface',
                                             command_name,
                                             interface_command_name, *args)

    @parameterized.expand([
        ['pause', 'Pause', [], []],
        ['stop', 'Stop', [], []],
        ['seek', 'Seek', [100], [100]],
        ['set_position', 'SetPosition', [1], [dbus.ObjectPath("/not/used"),
                                              dbus.Int64(1000000)]],
        ['list_subtitles', 'ListSubtitles', [], []],
        ['action', 'Action', ['p'], ['p']]
    ])
    def test_player_interface_commands(self, popen, sleep, isfile, killpg, command_name,
                                       interface_command_name, *args):
        self.patch_and_run_omxplayer()
        self.patch_interface_and_run_command('_get_player_interface',
                                             command_name,
                                             interface_command_name, *args)

    @parameterized.expand([
        ['can_play', 'CanPlay', [], []],
        ['can_seek', 'CanSeek', [], []],
        ['can_control', 'CanControl', [], []],
        ['playback_status', 'PlaybackStatus', [], []],
        ['volume', 'Volume', [], []],
        ['mute', 'Mute', [], []],
        ['unmute', 'Unmute', [], []],
        ['position', 'Position', [], []],
        ['duration', 'Duration', [], []],
        ['minimum_rate', 'MinimumRate', [], []],
        ['maximum_rate', 'MaximumRate', [], []],
    ])
    def test_properties_interface_commands(self, popen, sleep, isfile, killpg, command_name,
                                           interface_command_name, *args):
        self.patch_and_run_omxplayer()
        self.patch_interface_and_run_command('_get_properties_interface',
                                             command_name,
                                             interface_command_name, *args)

    def test_quitting(self, popen, sleep, isfile, killpg, *args):
        omxplayer_process = Mock()
        popen.return_value = omxplayer_process
        self.patch_and_run_omxplayer()
        with patch('os.getpgid', Mock(return_value=omxplayer_process.pid)):
            self.player.quit()
            killpg.assert_called_once_with(omxplayer_process.pid, signal.SIGTERM)

    def test_quitting_waits_for_omxplayer_to_die(self, popen, sleep, isfile, killpg, *args):
        omxplayer_process = Mock()
        popen.return_value = omxplayer_process
        self.patch_and_run_omxplayer()
        with patch('os.getpgid'):
            self.player.quit()
            omxplayer_process.wait.assert_has_calls([call()])

    def test_check_process_still_exists_before_dbus_call(self, *args):
        self.patch_and_run_omxplayer()
        self.player._process = process = Mock(return_value=None)
        process.poll.return_value = None

        self.player.can_quit()

        process.poll.assert_called_once_with()

    def test_checks_media_file_exists_before_launching_player(self, *args):
        with patch('os.path') as ospath:
            self.patch_and_run_omxplayer()
            ospath.isfile.assert_called_once_with(self.TEST_FILE_NAME)

    def test_player_doesnt_check_source_path_exists_for_a_url(self, *args):
        with patch('os.path') as ospath:
            self.patch_and_run_omxplayer_url()
            ospath.isfile.assert_not_called()

    def test_stop_event(self, *args):
        self.patch_and_run_omxplayer(active=True)
        callback = Mock()
        self.player.stopEvent += callback

        self.player.stop()

        callback.assert_called_once_with(self.player)

    def test_play_event(self, *args):
        self.patch_and_run_omxplayer(active=True)
        callback = Mock()
        self.player.playEvent += callback

        with patch.object(self.player, 'is_playing', return_value=False):
            self.player.play()

            callback.assert_called_once_with(self.player)

    def test_pause_event(self, *args):
        self.patch_and_run_omxplayer(active=True)
        callback = Mock()
        self.player.pauseEvent += callback

        with patch.object(self.player, 'is_playing', return_value=True):
            self.player.pause()

            callback.assert_called_once_with(self.player)

    def test_play_event_by_play_pause(self, *args):
        self.patch_and_run_omxplayer(active=True)
        callback = Mock()
        self.player.playEvent += callback

        with patch.object(self.player, 'is_playing', return_value=False):
            self.player.pause()

            # play
            self.player.play_pause()

            callback.assert_called_once_with(self.player)

    def test_pause_event_by_play_pause(self, *args):
        self.patch_and_run_omxplayer(active=True)
        callback = Mock()
        self.player.pauseEvent += callback

        with patch.object(self.player, 'is_playing', return_value=True):
            self.player.play()

            # pause
            self.player.play_pause()

            callback.assert_called_once_with(self.player)

    def test_seek_event(self, *args):
        self.patch_and_run_omxplayer(active=True)
        callback = Mock()
        self.player.seekEvent += callback

        self.player.seek(3.4)

        callback.assert_called_once_with(self.player, 3.4)

    def test_position_event(self, *args):
        self.patch_and_run_omxplayer(active=True)
        callback = Mock()
        self.player.positionEvent += callback

        self.player.set_position(5.01)

        callback.assert_called_once_with(self.player, 5.01)

    def patch_interface_and_run_command(self, interface_name,
                                        command_name, interface_command_name,
                                        command_args,
                                        expected_args):
        self.player._process.poll = Mock(return_value=None)
        with patch.object(self.player, interface_name) as interface:
            self.run_command(command_name, *command_args)
            # generates a call of the form `call().CanQuit`
            expected_call = getattr(call(), interface_command_name)(*expected_args)
            interface.assert_has_calls([expected_call])

    def run_command(self, command_name, *args):
        command = getattr(self.player, command_name)
        command(*args)

    # Must have the prefix 'patch' for the decorators to take effect
    def patch_and_run_omxplayer(self, Connection=Mock(), active=False):
        bus_address_finder = Mock()
        bus_address_finder.get_address.return_val = "example_bus_address"
        self.player = OMXPlayer(self.TEST_FILE_NAME,
                                bus_address_finder=bus_address_finder,
                                Connection=Connection)
        if active:
            self.player._process.poll = Mock(return_value=None)

    def patch_and_run_omxplayer_url(self, Connection=Mock(), active=False):
        bus_address_finder = Mock()
        bus_address_finder.get_address.return_val = "example_bus_address"
        self.player = OMXPlayer(self.TEST_URL,
                                bus_address_finder=bus_address_finder,
                                Connection=Connection)
        if active:
            self.player._process.poll = Mock(return_value=None)

    def test_load(self, popen, sleep, isfile, killpg, *args):
        omxplayer_process = Mock()
        popen.return_value = omxplayer_process
        with patch('os.getpgid', Mock(return_value=omxplayer_process.pid)):
            self.patch_and_run_omxplayer(active=True)
            # initial load
            self.assertEqual(self.player.get_filename(), './test.mp4')
            killpg.assert_not_called()
            popen.assert_called_once_with(['omxplayer', './test.mp4'],
                                        preexec_fn=os.setsid,
                                        stdin=MOCK_OPEN(),
                                        stdout=MOCK_OPEN())
            # load new video in same OMXPlayer instance
            self.player.load('./test2.mp4')
            # verify new video is registered in OMXPlayer
            self.assertEqual(self.player.get_filename(), './test2.mp4')
            # verify omxplayer process for previous video was killed
            killpg.assert_called_once_with(omxplayer_process.pid, signal.SIGTERM)
            # verify a new process was started for the second time
            self.assertEqual(popen.call_count, 2)


    def test_init_without_pause(self, popen, sleep, isfile, killpg, *args):
        with patch.object(OMXPlayer, 'pause', return_value=None) as mock_method:
            self.patch_and_run_omxplayer()
            self.assertEqual(mock_method.call_count, 0)

    def test_init_pause(self, popen, sleep, isfile, killpg, *args):
        with patch.object(OMXPlayer, 'pause', return_value=None) as mock_method:
            # self.patch_and_run_omxplayer(pause=False)
            bus_address_finder = Mock()
            bus_address_finder.get_address.return_val = "example_bus_address"
            self.player = OMXPlayer(self.TEST_FILE_NAME,
                                bus_address_finder=bus_address_finder,
                                Connection=Mock(),
                                pause=True)

            self.assertEqual(mock_method.call_count, 1)

    def test_load_and_pause(self, popen, sleep, isfile, killpg, *args):
        with patch.object(OMXPlayer, 'pause', return_value=None) as mock_method:
            self.patch_and_run_omxplayer()
            self.player.load('./test2.mp4', pause=True)
            self.assertEqual(mock_method.call_count, 1)

    def test_load_without_pause(self, popen, sleep, isfile, killpg, *args):
        with patch.object(OMXPlayer, 'pause', return_value=None) as mock_method:
            self.patch_and_run_omxplayer()
            self.player.load('./test2.mp4')
            self.assertEqual(mock_method.call_count, 0)
Exemplo n.º 24
0
    print("** Usage: %s <D-Bus configuration path>" % sys.argv[0])
    sys.exit(1)

# Get a connection to the system bus
bus = dbus.SystemBus()

# Retrieve the main session manager object
manager_object = bus.get_object('net.openvpn.v3.sessions',
                                '/net/openvpn/v3/sessions')

# Retireve access to the proper interface in the object
sessmgr_interface = dbus.Interface(manager_object,
                                   dbus_interface='net.openvpn.v3.sessions')

# Prepare the tunnel (type casting string to D-Bus objet path variable)
session_path = sessmgr_interface.NewTunnel(dbus.ObjectPath(sys.argv[1]))
print("Session path: " + session_path)
time.sleep(1)  # Wait for things to settle down

# Get access to the session object
session_object = bus.get_object('net.openvpn.v3.sessions', session_path)

# Get the proper interface access
session_interface = dbus.Interface(session_object,
                                   dbus_interface='net.openvpn.v3.sessions')
session_properties = dbus.Interface(
    session_object, dbus_interface='org.freedesktop.DBus.Properties')

#
# Start the tunnel
#
Exemplo n.º 25
0
 def TransferOwnership(self, sesspath, new_uid):
     self.__manager_intf.TransferOwnership(dbus.ObjectPath(sesspath),
                                           dbus.UInt32(new_uid))
Exemplo n.º 26
0
def label_path(label: Label) -> dbus.ObjectPath:
    ''' Return the D-Bus object path for a `qubes.Label` '''
    return dbus.ObjectPath('/org/qubes/Labels1/labels/' + label.name)
Exemplo n.º 27
0
def SettingsAddConnection(self, connection_settings):
    '''Add a connection.

    connection_settings is a String String Variant Map Map. See
    https://developer.gnome.org/NetworkManager/0.9/spec.html
        #type-String_String_Variant_Map_Map

    If you omit uuid, this method adds one for you.
    '''

    if 'uuid' not in connection_settings['connection']:
        connection_settings['connection']['uuid'] = str(uuid.uuid4())

    NM = dbusmock.get_object(MAIN_OBJ)
    settings_obj = dbusmock.get_object(SETTINGS_OBJ)
    main_connections = settings_obj.ListConnections()

    # Mimic how NM names connections
    count = 0
    while True:
        connection_obj_path = dbus.ObjectPath(SETTINGS_OBJ + '/' + str(count))
        if connection_obj_path not in main_connections:
            break
        count += 1
    connection_path = str(connection_obj_path)

    self.AddObject(connection_path,
                   CSETTINGS_IFACE,
                   {
                       'Unsaved': False
                   },
                   [
                       ('Delete', '', '', 'self.ConnectionDelete(self)'),
                       ('GetSettings', '', 'a{sa{sv}}', 'ret = self.ConnectionGetSettings(self)'),
                       ('GetSecrets', 's', 'a{sa{sv}}', 'ret = self.ConnectionGetSecrets(self, args[0])'),
                       ('Update', 'a{sa{sv}}', '', 'self.ConnectionUpdate(self, args[0])'),
                   ])

    connection_obj = dbusmock.get_object(connection_path)
    connection_obj.settings = connection_settings
    connection_obj.connection_path = connection_path
    connection_obj.ConnectionDelete = ConnectionDelete
    connection_obj.ConnectionGetSettings = ConnectionGetSettings
    connection_obj.ConnectionGetSecrets = ConnectionGetSecrets
    connection_obj.ConnectionUpdate = ConnectionUpdate

    main_connections.append(connection_path)
    settings_obj.Set(SETTINGS_IFACE, 'Connections', main_connections)

    settings_obj.EmitSignal(SETTINGS_IFACE, 'NewConnection', 'o', [connection_path])

    auto_connect = False
    if 'autoconnect' in connection_settings['connection']:
        auto_connect = connection_settings['connection']['autoconnect']

    if auto_connect:
        dev = None
        devices = NM.GetDevices()

        # Grab the first device.
        if len(devices) > 0:
            dev = devices[0]

        if dev:
            activate_connection(NM, connection_path, dev, connection_path)

    return connection_path
Exemplo n.º 28
0
def domain_path(vm: QubesVM) -> dbus.ObjectPath:
    ''' Return the D-Bus object path for a `qubes.vm.qubesvm.QubesVM` '''
    return dbus.ObjectPath('/org/qubes/DomainManager1/domains/' + str(vm.qid))
Exemplo n.º 29
0
 def get_path(self):
     return dbus.ObjectPath(self.path)
Exemplo n.º 30
0
 def MovePv(self):
     return dbus.ObjectPath(self._move_pv)