Skip to content

Commit 9fc5872

Browse files
committed
Documentation rework
1 parent 2cc46f3 commit 9fc5872

File tree

7 files changed

+103
-51
lines changed

7 files changed

+103
-51
lines changed

HACKING

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,7 @@ Source preparation:
99

1010
Packaging:
1111
- ./setup.py sdist
12-
- dpkg-buildpackage -rfakeroot
13-
- Upload tarballs and packages to kaarsemaker.net
14-
15-
pypi:
16-
- dh clean
17-
- cd docs/_build/html
18-
- rm -f docs.zip && zip -r docs.zip *
19-
- Upload docs.zip to pypi
12+
- debuild -S
13+
- Push to PPA
2014
- ./setup.py register
15+
- Regen gh-pages branch and push

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ include docs/index.rst
22
include docs/Makefile
33
include docs/conf.py
44
include examples/*
5+
include COPYING

NetworkManager.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# NetworkManager - a library to make interacting with the NetworkManager daemon
2+
# easier.
3+
#
4+
# (C)2011-2013 Dennis Kaarsemaker
5+
# License: GPL3+
6+
17
import dbus
28
import socket
39
import struct
@@ -160,7 +166,6 @@ def GetSecrets(self, name=None):
160166
return self.make_proxy_call('GetSecrets')(name)
161167

162168
def postprocess(self, name, val):
163-
# SSID is sent as bytes, make it a string
164169
if name == 'GetSettings':
165170
if 'ssid' in val.get('802-11-wireless', {}):
166171
val['802-11-wireless']['ssid'] = fixups.ssid_to_python(val['802-11-wireless']['ssid'])
@@ -201,7 +206,6 @@ class AccessPoint(NMDbusInterface):
201206
interface_name = 'org.freedesktop.NetworkManager.AccessPoint'
202207

203208
def postprocess(self, name, val):
204-
# SSID is sent as bytes, make it a string
205209
if name == 'Ssid':
206210
return fixups.ssid_to_python(val)
207211

@@ -290,6 +294,9 @@ def const(prefix, val):
290294
return key.replace(prefix,'').lower()
291295
raise ValueError("No constant found for %s* with value %d", (prefix, val))
292296

297+
# Several fixer methods to make the data easier to handle in python
298+
# - SSID sent/returned as bytes (only encoding tried is utf-8)
299+
# - IP, Mac address and route metric encoding/decoding
293300
class fixups(object):
294301
@staticmethod
295302
def ssid_to_python(ssid):

README

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ calls are forwarded to the correct interface.
99
See docs/index.rst for the documentation. An HTML version can be found on
1010
http://packages.python.org/python-networkmanager/
1111

12+
Requirements
13+
============
14+
Python 2.5 or newer (Python 3 is supported as well) and the python D-Bus
15+
bindings.
16+
1217
Quick install instructions
1318
==========================
1419

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
# General information about the project.
4343
project = u'python-networkmanager'
44-
copyright = u'2011-2012, Dennis Kaarsemaker'
44+
copyright = u'2011-2013, Dennis Kaarsemaker'
4545

4646
# The version info for the project you're documenting, acts as replacement for
4747
# |version| and |release|, also used in various other places throughout the
@@ -50,7 +50,7 @@
5050
# The short X.Y version.
5151
version = '0.9'
5252
# The full version, including alpha/beta/rc tags.
53-
release = '0.9.5'
53+
release = '0.9.6'
5454

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

docs/index.rst

Lines changed: 76 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1-
Welcome to python-networkmanager's documentation!
2-
=================================================
1+
Python API to talk to NetworkManager
2+
====================================
33

4-
python-networkmanager wraps NetworkManagers D-Bus interface so you can be less
5-
verbose when talking to NetworkManager from python. All interfaces have been
6-
wrapped in classes, properties are exposed as python properties and function
7-
calls are forwarded to the correct interface.
4+
NetworkManager provides a detailed and capable D-Bus interface on the system
5+
bus. You can use this interface to query NetworkManager about the overall state
6+
of the network and details of network devices like current IP addresses or DHCP
7+
options, and to activate and deactivate network connections.
88

9-
I wrote it to reduce a 100-line python script to 50 lines. Not realizing that
10-
the library has more lines than the ones I removed. Oh well 😊
9+
python-networkmanager takes this D-Bus interface and wraps D-Bus interfaces in
10+
classes and D-Bus properties in python properties. It also provides a
11+
command-line utility to inspect the configuration and (de-)activate
12+
connections.
1113

12-
As of version 0.9.2, python-networkmanager also ships a command-line utility
13-
called n-m, which allows you to manipulate NetworkManager's state from the
14-
command line.
15-
16-
:mod:`NetworkManager` -- Easy communication with NetworkManager
17-
---------------------------------------------------------------
14+
The :mod:`NetworkManager` module
15+
--------------------------------
1816
.. module:: NetworkManager
19-
:platform: Linux systems with NetworkManager 0.90
20-
:synopsis: Talk to NetworkManager without being verbose
17+
:platform: Linux systems with NetworkManager 0.9.x
18+
:synopsis: Talk to NetworkManager from python
2119

2220
All the code is contained in one module: :mod:`NetworkManager`. Using it is as
2321
simple as you think it is:
@@ -26,20 +24,33 @@ simple as you think it is:
2624
2725
>>> import NetworkManager
2826
>>> NetworkManager.NetworkManager.Version
29-
'0.9.1.90'
27+
'0.9.6.0'
3028
3129
NetworkManager exposes a lot of information via D-Bus and also allows full
3230
control of network settings. The full D-Bus API can be found on `NetworkManager
3331
project website`_. All interfaces listed there have been wrapped in classes as
34-
listed below.
32+
listed below. With a few exceptions, they behave exactly like the D-Bus
33+
methods. These exceptions are for convenience and limited to this list:
34+
35+
* IP addresses are returned as strings of the form :data:`1.2.3.4` instead of
36+
network byte ordered integers.
37+
* Route metrics are returned in host byte order, so you can use them as
38+
integers.
39+
* Mac addresses and BSSIDs are always returned as strings of the form
40+
:data:`00:11:22:33:44:55` instead of byte sequences.
41+
* Wireless SSID's are returned as strings instead of byte sequences. They will
42+
be decoded as UTF-8 data, so using any other encoding for your SSID will
43+
result in errors.
3544

3645
.. class:: NMDbusInterface
3746

3847
This is the base class for all interface wrappers. It adds a few useful
3948
features to standard D-Bus interfaces:
4049

4150
* All D-Bus properties are exposed as python properties
42-
* Return values are automatically unwrapped (so no more :data:`dbus.String`)
51+
* Return values are automatically converted to python basic types (so no more
52+
:data:`dbus.String`, but simple :data:`str` (python 3) or :data:`unicode`
53+
(python 2))
4354
* Object paths in return values are automatically replaced with proxy objects,
4455
so you don't need to do that manually
4556
* ...and vice versa when sending
@@ -48,7 +59,7 @@ features to standard D-Bus interfaces:
4859
.. function:: const(prefix, value)
4960

5061
Many of NetworkManagers D-Bus methods expect or return numeric constants, for
51-
which there are enums in teh C sourece code only. These constants, such as
62+
which there are enums in the C source code. These constants, such as
5263
:data:`NM_STATE_CONNECTED_GLOBAL`, can all be found in the
5364
:mod:`NetworkManager` module as well. The :func:`const` function can help you
5465
translate them to text. For example:
@@ -60,7 +71,7 @@ translate them to text. For example:
6071
>>> NetworkManager.const('device_type', 2)
6172
'wifi'
6273
63-
.. _`NetworkManager project website`: http://projects.gnome.org/NetworkManager/developers/migrating-to-09/spec.html
74+
.. _`NetworkManager project website`: projects.gnome.org/NetworkManager/developers/api/09/spec.html
6475

6576
List of classes
6677
---------------
@@ -102,9 +113,19 @@ interface.
102113

103114
.. class:: Bluetooth
104115

116+
.. class:: OlpcMesh
117+
105118
.. class:: Wimax
106119

107-
.. class:: OlpcMesh
120+
.. class:: Infiniband
121+
122+
.. class:: Bond
123+
124+
.. class:: Bridge
125+
126+
.. class:: Vlan
127+
128+
.. class:: Adsl
108129

109130
These classes represent D-Bus interfaces for various types of hardware. Note
110131
that methods such as :data:`NetworkManager.GetDevices()` will only return
@@ -118,30 +139,50 @@ that methods such as :data:`NetworkManager.GetDevices()` will only return
118139
[('eth0', 'Wired'), ('wlan0', 'Wireless'), ('wwan0', 'Modem')]
119140
120141
.. class:: IP4Config
142+
121143
.. class:: IP6Config
122144

145+
.. class:: DHCP4Config
146+
147+
.. class:: DHCP6Config
148+
123149
These classes represent the various IP configuration interfaces.
124150

151+
.. class:: AgentManager
152+
153+
.. class:: SecretAgent
154+
155+
Classes that can be used to handle and store secrets. Note that these are not
156+
for querying NetworkManager's exisiting secret stores. For that the
157+
:func:`GetSecrets` method of the :class:`Connection` class can be used.
158+
125159
.. class:: VPNConnection
126160

127161
This class represents the :data:`org.freedesktop.NetworkManager.VPN.Connection`
128162
interface.
129163

164+
.. class:: VPNPlugin
165+
166+
A class that can be used to query VPN plugins.
167+
130168
.. toctree::
131169
:maxdepth: 2
132170

133171
The n-m utility
134172
---------------
135-
n-m is a command-line tool to deal with network-manager. It can connect you to
136-
defined networks and disconnect you again.
137-
138-
Usage: [options] action [arguments]
139-
140-
Actions:
141-
list - List all defined and active connections
142-
activate - Activate a connection
143-
deactivate - Deactivate a connection
144-
offline - Deactivate all connections
145-
enable - Enable specific connection types
146-
disable - Disable specific connection types
147-
info - Information about a connection
173+
n-m is a command-line tool to interact with NetworkManager. With it, you can
174+
inspect various configuration items and (de-)activate connections.
175+
176+
Usage: [options] action [arguments]
177+
178+
Actions:
179+
list - List all defined and active connections
180+
activate - Activate a connection
181+
deactivate - Deactivate a connection
182+
offline - Deactivate all connections
183+
enable - Enable specific connection types
184+
disable - Disable specific connection types
185+
info - Information about a connection
186+
dump - Dump a python hash of connection information, suitable for
187+
creating new connections
188+

n-m

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#!/usr/bin/python
2-
"""
3-
n-m is a command-line tool to deal with network-manager. It can connect you to
4-
defined networks and disconnect you again.
5-
"""
2+
#
3+
# Command-line tool to interact with NetworkManager. With this tool, you can
4+
# inspect various configuration items and (de-)activate connections.
5+
#
6+
# (C) 2011-2013 Dennis Kaarsemaker
7+
# License: GPL3+
8+
69
from __future__ import print_function
710

811
usage = """%prog [options] action [arguments]

0 commit comments

Comments
 (0)