Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhacements to scripts for developers #1377

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 28 additions & 13 deletions examples/guided.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import logging
import os
import time
from inspect import getsourcefile

if __name__ == '__main__':
# to be able to execute simply as python examples/guided.py or (from inside examples python guided.py)
# will work only with the copy at examples
# this solution was taken from https://stackoverflow.com/questions/714063/importing-modules-from-parent-folder/33532002#33532002
import sys
current_path = os.path.abspath(getsourcefile(lambda: 0))
current_dir = os.path.dirname(current_path)
parent_dir = current_dir[:current_dir.rfind(os.path.sep)]
sys.path.append(parent_dir)

import archinstall
from archinstall import ConfigurationOutput, Menu
Expand Down Expand Up @@ -288,20 +299,24 @@ def perform_installation(mountpoint):
archinstall.log(f"Failed to update the keyring. Please check your internet connection and the log file '{log_file}'.", level=logging.INFO, fg="red")
exit(1)

if not archinstall.arguments.get('silent'):
ask_user_questions()
nomen = getsourcefile(lambda: 0)
script_name = nomen[nomen.rfind(os.path.sep) + 1:nomen.rfind('.')]

config_output = ConfigurationOutput(archinstall.arguments)
if not archinstall.arguments.get('silent'):
config_output.show()
config_output.save()
if __name__ in ('__main__',script_name):
if not archinstall.arguments.get('silent'):
ask_user_questions()

if archinstall.arguments.get('dry_run'):
exit(0)
config_output = ConfigurationOutput(archinstall.arguments)
if not archinstall.arguments.get('silent'):
config_output.show()
config_output.save()

if archinstall.arguments.get('dry_run'):
exit(0)

if not archinstall.arguments.get('silent'):
input(str(_('Press Enter to continue.')))
if not archinstall.arguments.get('silent'):
input(str(_('Press Enter to continue.')))

archinstall.configuration_sanity_check()
perform_filesystem_operations()
perform_installation(archinstall.storage.get('MOUNT_POINT', '/mnt'))
archinstall.configuration_sanity_check()
perform_filesystem_operations()
perform_installation(archinstall.storage.get('MOUNT_POINT', '/mnt'))
42 changes: 30 additions & 12 deletions examples/only_hd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
import os
import pathlib

from inspect import getsourcefile

if __name__ == '__main__':
# to be able to execute simply as python examples/guided.py or (from inside examples python guided.py)
# will work only with the copy at examples
# this solution was taken from https://stackoverflow.com/questions/714063/importing-modules-from-parent-folder/33532002#33532002
import sys
current_path = os.path.abspath(getsourcefile(lambda: 0))
current_dir = os.path.dirname(current_path)
parent_dir = current_dir[:current_dir.rfind(os.path.sep)]
sys.path.append(parent_dir)

import archinstall
from archinstall import ConfigurationOutput

Expand Down Expand Up @@ -134,18 +146,24 @@ def log_execution_environment():
archinstall.log(f"Arch Linux mirrors are not reachable. Please check your internet connection and the log file '{log_file}'.", level=logging.INFO, fg="red")
exit(1)

if not archinstall.arguments.get('silent'):
ask_user_questions()

config_output = ConfigurationOutput(archinstall.arguments)
if not archinstall.arguments.get('silent'):
config_output.show()
config_output.save()
nomen = getsourcefile(lambda: 0)
script_name = nomen[nomen.rfind(os.path.sep) + 1:nomen.rfind('.')]

if archinstall.arguments.get('dry_run'):
exit(0)
if not archinstall.arguments.get('silent'):
input('Press Enter to continue.')
if __name__ in ('__main__',script_name):

if not archinstall.arguments.get('silent'):
ask_user_questions()

config_output = ConfigurationOutput(archinstall.arguments)
if not archinstall.arguments.get('silent'):
config_output.show()
config_output.save()

if archinstall.arguments.get('dry_run'):
exit(0)
if not archinstall.arguments.get('silent'):
input('Press Enter to continue.')

perform_disk_operations()
perform_installation(archinstall.storage.get('MOUNT_POINT', '/mnt'))
perform_disk_operations()
perform_installation(archinstall.storage.get('MOUNT_POINT', '/mnt'))
46 changes: 32 additions & 14 deletions examples/swiss.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@
import pathlib
from typing import TYPE_CHECKING, Any

from inspect import getsourcefile

if __name__ == '__main__':
# to be able to execute simply as python examples/guided.py or (from inside examples python guided.py)
# will work only with the copy at examples
# this solution was taken from https://stackoverflow.com/questions/714063/importing-modules-from-parent-folder/33532002#33532002
import sys
current_path = os.path.abspath(getsourcefile(lambda: 0))
current_dir = os.path.dirname(current_path)
parent_dir = current_dir[:current_dir.rfind(os.path.sep)]
sys.path.append(parent_dir)


import archinstall
from archinstall import ConfigurationOutput, NetworkConfigurationHandler, Menu

Expand Down Expand Up @@ -495,20 +508,25 @@ def perform_installation(mountpoint, mode):
archinstall.log(f"Arch Linux mirrors are not reachable. Please check your internet connection and the log file '{log_file}'.", level=logging.INFO, fg="red")
exit(1)

mode = archinstall.arguments.get('mode', 'full').lower()
if not archinstall.arguments.get('silent'):
ask_user_questions(mode)
nomen = getsourcefile(lambda: 0)
script_name = nomen[nomen.rfind(os.path.sep) + 1:nomen.rfind('.')]

config_output = ConfigurationOutput(archinstall.arguments)
if not archinstall.arguments.get('silent'):
config_output.show()
config_output.save()
if __name__ in ('__main__',script_name):

if archinstall.arguments.get('dry_run'):
exit(0)
if not archinstall.arguments.get('silent'):
input('Press Enter to continue.')
mode = archinstall.arguments.get('mode', 'full').lower()
if not archinstall.arguments.get('silent'):
ask_user_questions(mode)

config_output = ConfigurationOutput(archinstall.arguments)
if not archinstall.arguments.get('silent'):
config_output.show()
config_output.save()

if archinstall.arguments.get('dry_run'):
exit(0)
if not archinstall.arguments.get('silent'):
input('Press Enter to continue.')

if mode in ('full','only_hd'):
perform_filesystem_operations()
perform_installation(archinstall.storage.get('MOUNT_POINT', '/mnt'), mode)
if mode in ('full','only_hd'):
perform_filesystem_operations()
perform_installation(archinstall.storage.get('MOUNT_POINT', '/mnt'), mode)