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

Added a batch option #150

Draft
wants to merge 3 commits into
base: dev
Choose a base branch
from
Draft
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
5 changes: 4 additions & 1 deletion exegol/console/ExegolPrompt.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import rich.prompt


def Confirm(question: str, default: bool) -> bool:
def Confirm(question: str, default: bool, batch: bool) -> bool:
"""Quick function to format rich Confirmation and options on every exegol interaction"""
if batch:
return default

default_text = "[bright_magenta][Y/n][/bright_magenta]" if default else "[bright_magenta]\[y/N][/bright_magenta]"
formatted_question = f"[bold blue][?][/bold blue] {question} {default_text}"
return rich.prompt.Confirm.ask(
Expand Down
5 changes: 3 additions & 2 deletions exegol/console/TUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ def selectFromTable(cls,
if allow_None:
if Confirm(
f"No {object_name} is available under this name, do you want to {action} it?",
default=True):
default=True,
batch=ParametersManager().batch):
return choice
logger.info(f"[red]Please select one of the available {object_name}s[/red]")
else:
Expand Down Expand Up @@ -364,7 +365,7 @@ def multipleSelectFromTable(cls,
pool.remove(selected)
if len(pool) == 0:
return result
elif not Confirm(f"Do you want to select another {object_subject}?", default=False):
elif not Confirm(f"Do you want to select another {object_subject}?", default=False, batch=ParametersManager().batch):
return result

@classmethod
Expand Down
6 changes: 6 additions & 0 deletions exegol/console/cli/actions/Command.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ def __init__(self):
action="store_true",
default=False,
help="Show no information at all")
self.batch = Option("-b", "--batch",
dest="batch",
action="store_true",
default=False,
help="Enable batch mode (default choice to all prompt)")
self.verbosity = Option("-v", "--verbose",
dest="verbosity",
action="count",
Expand Down Expand Up @@ -102,6 +107,7 @@ def __init__(self):
GroupArg({"arg": self.verbosity, "required": False},
# {"arg": self.interactive_mode, "required": False},
{"arg": self.quiet, "required": False},
{"arg": self.batch, "required": False},
{"arg": self.verify, "required": False},
{"arg": self.offline_mode, "required": False},
{"arg": self.arch, "required": False},
Expand Down
12 changes: 7 additions & 5 deletions exegol/manager/ExegolManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ def uninstall(cls):
all_name = ", ".join([x.getName() for x in images])
if not ParametersManager().force_mode and not Confirm(
f"Are you sure you want to [red]permanently remove[/red] the following images? [orange3][ {all_name} ][/orange3]",
default=False):
default=False,
batch=ParametersManager().batch):
logger.error("Aborting operation.")
return
for img in images:
Expand All @@ -169,7 +170,8 @@ def remove(cls):
all_name = ", ".join([x.name for x in containers])
if not ParametersManager().force_mode and not Confirm(
f"Are you sure you want to [red]permanently remove[/red] the following containers? [orange3][ {all_name} ][/orange3]",
default=False):
default=False,
batch=ParametersManager().batch):
logger.error("Aborting operation.")
return
for c in containers:
Expand Down Expand Up @@ -214,7 +216,7 @@ def print_version(cls):
UpdateManager.checkForWrapperUpdate()
if UpdateManager.isUpdateTag():
logger.empty_line()
if Confirm("An [green]Exegol[/green] update is [orange3]available[/orange3], do you want to update ?", default=True):
if Confirm("An [green]Exegol[/green] update is [orange3]available[/orange3], do you want to update ?", default=True, batch=ParametersManager().batch):
UpdateManager.updateWrapper()
else:
logger.empty_line(log_level=logging.DEBUG)
Expand Down Expand Up @@ -488,13 +490,13 @@ def __createContainer(cls, name: Optional[str]) -> ExegolContainer:
ExegolTUI.printContainerRecap(model)
if cls.__interactive_mode:
if not model.image.isUpToDate() and \
Confirm("Do you want to [green]update[/green] the selected image?", False):
Confirm("Do you want to [green]update[/green] the selected image?", False, batch=ParametersManager().batch):
image = UpdateManager.updateImage(model.image.getName())
if image is not None:
model.image = image
ExegolTUI.printContainerRecap(model)
command_options = []
while not Confirm("Is the container configuration [green]correct[/green]?", default=True):
while not Confirm("Is the container configuration [green]correct[/green]?", default=True, batch=ParametersManager().batch):
command_options = model.config.interactiveConfig(model.name)
ExegolTUI.printContainerRecap(model)
logger.info(f"Command line of the configuration: "
Expand Down
6 changes: 3 additions & 3 deletions exegol/manager/UpdateManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def __askToBuild(cls, tag: str) -> Optional[ExegolImage]:
"""Build confirmation process and image building"""
# Need confirmation from the user before starting building.
if ParametersManager().build_profile is not None or \
Confirm("Do you want to build locally a custom image?", default=False):
Confirm("Do you want to build locally a custom image?", default=False, batch=ParametersManager().batch):
return cls.buildAndLoad(tag)
return None

Expand All @@ -117,7 +117,7 @@ def updateImageSource(cls) -> bool:
def updateResources(cls) -> bool:
"""Update Exegol-resources from git (submodule)"""
try:
if not ExegolModules().isExegolResourcesReady() and not Confirm('Do you want to update exegol resources.', default=True):
if not ExegolModules().isExegolResourcesReady() and not Confirm('Do you want to update exegol resources.', default=True, batch=ParametersManager().batch):
return False
return cls.__updateGit(ExegolModules().getResourcesGit())
except CancelOperation:
Expand Down Expand Up @@ -305,7 +305,7 @@ def __buildSource(cls, build_name: Optional[str] = None) -> str:
# Ask to update git
try:
if ExegolModules().getSourceGit().isAvailable and not ExegolModules().getSourceGit().isUpToDate() and \
Confirm("Do you want to update image sources (in order to update local build profiles)?", default=True):
Confirm("Do you want to update image sources (in order to update local build profiles)?", default=True, batch=ParametersManager().batch):
cls.updateImageSource()
except AssertionError:
# Catch None git object assertions
Expand Down
37 changes: 20 additions & 17 deletions exegol/model/ContainerConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,14 @@ def interactiveConfig(self, container_name: str) -> List[str]:
# Workspace config
if Confirm(
"Do you want to [green]share[/green] your [blue]current host working directory[/blue] in the new container's worskpace?",
default=False):
default=False,
batch=ParametersManager().batch):
self.enableCwdShare()
command_options.append("-cwd")
elif Confirm(
f"Do you want to [green]share[/green] [blue]a host directory[/blue] in the new container's workspace [blue]different than the default one[/blue] ([magenta]{UserConfig().private_volume_path / container_name}[/magenta])?",
default=False):
default=False,
batch=ParametersManager().batch):
while True:
workspace_path = Prompt.ask("Enter the path of your workspace")
if Path(workspace_path).expanduser().is_dir():
Expand All @@ -222,67 +224,67 @@ def interactiveConfig(self, container_name: str) -> List[str]:

