Skip to content

Commit

Permalink
Unify sys-language and sys-encoding into sys-locale
Browse files Browse the repository at this point in the history
  • Loading branch information
codefiles committed Aug 13, 2022
1 parent b1ab5ba commit f20f057
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 59 deletions.
6 changes: 2 additions & 4 deletions archinstall/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,8 @@ def load_config():
else:
selected_region = arguments.get('mirror-region', None)
arguments['mirror-region'] = {selected_region: list_mirrors()[selected_region]}
if arguments.get('sys-language', None) is not None:
arguments['sys-language'] = arguments.get('sys-language', 'en_US')
if arguments.get('sys-encoding', None) is not None:
arguments['sys-encoding'] = arguments.get('sys-encoding', 'utf-8')
if arguments.get('sys-locale', None) is not None:
arguments['sys-locale'] = arguments.get('sys-locale', 'en_US.UTF-8 UTF-8')
if arguments.get('gfx_driver', None) is not None:
storage['gfx_driver_packages'] = AVAILABLE_GFX_DRIVERS.get(arguments.get('gfx_driver', None), None)
if arguments.get('servers', None) is not None:
Expand Down
5 changes: 3 additions & 2 deletions archinstall/lib/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,8 @@ def set_hostname(self, hostname: str, *args :str, **kwargs :str) -> None:
with open(f'{self.target}/etc/hostname', 'w') as fh:
fh.write(hostname + '\n')

def set_locale(self, locale :str, encoding :str = 'UTF-8', *args :str, **kwargs :str) -> bool:
def set_locale(self, locale :str, *args :str, **kwargs :str) -> bool:

if not len(locale):
return True

Expand Down Expand Up @@ -749,7 +750,7 @@ def minimal_installation(self, testing=False, multilib=False) -> bool:
# sys_command(f'/usr/bin/arch-chroot {self.target} ln -s /usr/share/zoneinfo/{localtime} /etc/localtime')
# sys_command('/usr/bin/arch-chroot /mnt hwclock --hctosys --localtime')
self.set_hostname('archinstall')
self.set_locale('en_US')
self.set_locale('en_US.UTF-8 UTF-8')

