Commit graph

151 commits

Author SHA1 Message Date
Thomas Haller 86e99fca6b
examples: avoid deprecated PropertiesChanged signal in "create-bond.py" example 2021-05-14 10:53:09 +02:00
Jagadeesh Kotra 3df607f3c2
examples: use python3 compatible exception syntax
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/781
2021-03-16 07:55:12 +01:00
Thomas Haller d446cde260
examples/python: some style update to avoid changes in black code formatting
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.
2021-01-28 10:25:25 +01:00
Thomas Haller c1529dab36
examples: minor bugfix comparing device state in "python/dbus/show-bssids.py" 2021-01-26 11:42:46 +01:00
Thomas Haller 6ce0c064ac
examples: add comment about scanning to "python/dbus/show-bssids.py" example
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/630
2021-01-18 13:26:12 +01:00
Thomas Haller 977ea352a0
all: update deprecated SPDX license identifiers
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')
2021-01-05 09:46:21 +01:00
Thomas Haller 4e49c417eb
examples: remove editor hint to mark source code as UTF-8
All our source code is UTF-8. We don't need to mark it as such.
2021-01-05 09:46:20 +01:00
Thomas Haller c45041f1fc
examples: extend "ovs-external-ids.py" to support nmcli device modify
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).
2020-11-17 19:49:03 +01:00
Thomas Haller 7e39e23f64
examples: add "ovs-external-ids.py" example script
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.
2020-11-09 17:53:15 +01:00
Frederic Martinsons 1f5c7f7d81
Correct python black rules
Signed-off-by: Frederic Martinsons <frederic.martinsons@sigfox.com>
2020-10-29 09:35:10 +01:00
Thomas Haller a9e6774670
example: add python gi example for keyfile handling 2020-10-28 14:30:49 +01:00
Sayed Shah 7baf615eaa
all: changes from python 2 syntax to python3 and removing dead code
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
2020-08-03 18:37:43 +02:00
Thomas Haller 1acd64b7a2
examples: run python black on "examples/python/gi/nm-wg-set"
black by default only considers files that have a ".py" extension.
2020-07-02 17:37:12 +02:00
Sayed Shah be822b52e6
all: reformat python files with python black
Part of !537.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/537
2020-06-15 16:40:38 +02:00
Thomas Haller 64331d6085
examples: remove unused code from "examples/python/dbus/vpn.py"
lgtm.com says "The value assigned to local variable all_connections is never used".
Just drop the entire statement. It's not right there.
2020-05-07 13:58:16 +02:00
Thomas Haller 8ad448444a
examples: avoid "x == None" checks in python examples
lgmt.com says "Testing for None should use the is operator".
2020-05-07 13:58:15 +02:00
Thomas Haller c7d0a86050
examples: avoid "except" for BaseException in examples
lgtm.com flags this as "Except block directly handles BaseException".
2020-05-07 13:58:14 +02:00
Thomas Haller 41a7a26259
examples: remove unused imports from python examples 2020-05-07 13:58:13 +02:00
Thomas Haller a5614dc469
examples: remove unused assignment in "examples/python/gi/wifi-p2p.py"
lgtm.com warns about this.
2020-05-07 13:58:12 +02:00
Beniamino Galvani 2c4d19c1dc examples: add Wi-Fi P2P example
Add a python example using GObject introspection that shows how to
scan for Wi-Fi P2P peers and connect to one of them.
2020-04-27 15:54:28 +02:00
David Drinn 4e73d71518 examples: fix copy/paste comment error from another script
https://github.com/NetworkManager/NetworkManager/pull/361
2020-04-11 15:38:46 +02:00
Beniamino Galvani e397582cca libnm: export interface flags
Add libnm support for the new InterfaceFlags property of NMDevice.
2019-11-22 10:18:26 +01:00
Thomas Haller 3b69f02164 all: unify format of our Copyright source code comments
```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
2019-10-02 17:03:52 +02:00
Thomas Haller abff46cacf all: manually drop code comments with file description 2019-10-01 07:50:52 +02:00
Lubomir Rintel 24028a2246 all: SPDX header conversion
$ find * -type f |xargs perl contrib/scripts/spdx.pl
  $ git rm contrib/scripts/spdx.pl
2019-09-10 11:19:56 +02:00
Thomas Haller 041a952297 examples: improve usage/synposis for nm-update2.py and nm-add-connection2.py 2019-08-08 10:53:03 +02:00
Thomas Haller 815acb9996 example: print WireGuard parameters in nm-wg-set example script
(cherry picked from commit e966f4b272)
2019-07-31 10:44:38 +02:00
Thomas Haller 10353a996f examples: add examples/python/gi/nm-update2.py example script
This is useful for manually testing Update2() D-Bus API.
2019-07-25 22:02:00 +02:00
Thomas Haller 360d26e27c examples: add examples/python/gi/nm-add-connection2.py example script
This is useful for manually testing AddConnection2() D-Bus API.
2019-07-25 15:26:49 +02:00
Thomas Haller 3c47285f4a all: drop vim file variables from source files
sed '1,3 { /^\(#\|--\) *vim:/d }; 1 { /^\/\* *vim:.*\*\/$/ d}' -i $(git grep -l 'vim:')
2019-06-11 10:08:07 +02:00
Thomas Haller c0e075c902 all: drop emacs file variables from source files
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.
2019-06-11 10:04:00 +02:00
Lubomir Rintel 4251f4e476 all: codespell fixes
Codespel run with the same arguments as described in
commit 58510ed566 ('docs: misc. typos pt2').

(cherry picked from commit bf0c4e6ac2)
2019-03-11 12:03:46 +01:00
Thomas Haller f617d5e8b4 libnm: change nm_wireguard_peer_set_endpoint() API to allow validation
This is an API break since 1.16-rc1.

Similar to previous commit.

(cherry picked from commit 8ae9aa2428)
2019-03-07 22:22:39 +01:00
Thomas Haller 6452d2d0e5 libnm: change nm_wireguard_peer_set_public_key() API to allow validation
This is an API break since 1.16-rc1.

Similar to previous commit.

(cherry picked from commit 7962653918)
2019-03-07 22:22:39 +01:00
Thomas Haller 7682826229 libnm: change nm_wireguard_peer_set_preshared_key() API to allow validation
This is an API break since 1.16-rc1.

The functions like _nm_utils_wireguard_decode_key() are internal API
and not accessible to a libnm user. Maybe this should be public API,
but for now it is not.

That makes it cumbersome for a client to validate the setting. The client
could only reimplement the validation (bad) or go ahead and set invalid
value.

When setting an invalid value, the user can afterwards detect it via
nm_wireguard_peer_is_valid(), but at that point, it's not clear which
exact property is invalid.

First I wanted to keep the API conservative and not promissing too much.
For example, not promising to do any validation when setting the key.
However, libnm indeed validates the key at the time of setting it
instead of doing lazy validation later. This makes sense, so we can
keep this promise and just expose the validation result to the caller.

Another downside of this is that the API just got more complicated.
But it not provides a validation API, that we previously did not have.

(cherry picked from commit d7bc1750c1)
2019-03-07 22:22:39 +01:00
Thomas Haller 4c8ff6f220 examples: fix handling secrets in nm-wg-set
When setting any secrets via D-Bus' Update2 call, then
it assumes that all settings are reset. That means, when
we modify any secrets in the client, we need to first load
them all.

Anyway, load always all secrets, then we can also print them
in the get output.

Honor WG_HIDE_KEYS like `wg` does.

(cherry picked from commit 6aa9e52bd8)
2019-02-26 09:40:57 +01:00
Thomas Haller 8b4247d31d examples: improve hints about existing WireGuard profiles in nm-wg-set
(cherry picked from commit b5a458c5ff)
2019-02-26 09:40:56 +01:00
Thomas Haller debd022a6d examples: add python example script "nm-wg-set" for modifying WireGuard profile
Use the script to test how GObject introspection with libnm's WireGuard
support works.

Also, since support for WireGuard peers is not yet implemented in nmcli
(or other clients), this script is rather useful.
2019-02-22 11:00:11 +01:00
Lubomir Rintel b385ad0159 all: say Wi-Fi instead of "wifi" or "WiFi"
Correct the spelling across the *entire* tree, including translations,
comments, etc. It's easier that way.

Even the places where it's not exposed to the user, such as tests, so
that we learn how is it spelled correctly.
2018-11-29 17:53:35 +01:00
luz.paz f985b6944a docs: misc. typos
Found via `codespell -q 3 --skip="*.po"`

https://github.com/NetworkManager/NetworkManager/pull/203
2018-09-15 09:08:03 +02:00
Lubomir Rintel 59ccf5dc89 examples/python: drop nmex.py
It's not an example and not actually used.

https://github.com/NetworkManager/NetworkManager/pull/141
2018-06-29 20:05:39 +02:00
Lubomir Rintel 1b6127d1bc examples/python: utilize nm_utils_get_timestamp_msec() 2018-06-15 16:23:30 +02:00
Lubomir Rintel 9c0db98094 Revert "example/python: avoid falling back to CLOCK_MONOTONIC"
This breaks client tests on avery old kernel (2.6.32, RHEL 6).

  Traceback (most recent call last):
    File "./clients/tests/test-client.py", line 699, in setUp
      self.srv = NMStubServer(self._testMethodName)
    File "./clients/tests/test-client.py", line 309, in __init__
      start = nmex.nm_boot_time_ns()
    File "/builddir/build/BUILD/NetworkManager-1.11.4/examples/python/nmex.py", line 54, in nm_boot_time_ns
      return sys_clock_gettime_ns(CLOCK_BOOTTIME)
    File "/builddir/build/BUILD/NetworkManager-1.11.4/examples/python/nmex.py", line 50, in sys_clock_gettime_ns
      return _sys_clock_gettime_ns(clock_id)
    File "/builddir/build/BUILD/NetworkManager-1.11.4/examples/python/nmex.py", line 39, in f
      raise OSError(errno_, os.strerror(errno_))
  OSError: [Errno 22] Invalid argument

This reverts commit 119e828dbe.
2018-06-15 08:36:22 +02:00
Lubomir Rintel 119e828dbe example/python: avoid falling back to CLOCK_MONOTONIC
According to the D-Bus API specification we return CLOCK_BOOTTIME only.
We don't support kernels too old to have it -- the fall back to
CLOCK_MONOTONIC is only there to be able to run unit tests on RHEL 6
kernel and will eventually go away.
2018-06-14 17:30:06 +02:00
Thomas Haller 735dc41bd0 libnm: rework checkpoint API
The libnm API fir checkpoints was only introduced with 1.11. It
is not yet stable, so there is still time to adjust it. Note that
this changes API/ABI of the development branch.

Changes:

- we only add async variants of the checkpoint functions. I believe
  that synchronous D-Bus methods are fundamentally flawed, because
  they mess up the ordering of events.
  Rename the async functions by removing the "_async" suffix. This
  matches glib style, for which the async form is also not specially
  marked.

- for function that refere to a particular checkpoint (rollback and
  destroy), accept the D-Bus path as string, instead of an NMCheckpoint
  instance. This form is more flexible, because it allows to use
  the function without having a NMCheckpoint instance at hand. On the
  other hand, if one has a NMCheckpoint instance, he can trivially
  obtain the path to make the call.
2018-04-04 14:02:13 +02:00
Thomas Haller 2a30bef856 examples: improve checkpoint.py for python/gi
- make python2 and python3 compatible
- support Checkpoint create flags (requires recent libnm for GI
  of flags)
- support adjust-rollback-timeout command
- print elapsed time in show output
2018-04-04 14:02:13 +02:00
Thomas Haller d14b9b8215 examples: add python utils for examples
We need common operations from the python scripts.
For example, to print the boot-time.

Move such utils to a separate nmex.py file ("ex" for
example). This file should contain helper functions that
are pure python (or, if the have requirements, load them
only on demand, so that examples that need those have
additional dependencies). It should also be simple to extract
individual helpers from nmex, so that the user can take an
example, merge parts of nmex.py in, and modify it to his needs.
2018-04-04 14:02:13 +02:00
Thomas Haller ab8312a18e checkpoint: generate GIR information for NMCheckpointCreateFlags
Note that this changes API for checkpoint_create_async() in Python
via GIR. Previously it would require an integer argument, now a flags
argument. But this API is still unstable, it will be introduced with
1.12.
2018-04-04 14:02:13 +02:00
Thomas Haller 28da0154fc all: drop trailing spaces 2018-02-07 13:32:04 +01:00
Thomas Haller e4839accf5 all: replace non-leading tabs with spaces
We commonly only allow tabs at the beginning of a line, not
afterwards. The reason for this style is so that the code
looks formated right with tabstop=4 and tabstop=8.
2018-02-07 13:32:04 +01:00