-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for reading optional pkgmgr env file
If there is a file .kiwi.package_manager.env in the root of the image tree it will be read and put into the caller environment for the selected package and repository manager. There are features in e.g zypper which can only be used via env variables. This Fixes bsc#1235448
- Loading branch information
Showing
11 changed files
with
104 additions
and
0 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 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,59 @@ | ||
# Copyright (c) 2024 SUSE Software Solutions Germany GmbH. All rights reserved. | ||
# | ||
# This file is part of kiwi. | ||
# | ||
# kiwi 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, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# kiwi 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 kiwi. If not, see <http://www.gnu.org/licenses/> | ||
# | ||
import csv | ||
import os | ||
from io import TextIOWrapper | ||
from typing import Iterable | ||
|
||
# project | ||
from kiwi.exceptions import KiwiEnvImportError | ||
|
||
|
||
class ToEnv: | ||
""" | ||
**Read env file and merge with os.environ** | ||
""" | ||
def __init__(self, root_dir: str, envfile: str): | ||
self.data = {} | ||
env_file = f'{root_dir}/{envfile}' | ||
if os.path.isfile(env_file): | ||
try: | ||
with open(env_file) as osdata: | ||
reader = csv.reader(ToEnv._rip(osdata), delimiter='=') | ||
self.data = dict(reader) | ||
except Exception as issue: | ||
raise KiwiEnvImportError( | ||
f'Import of {envfile} failed with {issue}' | ||
) | ||
if self.data: | ||
os.environ.update(self.data) | ||
|
||
@staticmethod | ||
def _is_comment(line: str) -> bool: | ||
return line.startswith('#') | ||
|
||
@staticmethod | ||
def _is_whitespace(line: str) -> bool: | ||
return line.isspace() | ||
|
||
@staticmethod | ||
def _rip(csvfile: TextIOWrapper) -> Iterable[str]: | ||
for row in csvfile: | ||
if not ToEnv._is_comment(row) \ | ||
and not ToEnv._is_whitespace(row): | ||
yield row |
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 @@ | ||
ZYPP_MODALIAS_SYSFS="" |
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 @@ | ||
xxxx |
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,18 @@ | ||
from pytest import raises | ||
import os | ||
|
||
from kiwi.utils.toenv import ToEnv | ||
from kiwi.exceptions import KiwiEnvImportError | ||
|
||
|
||
class TestToEnv(object): | ||
def setup(self): | ||
ToEnv('../data', 'some.env') | ||
assert os.environ['ZYPP_MODALIAS_SYSFS'] == '' | ||
|
||
def setup_method(self, cls): | ||
self.setup() | ||
|
||
def test_setup_raises(self): | ||
with raises(KiwiEnvImportError): | ||
ToEnv('../data', 'some_broken.env') |