-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
433 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1 @@ | ||
pymod = import('python') | ||
python = pymod.find_installation( | ||
'python3', | ||
modules: ['cffi'] | ||
) | ||
python_dep = python.dependency(required: true) | ||
|
||
cffi_srcs = configure_file( | ||
command: [ | ||
python, | ||
files('_build_cffi.py'), | ||
join_paths(meson.project_source_root(), 'include'), | ||
join_paths(meson.current_build_dir(), 'src'), | ||
], | ||
output: '_libnetplan0.c', | ||
) | ||
|
||
# See https://github.com/grimme-lab/xtb-python/blob/main/meson.build | ||
cffi_pyext = python.extension_module( | ||
'_libnetplan0', | ||
link_whole: static_library( | ||
'_libnetplan0', | ||
cffi_srcs, | ||
dependencies: [python_dep, glib], | ||
include_directories: [inc], | ||
), | ||
dependencies: [python_dep], | ||
include_directories: [include_directories(join_paths('..', 'include'))], | ||
subdir: 'netplan', | ||
install: true, | ||
) | ||
|
||
bindings_sources = ''' | ||
__init__.py | ||
parser.py | ||
state.py | ||
'''.split() | ||
|
||
bindings = python.install_sources( | ||
[bindings_sources], | ||
subdir: 'netplan') | ||
subdir('netplan') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Copyright (C) 2023 Canonical, Ltd. | ||
# Author: Lukas Märdian <[email protected]> | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; version 3. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from io import StringIO | ||
import os | ||
from typing import IO | ||
|
||
from _libnetplan0 import lib | ||
from .parser import Parser | ||
from .state import State | ||
from ._utils import (_checked_lib_call, NetplanException, | ||
NetplanValidationException, NetplanParserException, | ||
NetplanFileException, NetplanFormatException) | ||
|
||
|
||
def _dump_yaml_subtree(prefix, input_file: IO, output_file: IO): | ||
if isinstance(input_file, StringIO): | ||
input_fd = os.memfd_create(name='netplan_temp_input_file') | ||
data = input_file.getvalue() | ||
os.write(input_fd, data.encode('utf-8')) | ||
os.lseek(input_fd, 0, os.SEEK_SET) | ||
else: | ||
input_fd = input_file.fileno() | ||
|
||
if isinstance(output_file, StringIO): | ||
output_fd = os.memfd_create(name='netplan_temp_output_file') | ||
else: | ||
output_fd = output_file.fileno() | ||
|
||
_checked_lib_call(lib.netplan_util_dump_yaml_subtree, prefix.encode('utf-8'), input_fd, output_fd) | ||
|
||
if isinstance(input_file, StringIO): | ||
os.close(input_fd) | ||
|
||
if isinstance(output_file, StringIO): | ||
size = os.lseek(output_fd, 0, os.SEEK_CUR) | ||
os.lseek(output_fd, 0, os.SEEK_SET) | ||
data = os.read(output_fd, size) | ||
output_file.write(data.decode('utf-8')) | ||
os.close(output_fd) | ||
|
||
|
||
# Re-export submodules | ||
__all__ = [Parser, State, NetplanException, NetplanValidationException, | ||
NetplanParserException, NetplanFileException, NetplanFormatException, | ||
_dump_yaml_subtree] |
Oops, something went wrong.