Esempio n. 1
0
 def setup_keyboard_map(self):
     """
     Setup console keyboard
     """
     if 'keytable' in self.preferences:
         log.info('Setting up keytable: {0}'.format(
             self.preferences['keytable']))
         if CommandCapabilities.has_option_in_help('systemd-firstboot',
                                                   '--keymap',
                                                   root=self.root_dir,
                                                   raise_on_error=False):
             Path.wipe(self.root_dir + '/etc/vconsole.conf')
             Command.run([
                 'chroot', self.root_dir, 'systemd-firstboot',
                 '--keymap=' + self.preferences['keytable']
             ])
         elif os.path.exists(self.root_dir + '/etc/sysconfig/keyboard'):
             Shell.run_common_function('baseUpdateSysConfig', [
                 self.root_dir + '/etc/sysconfig/keyboard', 'KEYTABLE',
                 '"' + self.preferences['keytable'] + '"'
             ])
         else:
             log.warning(
                 'keyboard setup skipped no capable '
                 'systemd-firstboot or etc/sysconfig/keyboard found')
Esempio n. 2
0
 def setup_keyboard_map(self):
     """
     Setup console keyboard
     """
     if 'keytable' in self.preferences:
         log.info(
             'Setting up keytable: %s', self.preferences['keytable']
         )
         if CommandCapabilities.has_option_in_help(
             'systemd-firstboot', '--keymap',
             root=self.root_dir, raise_on_error=False
         ):
             Path.wipe(self.root_dir + '/etc/vconsole.conf')
             Command.run([
                 'chroot', self.root_dir, 'systemd-firstboot',
                 '--keymap=' + self.preferences['keytable']
             ])
         elif os.path.exists(self.root_dir + '/etc/sysconfig/keyboard'):
             Shell.run_common_function(
                 'baseUpdateSysConfig', [
                     self.root_dir + '/etc/sysconfig/keyboard', 'KEYTABLE',
                     '"' + self.preferences['keytable'] + '"'
                 ]
             )
         else:
             log.warning(
                 'keyboard setup skipped no capable '
                 'systemd-firstboot or etc/sysconfig/keyboard found'
             )
Esempio n. 3
0
 def setup_locale(self):
     """
     Setup UTF8 system wide locale
     """
     if 'locale' in self.preferences:
         if 'POSIX' in self.preferences['locale'].split(','):
             locale = 'POSIX'
         else:
             locale = '{0}.UTF-8'.format(
                 self.preferences['locale'].split(',')[0]
             )
         log.info('Setting up locale: %s', self.preferences['locale'])
         if CommandCapabilities.has_option_in_help(
             'systemd-firstboot', '--locale',
             root=self.root_dir, raise_on_error=False
         ):
             Path.wipe(self.root_dir + '/etc/locale.conf')
             Command.run([
                 'chroot', self.root_dir, 'systemd-firstboot',
                 '--locale=' + locale
             ])
         elif os.path.exists(self.root_dir + '/etc/sysconfig/language'):
             Shell.run_common_function(
                 'baseUpdateSysConfig', [
                     self.root_dir + '/etc/sysconfig/language',
                     'RC_LANG', locale
                 ]
             )
         else:
             log.warning(
                 'locale setup skipped no capable '
                 'systemd-firstboot or etc/sysconfig/language not found'
             )
Esempio n. 4
0
 def setup_locale(self):
     """
     Setup UTF8 system wide locale
     """
     if 'locale' in self.preferences:
         if 'POSIX' in self.preferences['locale'].split(','):
             locale = 'POSIX'
         else:
             locale = '{0}.UTF-8'.format(
                 self.preferences['locale'].split(',')[0])
         log.info('Setting up locale: %s', self.preferences['locale'])
         if CommandCapabilities.has_option_in_help('systemd-firstboot',
                                                   '--locale',
                                                   root=self.root_dir,
                                                   raise_on_error=False):
             Path.wipe(self.root_dir + '/etc/locale.conf')
             Command.run([
                 'chroot', self.root_dir, 'systemd-firstboot',
                 '--locale=' + locale
             ])
         if os.path.exists(self.root_dir + '/etc/sysconfig/language'):
             Shell.run_common_function('baseUpdateSysConfig', [
                 self.root_dir + '/etc/sysconfig/language', 'RC_LANG',
                 locale
             ])
