|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | + |
| 4 | +# This file is part of PrawnOS (https://www.prawnos.com) |
| 5 | +# Copyright (c) 2022 Hal Emmerich <[email protected]> |
| 6 | + |
| 7 | +# PrawnOS is free software: you can redistribute it and/or modify |
| 8 | +# it under the terms of the GNU General Public License version 2 |
| 9 | +# as published by the Free Software Foundation. |
| 10 | + |
| 11 | +# PrawnOS is distributed in the hope that it will be useful, |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +# GNU General Public License for more details. |
| 15 | + |
| 16 | +# You should have received a copy of the GNU General Public License |
| 17 | +# along with PrawnOS. If not, see <https://www.gnu.org/licenses/>. |
| 18 | + |
| 19 | + |
| 20 | +import click |
| 21 | +from prompt_toolkit.shortcuts import button_dialog |
| 22 | +from tools import get_device_model |
| 23 | + |
| 24 | +# option helpers |
| 25 | +def validate_res(res, expected): |
| 26 | + if res not in expected: |
| 27 | + raise ValueError(f"{res} is not a valid option, expected one of {expected}") |
| 28 | + |
| 29 | +# option handlers |
| 30 | +de_answers = ["xfce", "gnome"] |
| 31 | +de_hint ="Choose a desktop envorionment to install. If you are unsure, pick Xfce" |
| 32 | +def ask_de(options): |
| 33 | + result = None |
| 34 | + if (opt := options.get("de", None)): |
| 35 | + result = opt |
| 36 | + else: |
| 37 | + result = button_dialog( |
| 38 | + title='Install Desktop Environment', |
| 39 | + text=de_hint, |
| 40 | + buttons=[ |
| 41 | + ('Xfce', "xfce"), |
| 42 | + ('Gnome', "gnome"), |
| 43 | + ], |
| 44 | + ).run() |
| 45 | + validate_res(result, de_answers) |
| 46 | + return result |
| 47 | + |
| 48 | + |
| 49 | +#TODO ensure all options end up in the all_answers map |
| 50 | +all_answers = {"de" : de_answers} |
| 51 | +def ask_all(options): |
| 52 | + answers = all_answers |
| 53 | + answers["de"] = ask_de(options) |
| 54 | + |
| 55 | + return answers |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | +def main(options): |
| 61 | + #TODO take map of user prompted options to skip prompting |
| 62 | + answers = ask_all(options) |
| 63 | + |
| 64 | + model = get_device_model() |
| 65 | + print(model) |
| 66 | + print(answers) |
| 67 | + |
| 68 | +@click.command() |
| 69 | +@click.option('--options_file', default=None) |
| 70 | +def cli(options_file): |
| 71 | + if options_file: |
| 72 | + #TODO load the json options file if provided |
| 73 | + pass |
| 74 | + |
| 75 | + options = {} |
| 76 | + main(options) |
| 77 | + |
| 78 | +if __name__ == '__main__': |
| 79 | + cli() |
| 80 | + |
0 commit comments