Skip to content

Commit 17b0b1a

Browse files
committed
Merge tag '1.0.1' into debian
Version 1.0.1
2 parents 4f56bee + 6f48743 commit 17b0b1a

5 files changed

Lines changed: 94 additions & 41 deletions

File tree

NetworkManager.py

Lines changed: 85 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ def wrap(self, val):
9696
if hasattr(val, 'items'):
9797
return dict([(x, self.wrap(y)) for x, y in val.items()])
9898
else:
99+
if (isinstance(val, dbus.Struct) or isinstance(val, dbus.ByteArray)):
100+
return val
99101
return [self.wrap(x) for x in val]
100102
return val
101103

@@ -149,11 +151,18 @@ def preprocess(self, name, args, kwargs):
149151
settings['802-11-wireless']['ssid'] = fixups.ssid_to_dbus(settings['802-11-wireless']['ssid'])
150152
if 'ipv4' in settings:
151153
if 'addresses' in settings['ipv4']:
152-
settings['ipv4']['addresses'] = [fixups.addrconf_to_dbus(addr) for addr in settings['ipv4']['addresses']]
154+
settings['ipv4']['addresses'] = [fixups.addrconf_to_dbus(addr,socket.AF_INET) for addr in settings['ipv4']['addresses']]
153155
if 'routes' in settings['ipv4']:
154-
settings['ipv4']['routes'] = [fixups.route_to_dbus(route) for route in settings['ipv4']['routes']]
156+
settings['ipv4']['routes'] = [fixups.route_to_dbus(route,socket.AF_INET) for route in settings['ipv4']['routes']]
155157
if 'dns' in settings['ipv4']:
156-
settings['ipv4']['dns'] = [fixups.addr_to_dbus(addr) for addr in settings['ipv4']['dns']]
158+
settings['ipv4']['dns'] = [fixups.addr_to_dbus(addr,socket.AF_INET) for addr in settings['ipv4']['dns']]
159+
if 'ipv6' in settings:
160+
if 'addresses' in settings['ipv6']:
161+
settings['ipv6']['addresses'] = [fixups.addrconf_to_dbus(addr,socket.AF_INET6) for addr in settings['ipv6']['addresses']]
162+
if 'routes' in settings['ipv6']:
163+
settings['ipv6']['routes'] = [fixups.route_to_dbus(route,socket.AF_INET6) for route in settings['ipv6']['routes']]
164+
if 'dns' in settings['ipv6']:
165+
settings['ipv6']['dns'] = [fixups.addr_to_dbus(addr,socket.AF_INET6) for addr in settings['ipv6']['dns']]
157166
return args, kwargs
158167
NetworkManager = NetworkManager()
159168

@@ -176,7 +185,10 @@ def GetSecrets(self, name=None):
176185
break
177186
else:
178187
return {}
179-
return self.make_proxy_call('GetSecrets')(name)
188+
try:
189+
return self.make_proxy_call('GetSecrets')(name)
190+
except:
191+
return {}
180192

181193
def postprocess(self, name, val):
182194
if name == 'GetSettings':
@@ -191,9 +203,13 @@ def postprocess(self, name, val):
191203
if 'bssid' in val_:
192204
val_['bssid'] = fixups.mac_to_python(val_['bssid'])
193205
if 'ipv4' in val:
194-
val['ipv4']['addresses'] = [fixups.addrconf_to_python(addr) for addr in val['ipv4']['addresses']]
195-
val['ipv4']['routes'] = [fixups.route_to_python(route) for route in val['ipv4']['routes']]
196-
val['ipv4']['dns'] = [fixups.addr_to_python(addr) for addr in val['ipv4']['dns']]
206+
val['ipv4']['addresses'] = [fixups.addrconf_to_python(addr,socket.AF_INET) for addr in val['ipv4']['addresses']]
207+
val['ipv4']['routes'] = [fixups.route_to_python(route,socket.AF_INET) for route in val['ipv4']['routes']]
208+
val['ipv4']['dns'] = [fixups.addr_to_python(addr,socket.AF_INET) for addr in val['ipv4']['dns']]
209+
if 'ipv6' in val:
210+
val['ipv6']['addresses'] = [fixups.addrconf_to_python(addr,socket.AF_INET6) for addr in val['ipv6']['addresses']]
211+
val['ipv6']['routes'] = [fixups.route_to_python(route,socket.AF_INET6) for route in val['ipv6']['routes']]
212+
val['ipv6']['dns'] = [fixups.addr_to_python(addr,socket.AF_INET6) for addr in val['ipv6']['dns']]
197213
return val
198214
preprocess = NetworkManager.preprocess
199215