Esempio n. 5
0
 def test_run_common_function(self, mock_command):
     Shell.run_common_function('foo', ['"param1"', '"param2"'])
     command_string = ' '.join([
         'source',
         Defaults.project_file('config/functions.sh') + ';', 'foo',
         '"param1"', '"param2"'
     ])
     mock_command.assert_called_once_with(['bash', '-c', command_string])
Esempio n. 6
0
 def test_format_to_variable_value(self):
     assert Shell.format_to_variable_value('text') == 'text'
     assert Shell.format_to_variable_value(True) == 'true'
     assert Shell.format_to_variable_value(False) == 'false'
     assert Shell.format_to_variable_value('42') == '42'
     assert Shell.format_to_variable_value(0) == '0'
     assert Shell.format_to_variable_value(42) == '42'
     assert Shell.format_to_variable_value(None) == ''
     assert Shell.format_to_variable_value(b"42") == '42'
     with raises(KiwiShellVariableValueError):
         Shell.format_to_variable_value(['foo', 'bar'])
Esempio n. 7
0
 def test_run_common_function(self, mock_command):
     Shell.run_common_function('foo', ['"param1"', '"param2"'])
     command_string = ' '.join(
         [
             'source', Defaults.project_file('config/functions.sh') + ';',
             'foo', '"param1"', '"param2"'
         ]
     )
     mock_command.assert_called_once_with(
         ['bash', '-c', command_string]
     )
Esempio n. 8
0
 def setup_locale(self):
     """
     Setup etc/sysconfig/language UTF8 locale
     """
     if 'locale' in self.preferences:
         lang_config = self.root_dir + '/etc/sysconfig/language'
         if os.path.exists(lang_config):
             log.info('Setting up locale: %s', self.preferences['locale'])
             Shell.run_common_function('baseUpdateSysConfig', [
                 lang_config, 'RC_LANG',
                 self.preferences['locale'].split(',')[0] + '.UTF-8'
             ])
         else:
             log.warning(
                 'locale setup skipped etc/sysconfig/language not found')
Esempio n. 9
0
 def setup_keyboard_map(self):
     """
     Setup etc/sysconfig/keyboard console keyboard
     """
     if 'keytable' in self.preferences:
         keyboard_config = self.root_dir + '/etc/sysconfig/keyboard'
         if os.path.exists(keyboard_config):
             log.info('Setting up keytable: %s',
                      self.preferences['keytable'])
             Shell.run_common_function('baseUpdateSysConfig', [
                 keyboard_config, 'KEYTABLE',
                 '"' + self.preferences['keytable'] + '"'
             ])
         else:
             log.warning(
                 'keyboard setup skipped etc/sysconfig/keyboard not found')
Esempio n. 10
0
 def test_quote_key_value_file(self):
     assert Shell.quote_key_value_file("../data/key_value") == [
         "foo='bar'",
         "bar='xxx'",
         "name='bob'",
         "strange='$a_foo'",
     ]
Esempio n. 11
0
 def get_settings(self) -> Dict:
     """
     Return all profile elements that has a value
     """
     profile = {}
     for key, value in list(self.dot_profile.items()):
         profile[key] = Shell.format_to_variable_value(value)
     return collections.OrderedDict(sorted(profile.items()))
Esempio n. 12
0
 def test_quote_key_value_file(self, mock_which):
     mock_which.return_value = 'cp'
     assert Shell.quote_key_value_file('../data/key_value') == [
         "foo='bar'",
         "bar='xxx'",
         "name='bob'",
         "strange='$a_foo'"
     ]
