-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Works on all three UIs offers a generic function to ask a question that platform independent. If the user fails to offer a response, the installer will terminate. In the GUI this still works, however it may not be desirable to prompt the user for each question. So long as we don't attempt to access the variable before the user has had a chance to put in their preferences it will not prompt them Changed the GUI to gray out the other widgets if the product is not selected. start_ensure_config is called AFTER product is set, if it's called before it attempts to figure out which platform it's on, prompting the user with an additional dialog (not ideal, but acceptable)
- Loading branch information
1 parent
0def2e5
commit 82d0c94
Showing
6 changed files
with
243 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import abc | ||
from typing import Optional | ||
|
||
from ou_dedetai import config | ||
|
||
|
||
class App(abc.ABC): | ||
def __init__(self, **kwargs) -> None: | ||
self.conf = Config(self) | ||
|
||
def ask(self, question: str, options: list[str]) -> str: | ||
"""Askes the user a question with a list of supplied options | ||
Returns the option the user picked. | ||
If the internal ask function returns None, the process will exit with an error code 1 | ||
""" | ||
if options is not None and self._exit_option is not None: | ||
options += [self._exit_option] | ||
answer = self._ask(question, options) | ||
if answer == self._exit_option: | ||
answer = None | ||
|
||
if answer is None: | ||
exit(1) | ||
|
||
return answer | ||
|
||
_exit_option: Optional[str] = "Exit" | ||
|
||
@abc.abstractmethod | ||
def _ask(self, question: str, options: list[str] = None) -> Optional[str]: | ||
"""Implementation for asking a question pre-front end | ||
If you would otherwise return None, consider shutting down cleanly, | ||
the calling function will exit the process with an error code of one | ||
if this function returns None | ||
""" | ||
raise NotImplementedError() | ||
|
||
def _hook_product_update(self, product: Optional[str]): | ||
"""A hook for any changes the individual apps want to do when a platform changes""" | ||
pass | ||
|
||
class Config: | ||
def __init__(self, app: App) -> None: | ||
self.app = app | ||
|
||
@property | ||
def faithlife_product(self) -> str: | ||
"""Wrapper function that ensures that ensures the product is set | ||
if it's not then the user is prompted to choose one.""" | ||
if not config.FLPRODUCT: | ||
question = "Choose which FaithLife product the script should install: " # noqa: E501 | ||
options = ["Logos", "Verbum"] | ||
config.FLPRODUCT = self.app.ask(question, options) | ||
self.app._hook_product_update(config.FLPRODUCT) | ||
return config.FLPRODUCT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.