Files
NetworkManager/examples/python/gi/vpn-import.py
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

60 lines
1.5 KiB
Python
Executable File

#!/usr/bin/env python
# SPDX-License-Identifier: GPL-2.0+
#
# Copyright (C) 2014 Red Hat, Inc.
#
#
# This example imports a VPN connection, by loading the glib based
# VPN plugin.
import gi
gi.require_version('NM', '1.0')
from gi.repository import GLib, NM
import sys
if len(sys.argv) != 2:
print("Expects one argument: the filename")
sys.exit(1)
filename = sys.argv[1]
connection = None
for vpn_info in NM.VpnPluginInfo.list_load():
print("TRY: plugin %s" % (vpn_info.get_filename()))
try:
vpn_plugin = vpn_info.load_editor_plugin()
except Exception as e:
print("SKIP: cannot load plugin: %s" % (e))
continue
try:
connection = vpn_plugin.import_(filename)
except Exception as e:
print("SKIP: failure to import %s" % (e))
continue
break
if connection is None:
print("None of the VPN plugins was able to import \"%s\"" % (filename))
sys.exit(1)
connection.normalize()
print("connection imported from \"%s\" using plugin \"%s\" (\"%s\", %s)" % (filename, vpn_info.get_filename(), connection.get_id(), connection.get_uuid()))
client = NM.Client.new(None)
main_loop = GLib.MainLoop()
def added_cb(client, result, data):
try:
client.add_connection_finish(result)
print("The connection profile has been successfully added to NetworkManager.")
except Exception, e:
print("ERROR: failed to add connection: %s\n" % e)
main_loop.quit()
client.add_connection_async(connection, True, None, added_cb, None)
main_loop.run()