# GUI Config
if self.__enable_gui:
if Confirm("Do you want to [orange3]disable[/orange3] [blue]GUI[/blue]?", False):
if Confirm("Do you want to [orange3]disable[/orange3] [blue]GUI[/blue]?", False, batch=ParametersManager().batch):
self.__disableGUI()
elif Confirm("Do you want to [green]enable[/green] [blue]GUI[/blue]?", False):
elif Confirm("Do you want to [green]enable[/green] [blue]GUI[/blue]?", False, batch=ParametersManager().batch):
self.enableGUI()
# Command builder info
if not self.__enable_gui:
command_options.append("--disable-X11")

# Timezone config
if self.__share_timezone:
if Confirm("Do you want to [orange3]remove[/orange3] your [blue]shared timezone[/blue] config?", False):
if Confirm("Do you want to [orange3]remove[/orange3] your [blue]shared timezone[/blue] config?", False, batch=ParametersManager().batch):
self.__disableSharedTimezone()
elif Confirm("Do you want to [green]share[/green] your [blue]host's timezone[/blue]?", False):
elif Confirm("Do you want to [green]share[/green] your [blue]host's timezone[/blue]?", False, batch=ParametersManager().batch):
self.enableSharedTimezone()
# Command builder info
if not self.__share_timezone:
command_options.append("--disable-shared-timezones")

# my-resources config
if self.__my_resources:
if Confirm("Do you want to [orange3]disable[/orange3] [blue]my-resources[/blue]?", False):
if Confirm("Do you want to [orange3]disable[/orange3] [blue]my-resources[/blue]?", False, batch=ParametersManager().batch):
self.__disableMyResources()
elif Confirm("Do you want to [green]activate[/green] [blue]my-resources[/blue]?", False):
elif Confirm("Do you want to [green]activate[/green] [blue]my-resources[/blue]?", False, batch=ParametersManager().batch):
self.enableMyResources()
# Command builder info
if not self.__my_resources:
command_options.append("--disable-my-resources")

# Exegol resources config
if self.__exegol_resources:
if Confirm("Do you want to [orange3]disable[/orange3] the [blue]exegol resources[/blue]?", False):
if Confirm("Do you want to [orange3]disable[/orange3] the [blue]exegol resources[/blue]?", False, batch=ParametersManager().batch):
self.disableExegolResources()
elif Confirm("Do you want to [green]activate[/green] the [blue]exegol resources[/blue]?", False):
elif Confirm("Do you want to [green]activate[/green] the [blue]exegol resources[/blue]?", False, batch=ParametersManager().batch):
self.enableExegolResources()
# Command builder info
if not self.__exegol_resources:
command_options.append("--disable-exegol-resources")