Esempio n. 13
0
 def test_quote_key_value_file(self, mock_which):
     mock_which.return_value = 'cp'
     assert Shell.quote_key_value_file('../data/key_value') == [
         "foo='bar'",
         "bar='xxx'",
         "name='bob'",
         "strange='$a_foo'"
     ]
Esempio n. 14
0
File: profile.py Progetto: pyzh/kiwi
    def create(self):
        """
        Create bash quoted profile

        :return: profile dump for bash
        :rtype: string
        """
        sorted_profile = collections.OrderedDict(
            sorted(self.dot_profile.items()))
        temp_profile = NamedTemporaryFile()
        with open(temp_profile.name, 'w') as profile:
            for key, value in list(sorted_profile.items()):
                if value:
                    profile.write(
                        format(key) + '=' + self._format(value) + '\n')
        return Shell.quote_key_value_file(temp_profile.name)
Esempio n. 15
0
    def create(self, filename: str) -> None:
        """
        Create bash quoted profile

        :param str filename: file path name
        """
        sorted_profile = self.get_settings()
        temp_profile = Temporary().new_file()
        with open(temp_profile.name, 'w') as profile:
            for key, value in list(sorted_profile.items()):
                profile.write('{0}={1}{2}'.format(key, value, os.linesep))
        profile_environment = Shell.quote_key_value_file(temp_profile.name)
        with open(filename, 'w') as profile:
            for line in profile_environment:
                profile.write(line + os.linesep)
                log.debug('--> {0}'.format(line))
Esempio n. 16
0
    def create(self, filename):
        """
        Create bash quoted profile

        :param str filename: file path name
        """
        sorted_profile = collections.OrderedDict(
            sorted(self.dot_profile.items()))
        temp_profile = NamedTemporaryFile()
        with open(temp_profile.name, 'w') as profile:
            for key, value in list(sorted_profile.items()):
                if value:
                    profile.write(
                        format(key) + '=' + self._format(value) + '\n')
        profile_environment = Shell.quote_key_value_file(temp_profile.name)
        with open(filename, 'w') as profile:
            for line in profile_environment:
                profile.write(line + os.linesep)
                log.debug('--> {0}'.format(line))
Esempio n. 17
0
    def create(self):
        """
        Create bash quoted profile

        :return: profile dump for bash

        :rtype: str
        """
        Defaults.set_python_default_encoding_to_utf8()

        sorted_profile = collections.OrderedDict(
            sorted(self.dot_profile.items())
        )
        temp_profile = NamedTemporaryFile()
        with open(temp_profile.name, 'w') as profile:
            for key, value in list(sorted_profile.items()):
                if value:
                    profile.write(
                        format(key) + '=' + self._format(value) + '\n'
                    )
        return Shell.quote_key_value_file(temp_profile.name)
Esempio n. 18
0
 def test_quote_key_value_file(self):
     assert Shell.quote_key_value_file('../data/key_value') == [
         "foo='bar'", "bar='xxx'", "name='bob'", "strange='$a_foo'"
     ]
Esempio n. 19
0
 def test_quote(self):
     assert Shell.quote('aa\!') == 'aa\\\\\\!'
Esempio n. 20
0
 def test_quote(self):
     assert Shell.quote("aa\!") == "aa\\\\\\!"
Esempio n. 21
0
 def test_run_common_function(self, mock_command):
     Shell.run_common_function("foo", ['"param1"', '"param2"'])
     command_string = " ".join(
         ["source", Defaults.project_file("config/functions.sh") + ";", "foo", '"param1"', '"param2"']
     )
     mock_command.assert_called_once_with(["bash", "-c", command_string])
Esempio n. 22
0
 def test_quote(self):
     assert Shell.quote('aa\!') == 'aa\\\\\\!'