@@ -216,11 +232,14 @@ def SpecificDevice(self):
216232
NM_DEVICE_TYPE_VLAN: Vlan,
217233
NM_DEVICE_TYPE_ADSL: Adsl,
218234
NM_DEVICE_TYPE_BRIDGE: Bridge,
235+
NM_DEVICE_TYPE_GENERIC: Generic
219236
}[self.DeviceType](self.object_path)
220237

221238
def postprocess(self, name, val):
222239
if name == 'Ip4Address':
223-
return fixups.addr_to_python(val)
240+
return fixups.addr_to_python(val,socket.AF_INET)
241+
if name == 'Ip6Address':
242+
return fixups.addr_to_python(val,socket.AF_INET6)
224243
return val
225244

226245
class AccessPoint(NMDbusInterface):
@@ -266,6 +285,9 @@ class Vlan(NMDbusInterface):
266285
class Adsl(NMDbusInterface):
267286
interface_name = 'org.freedesktop.NetworkManager.Device.adsl'
268287

288+
class Generic(NMDbusInterface):
289+
interface_name = 'org.freedesktop.NetworkManager.Device.Generic'
290+
269291
class NSP(NMDbusInterface):
270292
interface_name = 'org.freedesktop.NetworkManager.Wimax.NSP'
271293

@@ -274,16 +296,25 @@ class IP4Config(NMDbusInterface):
274296

275297
def postprocess(self, name, val):
276298
if name == 'Addresses':
277-
return [fixups.addrconf_to_python(addr) for addr in val]
299+
return [fixups.addrconf_to_python(addr,socket.AF_INET) for addr in val]
278300
if name == 'Routes':
279-
return [fixups.route_to_python(route) for route in val]
301+
return [fixups.route_to_python(route,socket.AF_INET) for route in val]
280302
if name in ('Nameservers', 'WinsServers'):
281-
return [fixups.addr_to_python(addr) for addr in val]
303+
return [fixups.addr_to_python(addr,socket.AF_INET) for addr in val]
282304
return val
283305

284306
class IP6Config(NMDbusInterface):
285307
interface_name = 'org.freedesktop.NetworkManager.IP6Config'
286308

309+
def postprocess(self, name, val):
310+
if name == 'Addresses':
311+
return [fixups.addrconf_to_python(addr,socket.AF_INET6) for addr in val]
312+
if name == 'Routes':
313+
return [fixups.route_to_python(route,socket.AF_INET6) for route in val]
314+
if name in ('Nameservers', 'WinsServers'):
315+
return [fixups.addr_to_python(addr,socket.AF_INET6) for addr in val]
316+
return val
317+
287318
class DHCP4Config(NMDbusInterface):
288319
interface_name = 'org.freedesktop.NetworkManager.DHCP4Config'
289320

@@ -301,9 +332,9 @@ class VPNConnection(NMDbusInterface):
301332

302333
def preprocess(self, name, args, kwargs):
303334
conf = args[0]
304-
conf['addresses'] = [fixups.addrconf_to_python(addr) for addr in conf['addresses']]
305-
conf['routes'] = [fixups.route_to_python(route) for route in conf['routes']]
306-
conf['dns'] = [fixups.addr_to_python(addr) for addr in conf['dns']]
335+
conf['addresses'] = [fixups.addrconf_to_python(addr,socket.AF_INET) for addr in conf['addresses']]
336+
conf['routes'] = [fixups.route_to_python(route,socket.AF_INET) for route in conf['routes']]
337+
conf['dns'] = [fixups.addr_to_python(addr,socket.AF_INET) for addr in conf['dns']]
307338
return args, kwargs
308339