# Network config
if self.__network_host:
if Confirm("Do you want to use a [blue]dedicated private network[/blue]?", False):
if Confirm("Do you want to use a [blue]dedicated private network[/blue]?", False, batch=ParametersManager().batch):
self.setNetworkMode(False)
elif Confirm("Do you want to share the [green]host's[/green] [blue]networks[/blue]?", False):
elif Confirm("Do you want to share the [green]host's[/green] [blue]networks[/blue]?", False, batch=ParametersManager().batch):
self.setNetworkMode(True)
# Command builder info
if not self.__network_host:
command_options.append("--disable-shared-network")

# Shell logging config
if self.__shell_logging:
if Confirm("Do you want to [green]enable[/green] automatic [blue]shell logging[/blue]?", False):
if Confirm("Do you want to [green]enable[/green] automatic [blue]shell logging[/blue]?", False, batch=ParametersManager().batch):
self.__disableShellLogging()
elif Confirm("Do you want to [orange3]disable[/orange3] automatic [blue]shell logging[/blue]?", False):
elif Confirm("Do you want to [orange3]disable[/orange3] automatic [blue]shell logging[/blue]?", False, batch=ParametersManager().batch):
self.enableShellLogging()
# Command builder info
if self.__shell_logging:
command_options.append("--log")

# VPN config
if self.__vpn_path is None and Confirm(
"Do you want to [green]enable[/green] a [blue]VPN[/blue] for this container", False):
"Do you want to [green]enable[/green] a [blue]VPN[/blue] for this container", False, batch=ParametersManager().batch):
while True:
vpn_path = Prompt.ask('Enter the path to the OpenVPN config file')
if Path(vpn_path).expanduser().is_file():
Expand All @@ -291,7 +293,7 @@ def interactiveConfig(self, container_name: str) -> List[str]:
else:
logger.error("No config files were found.")
elif self.__vpn_path and Confirm(
"Do you want to [orange3]remove[/orange3] your [blue]VPN configuration[/blue] in this container", False):
"Do you want to [orange3]remove[/orange3] your [blue]VPN configuration[/blue] in this container", False, batch=ParametersManager().batch):
self.__disableVPN()
if self.__vpn_path:
command_options.append(f"--vpn {self.__vpn_path}")
Expand Down Expand Up @@ -453,7 +455,8 @@ def enableVPN(self, config_path: Optional[str] = None):
if self.__network_host:
logger.warning("Using the host network mode with a VPN profile is not recommended.")
if not Confirm(f"Are you sure you want to configure a VPN container based on the host's network?",
default=False):
default=False,
batch=ParametersManager().batch):
logger.info("Changing network mode to custom")
self.setNetworkMode(False)
# Add NET_ADMIN capabilities, this privilege is necessary to mount network tunnels
Expand Down
5 changes: 3 additions & 2 deletions exegol/model/ExegolContainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def __removeVolume(self):
list_files = os.listdir(volume_path)
except PermissionError:
if Confirm(f"Insufficient permission to view workspace files {volume_path}, "
f"do you still want to delete them?", default=False):
f"do you still want to delete them?", default=False, batch=ParametersManager().batch):
# Set list_files as empty to skip user prompt again
list_files = []
else:
Expand All @@ -217,7 +217,8 @@ def __removeVolume(self):
if len(list_files) > 0:
# Directory is not empty
if not Confirm(f"Workspace [magenta]{volume_path}[/magenta] is not empty, do you want to delete it?",
default=False):
default=False,
batch=ParametersManager().batch):
# User can choose not to delete the workspace on the host
return
# Try to remove files from the host with user permission (work only without sub-directory)
Expand Down
4 changes: 2 additions & 2 deletions exegol/model/ExegolModules.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __init_resources_repo(self):
if ParametersManager().offline_mode:
logger.error("It's not possible to install 'Exegol resources' in offline mode. Skipping the operation.")
raise CancelOperation
if Confirm("Do you want to download exegol resources? (~1G)", True):
if Confirm("Do you want to download exegol resources? (~1G)", True, batch=ParametersManager().batch):
# If git wrapper is ready and exegol resources location is the corresponding submodule, running submodule update
# if not, git clone resources
if UserConfig().exegol_resources_path == ConstantConfig.src_root_path_obj / 'exegol-resources' and \
Expand Down Expand Up @@ -92,5 +92,5 @@ def __warningExcludeFolderAV(directory: Union[str, Path]):
"""Generic procedure to warn the user that not antivirus compatible files will be downloaded and that
the destination folder should be excluded from the scans to avoid any problems"""
logger.warning(f"If you are using an [orange3][g]Anti-Virus[/g][/orange3] on your host, you should exclude the folder {directory} before starting the download.")
while not Confirm(f"Are you ready to start the download?", True):
while not Confirm(f"Are you ready to start the download?", True, batch=ParametersManager().batch):
pass
Loading