Skip to content

Commit

Permalink
Fixed capped default choice, removed old py2 code
Browse files Browse the repository at this point in the history
  • Loading branch information
Spitfireap committed Oct 15, 2023
1 parent 30c411b commit b8f3cbc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
20 changes: 6 additions & 14 deletions modoboa_installer/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Utility functions."""

import configparser
import contextlib
import datetime
import getpass
Expand All @@ -12,10 +13,6 @@
import string
import subprocess
import sys
try:
import configparser
except ImportError:
import ConfigParser as configparser

from . import config_dict_template
from .compatibility_matrix import APP_INCOMPATIBILITY
Expand All @@ -34,12 +31,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


Expand Down Expand Up @@ -322,8 +314,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):
Expand Down Expand Up @@ -469,7 +461,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")):
Expand All @@ -484,7 +476,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:
Expand Down
4 changes: 2 additions & 2 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,11 @@ 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) ")
"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)")
answer = utils.user_input("Would you like to stop to review the updated config? (y/N)")
if answer.lower().startswith("y"):
return
else:
Expand Down

0 comments on commit b8f3cbc

Please sign in to comment.