309340
class VPNPlugin(NMDbusInterface):
@@ -345,52 +376,67 @@ def mac_to_dbus(mac):
345376
return [dbus.Byte(int(x, 16)) for x in mac.split(':')]
346377

347378
@staticmethod
348-
def addrconf_to_python(addrconf):
379+
def addrconf_to_python(addrconf,family):
349380
addr, netmask, gateway = addrconf
350381
return [
351-
fixups.addr_to_python(addr),
382+
fixups.addr_to_python(addr,family),
352383
netmask,
353-
fixups.addr_to_python(gateway)
384+
fixups.addr_to_python(gateway,family)
354385
]
355386

356387
@staticmethod
357-
def addrconf_to_dbus(addrconf):
388+
def addrconf_to_dbus(addrconf,family):
358389
addr, netmask, gateway = addrconf
359-
return [
360-
fixups.addr_to_dbus(addr),
361-
fixups.mask_to_dbus(netmask),
362-
fixups.addr_to_dbus(gateway)
363-
]
390+
if (family == socket.AF_INET):
391+
return [
392+
fixups.addr_to_dbus(addr,family),
393+
fixups.mask_to_dbus(netmask),
394+
fixups.addr_to_dbus(gateway,family)
395+
]
396+
else:
397+
return dbus.Struct(
398+
(
399+
fixups.addr_to_dbus(addr,family),
400+
fixups.mask_to_dbus(netmask),
401+
fixups.addr_to_dbus(gateway,family)
402+
), signature = 'ayuay'
403+
)
364404

365405
@staticmethod
366-
def addr_to_python(addr):
367-
return socket.inet_ntoa(struct.pack('I', addr))
406+
def addr_to_python(addr,family):
407+
if (family == socket.AF_INET):
408+
return socket.inet_ntop(family,struct.pack('I', addr))
409+
else:
410+
return socket.inet_ntop(family,b''.join(addr))
368411

369412
@staticmethod
370-
def addr_to_dbus(addr):
371-
return dbus.UInt32(struct.unpack('I', socket.inet_aton(addr))[0])
413+
def addr_to_dbus(addr,family):
414+
if (family == socket.AF_INET):
415+
return dbus.UInt32(struct.unpack('I', socket.inet_pton(family,addr))[0])
416+
else:
417+
return dbus.ByteArray(socket.inet_pton(family,addr))
372418

373419
@staticmethod
374420
def mask_to_dbus(mask):
375421
return dbus.UInt32(mask)
376422

377423
@staticmethod
378-
def route_to_python(route):
424+
def route_to_python(route,family):
379425
addr, netmask, gateway, metric = route
380426
return [
381-
fixups.addr_to_python(addr),
427+
fixups.addr_to_python(addr,family),
382428
netmask,
383-
fixups.addr_to_python(gateway),
429+
fixups.addr_to_python(gateway,family),
384430
socket.ntohl(metric)
385431
]
386432

387433
@staticmethod
388-
def route_to_dbus(route):
434+
def route_to_dbus(route,family):
389435
addr, netmask, gateway, metric = route
390436
return [
391-
fixups.addr_to_dbus(addr),
437+
fixups.addr_to_dbus(addr,family),
392438
fixups.mask_to_dbus(netmask),
393-
fixups.addr_to_dbus(gateway),
439+
fixups.addr_to_dbus(gateway,family),
394440
socket.htonl(metric)
395441
]
396442

