Source code for

# Copyright (c) 2015 SUSE Linux 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
# 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 <>
from tempfile import NamedTemporaryFile

# project
from kiwi.command import Command
from kiwi.defaults import Defaults

[docs]class Shell: """ **Special character handling for shell evaluated code** """
[docs] @staticmethod def quote(message): """ Quote characters which have a special meaning for bash but should be used as normal characters. actually I had planned to use pipes.quote but it does not quote as I had expected it. e.g 'name_wit_a_$' does not quote the $ so we do it on our own for the scope of kiwi :param str message: message text :return: quoted text :rtype: str """ # \\ quoting must be first in the list quote_characters = ['\\', '$', '"', '`', '!'] for quote in quote_characters: message = message.replace(quote, '\\' + quote) return message
[docs] @staticmethod def quote_key_value_file(filename): """ Quote given input file which has to be of the form key=value to be able to become sourced by the shell :param str filename: file path name :return: quoted text :rtype: str """ temp_copy = NamedTemporaryFile()['cp', filename,]) Shell.run_common_function('baseQuoteFile', []) with open( as quoted: return
[docs] @staticmethod def run_common_function(name, parameters): """ Run a function implemented in config/ :param str name: function name :param list parameters: function arguments """ [ 'bash', '-c', 'source ' + ''.join( [ Defaults.get_common_functions_file(), '; ', name, ' ', ' '.join(parameters) ] ) ] )