Fixed capped default choice, removed old py2 code

This commit is contained in:
Spitap
2023-10-15 11:30:16 +02:00
committed by Antoine Nguyen
parent bd91c85888
commit e4d68498dd
2 changed files with 12 additions and 55 deletions

View File

@@ -1,5 +1,6 @@
"""Utility functions."""
import configparser
import contextlib
import datetime
import getpass
@@ -13,10 +14,6 @@ import string
import subprocess
import sys
import uuid
try:
import configparser
except ImportError:
import ConfigParser as configparser
from . import config_dict_template
from .compatibility_matrix import APP_INCOMPATIBILITY
@@ -35,12 +32,7 @@ class FatalError(Exception):
def user_input(message):
"""Ask something to the user."""
try:
from builtins import input
except ImportError:
answer = raw_input(message)
else:
answer = input(message)
answer = input(message)
return answer
@@ -323,8 +315,8 @@ def validate(value, config_entry):
return True
def get_entry_value(entry, interactive, config):
default_entry = entry("default")
def get_entry_value(entry: dict, interactive: bool, config: configparser.ConfigParser) -> string:
default_entry = entry["default"]
if type(default_entry) is type(list()):
default_value = check_if_condition(config, default_entry)
if callable(default_entry):
@@ -481,7 +473,7 @@ def validate_backup_path(path: str, silent_mode: bool):
if not path_exists:
if not silent_mode:
create_dir = input(
f"\"{path}\" doesn't exist, would you like to create it? [Y/n]\n"
f"\"{path}\" doesn't exist, would you like to create it? [y/N]\n"
).lower()
if silent_mode or (not silent_mode and create_dir.startswith("y")):
@@ -496,7 +488,7 @@ def validate_backup_path(path: str, silent_mode: bool):
if len(os.listdir(path)) != 0:
if not silent_mode:
delete_dir = input(
"Warning: backup directory is not empty, it will be purged if you continue... [Y/n]\n").lower()
"Warning: backup directory is not empty, it will be purged if you continue... [y/N]\n").lower()
if silent_mode or (not silent_mode and delete_dir.startswith("y")):
try:

47
run.py
View File

@@ -11,7 +11,6 @@ except ImportError:
import ConfigParser as configparser
import sys
import checks
from modoboa_installer import compatibility_matrix
from modoboa_installer import constants
from modoboa_installer import package
@@ -37,12 +36,6 @@ PRIMARY_APPS = [
def installation_disclaimer(args, config):
"""Display installation disclaimer."""
hostname = config.get("general", "hostname")
utils.printcolor(
"Notice:\n"
"It is recommanded to run this installer on a FRESHLY installed server.\n"
"(ie. with nothing special already installed on it)\n",
utils.CYAN
)
utils.printcolor(
"Warning:\n"
"Before you start the installation, please make sure the following "
@@ -53,7 +46,7 @@ def installation_disclaimer(args, config):
hostname.replace(".{}".format(args.domain), ""),
hostname
),
utils.YELLOW
utils.CYAN
)
utils.printcolor(
"Your mail server will be installed with the following components:",
@@ -119,9 +112,6 @@ def backup_system(config, args):
utils.copy_file(args.configfile, backup_path)
# Backup applications
for app in PRIMARY_APPS:
if app == "dovecot" and args.no_mail:
utils.printcolor("Skipping mail backup", utils.BLUE)
continue
scripts.backup(app, config, backup_path)
@@ -173,17 +163,11 @@ def main(input_args):
help="For script usage, do not require user interaction "
"backup will be saved at ./modoboa_backup/Backup_M_Y_d_H_M "
"if --backup-path is not provided")
parser.add_argument(
"--no-mail", action="store_true", default=False,
help="Disable mail backup (save space)")
parser.add_argument(
"--restore", type=str, metavar="path",
help="Restore a previously backup up modoboa instance on a NEW machine. "
"You MUST provide backup directory"
),
parser.add_argument(
"--skip-checks", action="store_true", default=False,
help="Skip the checks the installer performs initially")
)
parser.add_argument("domain", type=str,
help="The main domain of your future mail server")
args = parser.parse_args(input_args)
@@ -204,12 +188,6 @@ def main(input_args):
utils.success("Welcome to Modoboa installer!\n")
# Checks
if not args.skip_checks:
utils.printcolor("Checking the installer...", utils.BLUE)
checks.handle()
utils.success("Checks complete\n")
is_config_file_available, outdate_config = utils.check_config_file(
args.configfile, args.interactive, args.upgrade, args.backup, is_restoring)
@@ -221,12 +199,12 @@ def main(input_args):
# Check if config is outdated and ask user if it needs to be updated
if is_config_file_available and outdate_config:
answer = utils.user_input("It seems that your config file is outdated. "
"Would you like to update it? (Y/n) ")
if not answer or answer.lower().startswith("y"):
"Would you like to update it? (y/N) ")
if answer.lower().startswith("y"):
config_file_update_complete(utils.update_config(args.configfile))
if not args.stop_after_configfile_check:
answer = utils.user_input("Would you like to stop to review the updated config? (Y/n)")
if not answer or answer.lower().startswith("y"):
answer = utils.user_input("Would you like to stop to review the updated config? (y/N)")
if answer.lower().startswith("y"):
return
else:
utils.error("You might encounter unexpected errors ! "
@@ -300,19 +278,6 @@ def main(input_args):
"Restore complete! You can enjoy Modoboa at https://{} (same credentials as before)"
.format(config.get("general", "hostname"))
)
utils.success(
"\n"
"Modoboa is a free software maintained by volunteers.\n"
"You like the project and want it to be sustainable?\n"
"Then don't wait anymore and go sponsor it here:\n"
)
utils.printcolor(
"https://github.com/sponsors/modoboa\n",
utils.YELLOW
)
utils.success(
"Thank you for your help :-)\n"
)
if __name__ == "__main__":