Provisionally implement -n as -a.
[cnetworkmanager.git] / networkmanager / networkmanager.py
blobe444dea616ea5390efe32006d19d33894ee6828d
1 # -*- coding: utf-8 -*-
3 import dbus
4 from dbusclient import DBusClient, object_path
5 from device import Device
6 from activeconnection import ActiveConnection
7 from util import Enum
8 from func import *
10 # need better/shorter names? or hide them?
11 SYSTEM_SERVICE = "org.freedesktop.NetworkManagerSystemSettings"
12 USER_SERVICE = "org.freedesktop.NetworkManagerUserSettings"
14 # gratuitous convertor to test writable properties
15 def english_to_bool(v):
16 if v == "yes":
17 return True
18 elif v == "no":
19 return False
20 return v
22 class NetworkManager(DBusClient):
23 """networkmanager
25 The NM client library
27 Methods:
28 GetDevices ( ) → ao
29 ActivateConnection ( s: service_name, o: connection, o: device, o: specific_object ) → o
30 DeactivateConnection ( o: active_connection ) → nothing
31 Sleep ( b: sleep ) → nothing
33 Signals:
34 StateChanged ( u: state )
35 PropertiesChanged ( a{sv}: properties )
36 DeviceAdded ( o: device_path )
37 DeviceRemoved ( o: device_path )
39 Properties:
40 WirelessEnabled - b - (readwrite)
41 WirelessHardwareEnabled - b - (read)
42 ActiveConnections - ao - (read)
43 State - u - (read) (NM_STATE)
45 Enumerated types:
46 NM_STATE
47 """
49 SERVICE = "org.freedesktop.NetworkManager"
50 OPATH = "/org/freedesktop/NetworkManager"
51 IFACE = "org.freedesktop.NetworkManager"
53 def __init__(self):
54 super(NetworkManager, self).__init__(dbus.SystemBus(), self.SERVICE, self.OPATH, default_interface=self.IFACE)
57 class State(Enum):
58 UNKNOWN = 0
59 ASLEEP = 1
60 CONNECTING = 2
61 CONNECTED = 3
62 DISCONNECTED = 4
64 "TODO find a good term for 'adaptor'"
65 NetworkManager._add_adaptors(
66 methods = {
67 "GetDevices": seq_adaptor(Device._create),
68 "ActivateConnection": [ActiveConnection, [identity, object_path, object_path, object_path]],
69 "DeactivateConnection": [void, [object_path]],
71 properties = {
72 "State": NetworkManager.State,
73 "WirelessEnabled": [bool, english_to_bool],
74 "WirelessHardwareEnabled": bool,
75 "ActiveConnections": seq_adaptor(ActiveConnection),
77 signals = {
78 "StateChanged": [void, [NetworkManager.State]],