@@ -437,7 +483,9 @@ def route_to_dbus(route):
437483
NM_WIFI_DEVICE_CAP_RSN = 32
438484
NM_WIFI_DEVICE_CAP_AP = 64
439485
NM_WIFI_DEVICE_CAP_ADHOC = 128
440-
NM_WIFI_DEVICE_CAP_IBSS_RSN = 256
486+
NM_WIFI_DEVICE_CAP_FREQ_VALID = 256
487+
NM_WIFI_DEVICE_CAP_FREQ_2GHZ = 512
488+
NM_WIFI_DEVICE_CAP_FREQ_5GHZ = 1024
441489
NM_802_11_AP_FLAGS_NONE = 0
442490
NM_802_11_AP_FLAGS_PRIVACY = 1
443491
NM_802_11_AP_SEC_NONE = 0
@@ -463,7 +511,6 @@ def route_to_dbus(route):
463511
NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO = 2
464512
NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS = 4
465513
NM_DEVICE_MODEM_CAPABILITY_LTE = 8
466-
NM_DEVICE_MODEM_CAPABILITY_OFONO = 16
467514
NM_DEVICE_STATE_UNKNOWN = 0
468515
NM_DEVICE_STATE_UNMANAGED = 10
469516
NM_DEVICE_STATE_UNAVAILABLE = 20
@@ -537,6 +584,9 @@ def route_to_dbus(route):
537584
NM_DEVICE_STATE_REASON_MODEM_FAILED = 57
538585
NM_DEVICE_STATE_REASON_MODEM_AVAILABLE = 58
539586
NM_DEVICE_STATE_REASON_SIM_PIN_INCORRECT = 59
587+
NM_DEVICE_STATE_REASON_NEW_ACTIVATION = 60
588+
NM_DEVICE_STATE_REASON_PARENT_CHANGED = 61
589+
NM_DEVICE_STATE_REASON_PARENT_MANAGED_CHANGED = 62
540590
NM_DEVICE_STATE_REASON_LAST = 65535
541591
NM_ACTIVE_CONNECTION_STATE_UNKNOWN = 0
542592
NM_ACTIVE_CONNECTION_STATE_ACTIVATING = 1

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
# built documents.
4949
#
5050
# The short X.Y version.
51-
version = '0.9'
51+
version = '1.0'
5252
# The full version, including alpha/beta/rc tags.
53-
release = '0.9.13'
53+
release = '1.0.1'
5454

5555
# The language for content autogenerated by Sphinx. Refer to documentation
5656
# for a list of supported languages.

docs/index.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ connections.
1414
The :mod:`NetworkManager` module
1515
--------------------------------
1616
.. module:: NetworkManager
17-
:platform: Linux systems with NetworkManager 0.9.x
17+
:platform: Linux systems with NetworkManager 0.9 and 1.0
1818
:synopsis: Talk to NetworkManager from python
1919

2020
All the code is contained in one module: :mod:`NetworkManager`. Using it is as
@@ -24,7 +24,7 @@ simple as you think it is:
2424
2525
>>> import NetworkManager
2626
>>> NetworkManager.NetworkManager.Version
27-
'0.9.6.0'
27+
'1.0.4'
2828
2929
NetworkManager exposes a lot of information via D-Bus and also allows full
3030
control of network settings. The full D-Bus API can be found on `NetworkManager
@@ -127,6 +127,8 @@ interface.
127127

128128
.. class:: Adsl
129129

130+
.. class:: Generic
131+
130132
These classes represent D-Bus interfaces for various types of hardware. Note
131133
that methods such as :data:`NetworkManager.GetDevices()` will only return
132134
:class:`Device` instances. To get the hardware-specific class, you can call the

examples/connection_detail.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
if conn.Devices:
2121
devices = " (on %s)" % ", ".join([x.Interface for x in conn.Devices])
2222
print("Active connection: %s%s" % (settings['connection']['id'], devices))
23-
size = max([max([len(y) for y in x.keys()]) for x in settings.values()])
23+
size = max([max([len(y) for y in x.keys() + ['']]) for x in settings.values()])
2424
format = " %%-%ds %%s" % (size + 5)
2525
for key, val in sorted(settings.items()):
2626
print(" %s" % key)

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from distutils.core import setup
44

55
setup(name = "python-networkmanager",
6-
version = "0.9.13",
6+
version = "1.0.1",
77
author = "Dennis Kaarsemaker",
88
author_email = "dennis@kaarsemaker.net",
99
url = "http://github.com/seveas/python-networkmanager",
@@ -16,6 +16,7 @@
1616
'License :: OSI Approved :: GNU General Public License (GPL)',
1717
'Operating System :: POSIX :: Linux',
1818
'Programming Language :: Python',
19+
'Programming Language :: Python :: 3',
1920
'Topic :: System :: Networking',
2021
]
2122
)

0 commit comments

Comments
 (0)