# TODO: Use python functions for this
SysCommand(f'/usr/bin/arch-chroot {self.target} chmod 700 /root')
Expand Down
16 changes: 5 additions & 11 deletions archinstall/lib/menu/global_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
from ..user_interaction import ask_for_additional_users
from ..user_interaction import select_language
from ..user_interaction import select_mirror_regions
from ..user_interaction import select_locale_lang
from ..user_interaction import select_locale_enc
from ..user_interaction import select_locale
from ..user_interaction import select_disk_layout
from ..user_interaction import select_kernel
from ..user_interaction import select_encrypted_partitions
Expand Down Expand Up @@ -65,16 +64,11 @@ def _setup_selection_menu_options(self):
lambda preset: select_mirror_regions(preset),
display_func=lambda x: list(x.keys()) if x else '[]',
default={})
self._menu_options['sys-language'] = \
self._menu_options['sys-locale'] = \
Selector(
_('Locale language'),
lambda preset: select_locale_lang(preset),
default='en_US')
self._menu_options['sys-encoding'] = \
Selector(
_('Locale encoding'),
lambda preset: select_locale_enc(preset),
default='UTF-8')
_('Locale'),
lambda preset: select_locale(preset),
default='en_US.UTF-8 UTF-8')
self._menu_options['harddrives'] = \
Selector(
_('Drive(s)'),
Expand Down
2 changes: 1 addition & 1 deletion archinstall/lib/user_interaction/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .save_conf import save_config
from .manage_users_conf import ask_for_additional_users
from .backwards_compatible_conf import generic_select, generic_multi_select
from .locale_conf import select_locale_lang, select_locale_enc
from .locale_conf import select_locale
from .system_conf import select_kernel, select_harddrives, select_driver, ask_for_bootloader, ask_for_swap
from .network_conf import ask_to_configure_network
from .partitioning_conf import select_partition, select_encrypted_partitions
Expand Down
23 changes: 3 additions & 20 deletions archinstall/lib/user_interaction/locale_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,12 @@
_: Any


def select_locale_lang(preset: str = None) -> str:
def select_locale(preset: str = None) -> str:
locales = list_locales()
locale_lang = set([locale.split()[0] for locale in locales])

selected_locale = Menu(
_('Choose which locale language to use'),
list(locale_lang),
sort=True,
preset_values=preset
).run()

match selected_locale.type_:
case MenuSelectionType.Selection: return selected_locale.value
case MenuSelectionType.Esc: return preset


def select_locale_enc(preset: str = None) -> str:
locales = list_locales()
locale_enc = set([locale.split()[1] for locale in locales])

selected_locale = Menu(
_('Choose which locale encoding to use'),
list(locale_enc),
_('Choose which locale to use'),
list(locales),
sort=True,
preset_values=preset
).run()
Expand Down
7 changes: 2 additions & 5 deletions docs/installing/guided.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ There are three different configuration files, all of which are optional.
"packages": ["docker", "git", "wget", "zsh"],
"profile": "gnome",
"services": ["docker"],
"sys-encoding": "utf-8",
"sys-language": "en_US",
"sys-locale": "en_US.UTF-8 UTF-8",
"timezone": "US/Eastern",
}
Expand Down Expand Up @@ -141,9 +140,7 @@ Options for ``--config``
+----------------------+--------------------------------------------------------+---------------------------------------------------------------------------------------------+-----------------------------------------------+
| services | [ "service1", "service2", ..] | Services to enable post-installation | No |
+----------------------+--------------------------------------------------------+---------------------------------------------------------------------------------------------+-----------------------------------------------+
| sys-encoding | "utf-8" | Set to change system encoding post-install, ignored if --advanced flag is not passed | No |
+----------------------+--------------------------------------------------------+---------------------------------------------------------------------------------------------+-----------------------------------------------+
| sys-language | "en_US" | Set to change system language post-install, ignored if --advanced flag is not passed | No |
| sys-locale | "en_US.UTF-8 UTF-8" | Set to change system locale post-install, ignored if --advanced flag is not passed | No |
+----------------------+--------------------------------------------------------+---------------------------------------------------------------------------------------------+-----------------------------------------------+
| timezone | Timezone to configure in installation | Timezone eg: UTC, Asia/Kolkata etc. Defaults to UTC | No |
+----------------------+--------------------------------------------------------+---------------------------------------------------------------------------------------------+-----------------------------------------------+
Expand Down
3 changes: 1 addition & 2 deletions examples/config-sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"profile": null,
"script": "guided",
"swap": true,
"sys-encoding": "utf-8",
"sys-language": "en_US",
"sys-locale": "en_US.UTF-8 UTF-8",
"timezone": "UTC"
}
3 changes: 1 addition & 2 deletions examples/custom-command-sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
"profile": "gnome",
"gfx_driver": "All open-source (default)",
"swap": true,
"sys-encoding": "utf-8",
"sys-language": "en_US",
"sys-locale": "en_US.UTF-8 UTF-8",
"timezone": "Europe/Stockholm",
"version": "2.3.1.dev0",
"custom-commands": [
Expand Down
5 changes: 2 additions & 3 deletions examples/guided.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ def ask_user_questions():
# Set which region to download packages from during the installation
global_menu.enable('mirror-region')

global_menu.enable('sys-language')
global_menu.enable('sys-encoding')
global_menu.enable('sys-locale')

# Ask which harddrives/block-devices we will install to
# and convert them into archinstall.BlockDevice() objects.
Expand Down Expand Up @@ -193,7 +192,7 @@ def perform_installation(mountpoint):
enable_multilib = False

if installation.minimal_installation(testing=enable_testing, multilib=enable_multilib):
installation.set_locale(archinstall.arguments['sys-language'], archinstall.arguments['sys-encoding'].upper())
installation.set_locale(archinstall.arguments['sys-locale'])
installation.set_hostname(archinstall.arguments['hostname'])
if archinstall.arguments.get('mirror-region') is not None:
if archinstall.arguments.get("mirrors", None) is not None:
Expand Down
6 changes: 3 additions & 3 deletions examples/swiss.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def _setup_selection_menu_options(self):
'!users', 'profile', 'audio', 'kernels', 'packages','additional-repositories','nic',
'timezone', 'ntp']
if archinstall.arguments.get('advanced',False):
options_list.extend(['sys-language','sys-encoding'])
options_list.extend(['sys-locale'])
mandatory_list = ['harddrives','bootloader','hostname']
elif self._execution_mode == 'only_hd':
options_list = ['harddrives', 'disk_layouts', '!encryption-password','swap']
Expand All @@ -245,7 +245,7 @@ def _setup_selection_menu_options(self):
'packages', 'additional-repositories', 'nic', 'timezone', 'ntp']
mandatory_list = ['hostname']
if archinstall.arguments.get('advanced',False):
options_list.expand(['sys-language','sys-encoding'])
options_list.expand(['sys-locale'])
elif self._execution_mode == 'minimal':
pass
else:
Expand Down Expand Up @@ -403,7 +403,7 @@ def os_setup(installation):
if archinstall.arguments.get('mirror-region', None):
archinstall.use_mirrors(archinstall.arguments['mirror-region']) # Set the mirrors for the live medium
if installation.minimal_installation():
installation.set_locale(archinstall.arguments['sys-language'], archinstall.arguments['sys-encoding'].upper())
installation.set_locale(archinstall.arguments['sys-locale'])
installation.set_hostname(archinstall.arguments['hostname'])
if archinstall.arguments['mirror-region'].get("mirrors", None) is not None:
installation.set_mirrors(
Expand Down
8 changes: 2 additions & 6 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,8 @@
"type": "string"
}
},
"sys-encoding": {
"description": "Set to change system encoding post-install, ignored if --advanced flag is not passed",
"type": "string"
},
"sys-language": {
"description": "Set to change system language post-install, ignored if --advanced flag is not passed",
"sys-locale": {
"description": "Set to change system locale post-install, ignored if --advanced flag is not passed",
"type": "string"
},
"timezone": {
Expand Down

0 comments on commit f20f057

Please sign in to comment.