Commit graph

285 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
Thomas Haller ca607d2eff
example: rework "vpn-import-libnm" example
- add more error handling and free/unref data.

- split code in 3 functions: vpn_connection_import(),
  connection_add() and main(). These steps are mostly
  independent, and having them in separate functions
  makes their separation clearer.

- handle error from nm_client_add_connection_async() to
  exit program with non zero exit code.
2021-04-01 21:16:01 +02:00
Thomas Haller 3348901df3
examples: fix exit from "vpn-import-libnm.c" example
../examples/C/glib/vpn-import-libnm.c: In function main:
  ../examples/C/glib/vpn-import-libnm.c:72:1: error: control reaches end of non-void function [-Werror=return-type]
   }
   ^

Fixes: 905f9975d2 ('example: importing vpn with libnm')
2021-03-22 16:29:14 +01:00
Jagadeesh Kotra 905f9975d2
example: importing vpn with libnm
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/789
2021-03-22 15:54:07 +01: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 4c98a45270
build/meson: drop libnm_nm_default_dep dependency 2021-02-28 10:42:06 +01:00
Thomas Haller 9bba4871f3
build: move "libnm/" to "src/" and split it
Like with "libnm-core/", split "libnm/" into different directories for
the public headers, for the implementation and for the helper "aux"
library.
2021-02-24 12:48:37 +01:00
Thomas Haller fdf9614ba7
build: move "libnm-core/" to "src/" and split it
"libnm-core/" is rather complicated. It provides a static library that
is linked into libnm.so and NetworkManager. It also contains public
headers (like "nm-setting.h") which are part of public libnm API.

Then we have helper libraries ("libnm-core/nm-libnm-core-*/") which
only rely on public API of libnm-core, but are themself static
libraries that can be used by anybody who uses libnm-core. And
"libnm-core/nm-libnm-core-intern" is used by libnm-core itself.

Move "libnm-core/" to "src/". But also split it in different
directories so that they have a clearer purpose.

The goal is to have a flat directory hierarchy. The "src/libnm-core*/"
directories correspond to the different modules (static libraries and set
of headers that we have). We have different kinds of such modules because
of how we combine various code together. The directory layout now reflects
this.
2021-02-18 19:46:51 +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
Thomas Haller 88071abb43
all: unify comment style for SPDX-License-Identifier tag
Our coding style recommends C style comments (/* */) instead of C++
(//). Also, systemd (which we partly fork) uses C style comments for
the SPDX-License-Identifier.

Unify the style.

  $ sed -i '1 s#// SPDX-License-Identifier: \([^ ]\+\)$#/* SPDX-License-Identifier: \1 */#' -- $(git ls-files -- '*.[hc]' '*.[hc]pp')
2020-09-29 16:50:53 +02:00
Thomas Haller 740b092fda
format: replace tabs for indentation in code comments
sed -i \
     -e 's/^'$'\t'' \*/     */g' \
     -e 's/^'$'\t\t'' \*/         */g' \
     -e 's/^'$'\t\t\t'' \*/             */g' \
     -e 's/^'$'\t\t\t\t'' \*/                 */g' \
     -e 's/^'$'\t\t\t\t\t'' \*/                     */g' \
     -e 's/^'$'\t\t\t\t\t\t'' \*/                         */g' \
     -e 's/^'$'\t\t\t\t\t\t\t'' \*/                             */g' \
     $(git ls-files -- '*.[hc]')
2020-09-28 16:07:52 +02:00
Antonio Cardace 328fb90f3e
all: reformat all with new clang-format style
Run:

    ./contrib/scripts/nm-code-format.sh -i
    ./contrib/scripts/nm-code-format.sh -i

Yes, it needs to run twice because the first run doesn't yet produce the
final result.

Signed-off-by: Antonio Cardace <acardace@redhat.com>
2020-09-28 16:07:51 +02: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 5c08981356
examples: avoid non-thread-safe localtime() function example
Just to silence the warning on lgtm.com.
2020-05-07 13:58:13 +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
Iñigo Martínez 648155e4a1 license: Add license using SPDX identifiers to meson build files
License is missing in meson build files. This has been added using
SPDX identifiers and licensed under LGPL-2.1+.
2020-02-17 13:16:57 +01: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 c6d53c5500 dispatcher: avoid "dirname" and "basename" calls in "10-ifcfg-rh-routes.sh" script
The script is run for every dispatcher event. Most of the events are not
actually relevant, and we just need to determine that there is nothing
to do and quit.

Avoid calling "dirname" and "basename".

The supported ifcfg-file has a very specific form. We can just check
(and parse) it in one got regular expression in bash.
2019-10-04 12:38:16 +02:00
Thomas Haller babd1f314e dispatcher: move return-early checks in "10-ifcfg-rh-routes.sh" first
A shell script is executed line-by-line. Note that for most dispatcher
events, "10-ifcfg-rh-routes.sh" has nothing to do and will just quit.
Move those checks earlier, to avoid bash executing the code that won't
be needed most of the time.
2019-10-04 12:37:50 +02: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
Iñigo Martínez 700f6f6b5f meson: Improve Qt examples
Qt dependencies have been moved to the main build file where the
rest of dependencies are located. This makes it easier to find them.

The included directories has also reviewed and removed the
unnecessary ones.
2019-10-01 09:49:33 +02:00
Iñigo Martínez caf470f788 meson: Improve targets involving libnm library
The targets that involve the use of the `libnm` library have been
improved by applying a set of changes:

- Generated enum sources variable `libnm_enum` has been renamed to
  `libnm_enum_sources` to clearly specify what it is holding.
- Indentation in the `libnm` build and test files has been fixed.
- Set of objects used in targets have been grouped together.
2019-10-01 09:49:33 +02:00
Iñigo Martínez f427f4771e meson: Improve the libnm-core build file
The `libnm-core` build file has been improved by applying a set of
changes:

- Indentation has been fixed to be consistent.
- Library variable names have been changed to `lib{name}` pattern
  following their filename pattern.
- `shared` prefix has been removed from all variables using it.
- Dependencies have been reviewed to store the necessary data.
- The use of the libraries and dependencies created in this file
  has been reviewed through the entire source code. This has
  required the addition or the removal of different libraries and
  dependencies in different targets.
- Some files used directly with the `files` function have been moved
  to their nearest path build file because meson stores their full
  path seamessly and they can be used anywhere later.
2019-10-01 09:49:33 +02:00
Iñigo Martínez 70a34c54fe meson: Use dependency for nm-default header
The `nm-default.h` header is used widely in the code by many
targets. This header includes different headers and needs different
libraries depending the compilation flags.

A new set of `*nm_default_dep` dependencies have been created to
ease the inclusion of different directorires and libraries.

This allows cleaner build files and avoiding linking unnecessary
libraries so this has been applied allowing the removal of some
dependencies involving the linking of unnecessary libraries.
2019-10-01 09:49:33 +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
Thomas Haller d3db21ddaf examples: use '\n' line endings in "examples/C/qt/add-connection-wired.cpp"
Find with:

  git ls-files -z | xargs -0 file | grep with\ CRLF

Fix with:

  dos2unix examples/C/qt/add-connection-wired.cpp
2019-06-11 09:58:50 +02:00
Thomas Haller 1da7dfc408 gitignore: merge gitignore files
For the most part, we only have one main .gitignore file.

There were a few nested files, merge them into the main file.

I find it better to have only one gitignore file, otherwise the
list of ignored files is spread out through the working directory.
2019-05-19 14:41:21 +02:00