Skip to content

Commit de4715c

Browse files
committed
begin work on python version of install script
improve maintainability, readability, and automation-ability over the bash counterparts
1 parent d7444cc commit de4715c

File tree

4 files changed

+135
-0
lines changed

4 files changed

+135
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ PrawnOS-initramfs.cpio.gz
33
PrawnOS-Shiba-*
44
.*.swp
55
tmp.*
6+
__pycache__/
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
21+
22+
device_veyron_speedy="Google Speedy"
23+
device_veyron_minnie="Google Minnie"
24+
device_veyron_mickey="Google Mickey"
25+
device_gru_kevin="Google Kevin"
26+
device_gru_bob="Google Bob"

scripts/InstallScripts/tools.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
def get_device_model():
21+
f = open("/sys/firmware/devicetree/base/model", "r")
22+
model = f.read().strip()
23+
return model
24+
25+
26+
#TODO add wrapper for apt
27+
# maybe use
28+
# https://apt-team.pages.debian.net/python-apt/library/index.html

0 commit comments

Comments
 (0)