From 31f55e8d6b0b6e7a7fe28433d7d305d58d5667a1 Mon Sep 17 00:00:00 2001 From: Werner Llácer Date: Sat, 15 Jan 2022 14:20:06 +0100 Subject: Activate file write into only_hd and upgrade to guided.py level (#867) --- examples/only_hd.py | 50 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/examples/only_hd.py b/examples/only_hd.py index 0120b64c..addb1d67 100644 --- a/examples/only_hd.py +++ b/examples/only_hd.py @@ -100,36 +100,51 @@ def ask_user_questions(): """ ask_harddrives() +def save_user_configurations(): + user_credentials = {} + if archinstall.arguments.get('!users'): + user_credentials["!users"] = archinstall.arguments['!users'] + if archinstall.arguments.get('!superusers'): + user_credentials["!superusers"] = archinstall.arguments['!superusers'] + if archinstall.arguments.get('!encryption-password'): + user_credentials["!encryption-password"] = archinstall.arguments['!encryption-password'] + + user_configuration = json.dumps({ + 'config_version': archinstall.__version__, # Tells us what version was used to generate the config + **archinstall.arguments, # __version__ will be overwritten by old version definition found in config + 'version': archinstall.__version__ + } , indent=4, sort_keys=True, cls=archinstall.JSON) + + with open("/var/log/archinstall/user_credentials.json", "w") as config_file: + config_file.write(json.dumps(user_credentials, indent=4, sort_keys=True, cls=archinstall.UNSAFE_JSON)) + + with open("/var/log/archinstall/user_configuration.json", "w") as config_file: + config_file.write(user_configuration) + + if archinstall.storage.get('disk_layouts'): + user_disk_layout = json.dumps(archinstall.storage['disk_layouts'], indent=4, sort_keys=True, cls=archinstall.JSON) + with open("/var/log/archinstall/user_disk_layout.json", "w") as disk_layout_file: + disk_layout_file.write(user_disk_layout) + def write_config_files(): print() print('This is your chosen configuration:') archinstall.log("-- Guided template chosen (with below config) --", level=logging.DEBUG) - user_configuration = json.dumps(archinstall.arguments, indent=4, sort_keys=True, cls=archinstall.JSON) + + user_configuration = json.dumps({**archinstall.arguments, 'version' : archinstall.__version__} , indent=4, sort_keys=True, cls=archinstall.JSON) archinstall.log(user_configuration, level=logging.INFO) - with open("/var/log/archinstall/user_configuration.json", "w") as config_file: - config_file.write(user_configuration) + if archinstall.storage.get('disk_layouts'): user_disk_layout = json.dumps(archinstall.storage['disk_layouts'], indent=4, sort_keys=True, cls=archinstall.JSON) archinstall.log(user_disk_layout, level=logging.INFO) - with open("/var/log/archinstall/user_disk_layout.json", "w") as disk_layout_file: - disk_layout_file.write(user_disk_layout) + print() + save_user_configurations() if archinstall.arguments.get('dry-run'): exit(0) - # it is here so a dry run execution will not save the credentials file ¿? - user_credentials = {} - if archinstall.arguments.get('!users'): - user_credentials["!users"] = archinstall.arguments['!users'] - if archinstall.arguments.get('!superusers'): - user_credentials["!superusers"] = archinstall.arguments['!superusers'] - if archinstall.arguments.get('!encryption-password'): - user_credentials["!encryption-password"] = archinstall.arguments['!encryption-password'] - - with open("/var/log/archinstall/user_credentials.json", "w") as config_file: - config_file.write(json.dumps(user_credentials, indent=4, sort_keys=True, cls=archinstall.UNSAFE_JSON)) def perform_disk_operations(): """ @@ -209,9 +224,8 @@ load_config() if not archinstall.arguments.get('silent'): ask_user_questions() -# YEP write_config_files() - if not archinstall.arguments.get('silent'): + write_config_files() input('Press Enter to continue.') perform_disk_operations() -- cgit v1.2.3-70-g09d2