From The Compiler, 1 Month ago, written in Diff-output.
Embed
  1. diff --git i/networkmanager_dmenu w/networkmanager_dmenu
  2. index 33ba44b..064a116 100755
  3. --- i/networkmanager_dmenu
  4. +++ w/networkmanager_dmenu
  5. @@ -284,6 +284,34 @@ class Action():  # pylint: disable=too-few-public-methods
  6.              self.func(*self.args)
  7.  
  8.  
  9. +def conn_matches_adapter(conn, adapter):
  10. +    """Return True if the connection is applicable for the given adapter.
  11. +
  12. +    There seem to be two ways for a connection specify what interface it belongs
  13. +    to:
  14. +
  15. +    - By setting 'mac-address' in [wifi] to the adapter's MAC
  16. +    - By setting 'interface-name` in [connection] to the adapter's name.
  17. +
  18. +    Depending on how the connection was added, it seems like either
  19. +    'mac-address', 'interface-name' or neither of both is set.
  20. +    """
  21. +    # [wifi] mac-address
  22. +    setting_wireless = conn.get_setting_wireless()
  23. +    mac = setting_wireless.get_mac_address()
  24. +    if mac is not None:
  25. +        return mac == adapter.get_permanent_hw_address()
  26. +
  27. +    # [connection] interface-name
  28. +    setting_connection = conn.get_setting_connection()
  29. +    interface = setting_connection.get_interface_name()
  30. +    if interface is not None:
  31. +        return interface == adapter.get_iface()
  32. +
  33. +    # Neither is set, let's assume this connection is for multiple/all adapters.
  34. +    return True
  35. +
  36. +
  37.  def process_ap(nm_ap, is_active, adapter):
  38.      """Activate/Deactivate a connection and get password if required"""
  39.      if is_active:
  40. @@ -291,8 +319,7 @@ def process_ap(nm_ap, is_active, adapter):
  41.      else:
  42.          conns_cur = [i for i in CONNS if
  43.                       i.get_setting_wireless() is not None and
  44. -                     i.get_setting_wireless().get_mac_address() ==
  45. -                     adapter.get_permanent_hw_address()]
  46. +                     conn_matches_adapter(i, adapter)]
  47.          con = nm_ap.filter_connections(conns_cur)
  48.          if len(con) > 1:
  49.              raise ValueError("There are multiple connections possible")
  50.