summaryrefslogtreecommitdiff
path: root/examples/python
Commit message (Collapse)AuthorAgeFilesLines
* examples: fix tracking destruction in destroy_nmc()Thomas Haller2022-07-131-3/+3
| | | | | | | | | | While iterating the context (once), multiple sources can be dispatched. So if we get a timeout and shortly after the weak-ref callback, then we still need to honor the weak-ref. In particular, because weak_ref.unref() is not safe to do after the object was already destroyed. So we need to be correct about tracking destruction.
* example: add python example for libnm, NMClient, GMainContext and asyncThomas Haller2022-07-051-0/+448
| | | | https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1290
* feat: add example for wifi sae connectionliaohanqin2022-06-161-0/+36
| | | | https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1247
* examples: improve finding last checkpoint in "checkpoint.py"Thomas Haller2022-05-021-5/+5
| | | | | This is a python example. We should do nice things, like using max() for finding the maximum, instead of sorting.
* examples: add "--last" argument to "examples/python/gi/checkpoint.py"Thomas Haller2022-02-231-44/+73
| | | | | | | | | | | | | "examples/python/gi/checkpoint.py" is not only an example. It's also a useful script for testing checkpoints. Support a "--last" argument to specify the last checkpoint created. Otherwise, when you are using this example from a test script, it can be cumbersome to find the right checkpoint point. Also, rename "client" and "nm_client" variables to "nmc". The purpose of using the same variable name for the same thing is readability, but also it works better when copy+paste snippets into the Python REPL.
* examples/python: avoid Python2 "print" statementThomas Haller2022-02-143-22/+28
| | | | | Recent python-black (22.0) dropped support for Python 2 and thus fail for those files. Make the examples Python3 compatible.
* docs: update URL for latest online documentationThomas Haller2021-09-248-8/+8
|
* examples: rework nm-up-many.py for ratelimiting parallel activationsThomas Haller2021-06-221-174/+147
| | | | | | | | | | | | | | | | The previous implementation did some ratelimiting, namely how many parallel ActivateConnection D-Bus calls are in fly. This way we are able to kick off many parallel calls, but the activations themselves were not ratelimited. Rework the code. Now there are two rate limits (that can be set via environment variables): NUM_PARALLEL_STARTING NUM_PARALLEL_IN_PROGRESS This allows more control about how much is happening in parallel. If we are going to activate 1000 profiles, then it matters that we do things in parallel, but not everything at the same time.
* example: drop unused import from "nm-up-many.py"Thomas Haller2021-06-171-2/+1
| | | | lgtm.com complains about this. Avoid the warning.
* examples: add "examples/python/gi/nm-up-many.py"Thomas Haller2021-06-111-0/+373
| | | | | | | | | | | | | | | | | | | It's an example for how to use libnm and asynchronous API. But it's also a script I will use to test activating many profiles in parallel. Also add a test script that creates many veth interfaces and connection profiles. So now you can do: sudo NUM_DEVS=100 contrib/scripts/test-create-many-device-setup.sh setup ./examples/python/gi/nm-up-many.py c-a{1..100} and cleanup with nmcli connection down c-a{1..100} sudo contrib/scripts/test-create-many-device-setup.sh cleanup Of course, be careful to do this on your production machine.
* examples/trivial: fix black formatting of python codeThomas Haller2021-05-271-1/+3
|
* examples: explicitly catch "Exception" in "ovs-external-ids.py"Thomas Haller2021-05-271-1/+1
| | | | | lgtm.com warns about unqualified "except". This catches any "BaseException", when we really only should handle "Exception" here.
* examples: fix printing applied connection in "ovs-external-ids.py"Thomas Haller2021-05-271-1/+1
| | | | | lgtm.com also complained about "connection_after" being unused. This hopefully works around that warning.
* examples: drop unused variable in "examples/python/gi/ovs-external-ids.py"Thomas Haller2021-05-271-1/+0
|
* python: remove unused importsThomas Haller2021-05-271-1/+2
| | | | | They are flagged by lgtm.com. Avoid the warning by dropping unused includes.
* examples: drop confusing UID handling in "vpn.py" exampleThomas Haller2021-05-271-8/+0
| | | | | | | | | | | | | | | | First of all, the "os.setuid()" call is never reached. lgtm.com warns about that, and warnings are annoying because they require investigation. This code is only in the example, so that the user would understand that they should edit the source and set the desired UID. But you can only call setuid() if you have CAP_SETUID, so commonly this anyway doesn't work -- unless you are root already, and then you actually don't need it either. Let's drop this code from the example. Maybe this example really should be dropped. Does the "dbus" python module even still work? Doesn't for me...
* examples: fix usage of input() with Python2Thomas Haller2021-05-261-0/+6
| | | | | | | | | | | | input() in Python2 evaluated the string and was thus unsafe. On Python2, the right choice is raw_input. In Python3, input does what raw_input did. Work around this. The main "problem" is that lgtm.com flags this as error. The fix in the example is not important, but getting a low number of warnings is.
* examples: avoid deprecated PropertiesChanged signal in "create-bond.py" exampleThomas Haller2021-05-141-7/+11
|
* examples: use python3 compatible exception syntaxJagadeesh Kotra2021-03-161-1/+1
| | | | https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/781
* examples/python: some style update to avoid changes in black code formattingThomas Haller2021-01-281-2/+2
| | | | | | | | | | | | Fedora 33's version of python-black is the authoritative version we use for formatting -- note that formatting may look different depending on the black version. Recently, the package was updated to 20.8~b1-1.fc33, which treats these lines different. Work around that by adjusting the code so that both older and current versions of python black behave the same.
* examples: minor bugfix comparing device state in "python/dbus/show-bssids.py"Thomas Haller2021-01-261-1/+1
|
* examples: add comment about scanning to "python/dbus/show-bssids.py" exampleThomas Haller2021-01-181-0/+5
| | | | https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/630
* all: update deprecated SPDX license identifiersThomas Haller2021-01-0541-41/+41
| | | | | | | | | | | | | | | | These SPDX license identifiers are deprecated ([1]). Update them. [1] https://spdx.org/licenses/ sed \ -e '1 s%^/\* SPDX-License-Identifier: \(GPL-2.0\|LGPL-2.1\)+ \*/$%/* SPDX-License-Identifier: \1-or-later */%' \ -e '1,2 s%^\(--\|#\|//\) SPDX-License-Identifier: \(GPL-2.0\|LGPL-2.1\)+$%\1 SPDX-License-Identifier: \2-or-later%' \ -i \ $(git grep -l SPDX-License-Identifier -- \ ':(exclude)shared/c-*/' \ ':(exclude)shared/n-*/' \ ':(exclude)shared/systemd/src' \ ':(exclude)src/systemd/src')
* examples: remove editor hint to mark source code as UTF-8Thomas Haller2021-01-051-1/+0
| | | | All our source code is UTF-8. We don't need to mark it as such.
* examples: extend "ovs-external-ids.py" to support `nmcli device modify`Thomas Haller2020-11-171-67/+305
| | | | | | The python example is (also) used to test the feature. That is because currently nmcli does not yet have support for ovs.external-ids and this API is only accessible via D-Bus (or a tool like this example).
* examples: add "ovs-external-ids.py" example scriptThomas Haller2020-11-091-0/+425
| | | | | | | | | | | | | And example script for getting and setting OVS external-ids. Since currently there is no nmcli support for these properties yet, the script becomes more interesting. This "example" is rather long, and it showcases less the usage of libnm (which is rather trivial, with respect to configuring NMSettingOvsExternalIDs). Instead, it aims to provide a useful command line tool for debugging. Hence, it's mostly concerned with an elaborate command line syntax and useful print output.
* Correct python black rulesFrederic Martinsons2020-10-291-2/+2
| | | | Signed-off-by: Frederic Martinsons <frederic.martinsons@sigfox.com>
* example: add python gi example for keyfile handlingth/keyfile-public-apiThomas Haller2020-10-281-0/+139
|
* all: changes from python 2 syntax to python3 and removing dead codeSayed Shah2020-08-0315-120/+70
| | | | | | | There were python 2 methods that are not used anymore so now it's in python 3. Added helper fuctions so that the code is more clear https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/540
* examples: run python black on "examples/python/gi/nm-wg-set"Thomas Haller2020-07-021-94/+185
| | | | black by default only considers files that have a ".py" extension.
* all: reformat python files with python blackSayed Shah2020-06-1538-648/+933
| | | | | | Part of !537. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/537
* examples: remove unused code from "examples/python/dbus/vpn.py"Thomas Haller2020-05-071-1/+0
| | | | | lgtm.com says "The value assigned to local variable all_connections is never used". Just drop the entire statement. It's not right there.
* examples: avoid "x == None" checks in python examplesThomas Haller2020-05-072-2/+2
| | | | lgmt.com says "Testing for None should use the is operator".
* examples: avoid "except" for BaseException in examplesThomas Haller2020-05-072-2/+2
| | | | lgtm.com flags this as "Except block directly handles BaseException".
* examples: remove unused imports from python examplesThomas Haller2020-05-0712-13/+7
|
* examples: remove unused assignment in "examples/python/gi/wifi-p2p.py"Thomas Haller2020-05-071-1/+1
| | | | lgtm.com warns about this.
* examples: add Wi-Fi P2P exampleBeniamino Galvani2020-04-271-0/+109
| | | | | Add a python example using GObject introspection that shows how to scan for Wi-Fi P2P peers and connect to one of them.
* examples: fix copy/paste comment error from another scriptDavid Drinn2020-04-111-1/+1
| | | | https://github.com/NetworkManager/NetworkManager/pull/361
* libnm: export interface flagsBeniamino Galvani2019-11-221-0/+19
| | | | Add libnm support for the new InterfaceFlags property of NMDevice.
* all: unify format of our Copyright source code commentsThomas Haller2019-10-0213-13/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ```bash readarray -d '' FILES < <( git ls-files -z \ ':(exclude)po' \ ':(exclude)shared/c-rbtree' \ ':(exclude)shared/c-list' \ ':(exclude)shared/c-siphash' \ ':(exclude)shared/c-stdaux' \ ':(exclude)shared/n-acd' \ ':(exclude)shared/n-dhcp4' \ ':(exclude)src/systemd/src' \ ':(exclude)shared/systemd/src' \ ':(exclude)m4' \ ':(exclude)COPYING*' ) sed \ -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) *[-–] *\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C1pyright#\5 - \7#\9/' \ -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) *[,] *\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C2pyright#\5, \7#\9/' \ -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C3pyright#\5#\7/' \ -e 's/^Copyright \(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/C4pyright#\1#\3/' \ -i \ "${FILES[@]}" echo ">>> untouched Copyright lines" git grep Copyright "${FILES[@]}" echo ">>> Copyright lines with unusual extra" git grep '\<C[0-9]pyright#' "${FILES[@]}" | grep -i reserved sed \ -e 's/\<C[0-9]pyright#\([^#]*\)#\(.*\)$/Copyright (C) \1 \2/' \ -i \ "${FILES[@]}" ``` https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/298
* all: manually drop code comments with file descriptionThomas Haller2019-10-0111-10/+5
|
* all: SPDX header conversionLubomir Rintel2019-09-1037-512/+37
| | | | | $ find * -type f |xargs perl contrib/scripts/spdx.pl $ git rm contrib/scripts/spdx.pl
* examples: improve usage/synposis for nm-update2.py and nm-add-connection2.pyThomas Haller2019-08-082-4/+14
|
* example: print WireGuard parameters in nm-wg-set example scriptThomas Haller2019-07-311-0/+12
| | | | (cherry picked from commit e966f4b272331fcf99914ee2c1a980074a01ed94)
* examples: add examples/python/gi/nm-update2.py example scriptThomas Haller2019-07-251-0/+155
| | | | This is useful for manually testing Update2() D-Bus API.
* examples: add examples/python/gi/nm-add-connection2.py example scriptth/settings-add2-and-update2-optionsThomas Haller2019-07-251-0/+156
| | | | This is useful for manually testing AddConnection2() D-Bus API.
* all: drop vim file variables from source filesThomas Haller2019-06-1116-16/+0
| | | | sed '1,3 { /^\(#\|--\) *vim:/d }; 1 { /^\/\* *vim:.*\*\/$/ d}' -i $(git grep -l 'vim:')
* all: drop emacs file variables from source filesThomas Haller2019-06-1122-22/+0
| | | | | | | | | | | | | | | | | | | | | | We no longer add these. If you use Emacs, configure it yourself. Also, due to our "smart-tab" usage the editor anyway does a subpar job handling our tabs. However, on the upside every user can choose whatever tab-width he/she prefers. If "smart-tabs" are used properly (like we do), every tab-width will work. No manual changes, just ran commands: F=($(git grep -l -e '-\*-')) sed '1 { /\/\* *-\*- *[mM]ode.*\*\/$/d }' -i "${F[@]}" sed '1,4 { /^\(#\|--\|dnl\) *-\*- [mM]ode/d }' -i "${F[@]}" Check remaining lines with: git grep -e '-\*-' The ultimate purpose of this is to cleanup our files and eventually use SPDX license identifiers. For that, first get rid of the boilerplate lines.
* all: codespell fixesLubomir Rintel2019-03-111-1/+1
| | | | | | | Codespel run with the same arguments as described in commit 58510ed56679 ('docs: misc. typos pt2'). (cherry picked from commit bf0c4e6ac2855088e3962693886bb6ab71856f7b)
* libnm: change nm_wireguard_peer_set_endpoint() API to allow validationThomas Haller2019-03-071-1/+1
| | | | | | | | This is an API break since 1.16-rc1. Similar to previous commit. (cherry picked from commit 8ae9aa2428c10aafb837c692fb39bfd04ef4235c)