-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-wizard.py
More file actions
208 lines (164 loc) · 6.63 KB
/
build-wizard.py
File metadata and controls
208 lines (164 loc) · 6.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/usr/bin/env python3
#== Copyright ==#
# (C) 2019-2020 Fascode Network
#== Import ==#
import gi, subprocess, sys, threading
gi.require_version("Gtk", "3.0")
from gi.repository import GLib, Gtk, GObject
#== Main Window ==#
class MainWindow(Gtk.Window):
#= Fuction =#
def __init__(self):
def yn(name):
y = Gtk.RadioButton.new_with_label_from_widget(None, "Yes")
y.connect("toggled", self.on_button_toggled, name, True)
n = Gtk.RadioButton.new_with_mnemonic_from_widget(y, "No")
n.connect("toggled", self.on_button_toggled, name, False)
return y, n
def combobox(name, list):
list_store = Gtk.ListStore(int, str)
for num in range(len(list)):
list_store.append([num, list[num]])
combo = Gtk.ComboBox.new_with_model_and_entry(list_store)
combo.connect("changed", self.on_combo_changed, name)
combo.set_entry_text_column(1)
combo.set_active(0)
return combo
#-- Create Window --#
Gtk.Window.__init__(self, title="build wizard")
#-- Define --#
self.bool = {"plymouth": True, "japanese": True}
self.selected = {"build": "native"}
#-- Sub Layout 1 --#
#- Create -#
sub_layout1 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5)
#- Labels -#
label1 = Gtk.Label("select desktop environment")
label2 = Gtk.Label("select kernel")
#- Comboboxes -#
de = combobox("de", ["xfce", "plasma", "lxde"])
kernel= combobox("kernel", ["zen", "linux", "lts", "lqx", "ck", "rt", "rt-lts", "xanmod-lts"])
#- Buttons & Add -#
for name in "plymouth", "japanese":
y, n = yn(name)
subs_layout = Gtk.Box(spacing=5)
subs_layout.pack_start(y, True, True, 30)
subs_layout.pack_start(n, True, True, 30)
label = Gtk.Label("Enable" + " " + name + "?")
sub_layout1.pack_start(label, True, True, 5)
sub_layout1.pack_start(subs_layout, True, True, 5)
#- Add -#
for name in label1, de, label2, kernel:
sub_layout1.pack_start(name, True, True, 5)
#-- Sub Layout 2 --#
#- Create -#
sub_layout2 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5)
#- Labels -#
label1 = Gtk.Label("select compression")
label2 = Gtk.Label("user name")
label3 = Gtk.Label("password")
#- Combobox -#
comp = combobox("comp", ["zstd", "lzma", "lzo", "lz4", "xz", "gzip"])
#- Entrys -#
self.usr = Gtk.Entry()
self.usr.set_text("alter")
self.passwd = Gtk.Entry()
self.passwd.set_visibility(False)
self.passwd.set_text("alter")
#- Button -#
showpasswd = Gtk.ToggleButton("Show password")
showpasswd.connect("toggled", self.on_button_toggled, "1")
#- Add -#
for name in label1, comp, label2, self.usr, label3, self.passwd, showpasswd:
sub_layout2.pack_start(name, True, True, 5)
#-- Sub Layout 3 --#
#- Create -#
sub_layout3 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5)
#- Label -#
label = Gtk.Label("select build type")
#- Button -#
button1 = Gtk.RadioButton.new_with_label_from_widget(None, "native")
button1.connect("toggled", self.select_build, "native")
#- Add -#
sub_layout3.pack_start(label, True, True, 5)
sub_layout3.pack_start(button1, True, True, 5)
#- Buttons & Add -#
for name in "docker", "ssh":
button = Gtk.RadioButton.new_with_mnemonic_from_widget(button1, name)
button.connect("toggled", self.select_build, name)
sub_layout3.pack_start(button, True, True, 5)
#-- Grid --#
#- Create -#
grid = Gtk.Grid(column_spacing=10, row_spacing=10)
#- Progressbar -#
self.progressbar = Gtk.ProgressBar()
#- Button -#
build = Gtk.Button("build")
build.connect("clicked", self.on_click_build)
#- Add -#
grid.attach(sub_layout1, 0, 0, 1, 1)
grid.attach(sub_layout2, 1, 0, 1, 1)
grid.attach(sub_layout3, 2, 0, 1, 1)
grid.attach(self.progressbar, 0, 1, 2, 1)
grid.attach(build, 2, 1, 1, 1)
#-- Layout --#
#- Create -#
layout = Gtk.Box(spacing=10)
#- Add -#
layout.pack_start(grid, True, True, 10)
#-- Main Layout --#
#- Create -#
main_layout = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
#- Add -#
main_layout.pack_start(layout, True, True, 10)
#-- Add Main Window --#
self.add(main_layout)
def on_button_toggled(self, button, name):
if button.get_active():
self.passwd.set_visibility(True)
else:
self.passwd.set_visibility(False)
def on_combo_changed(self, combo, name):
self.selected[name] = combo.get_model()[combo.get_active_iter()][1]
def select_build(self, button, name):
self.selected["build"] = name
def on_click_build(self, button):
cmd = ["sudo", "./build.sh"]
if self.selected["build"] == "native":
if self.bool["plymouth"]:
cmd.append("-b")
if self.bool["japanese"]:
cmd.append("-j")
for name in "-k", self.selected["kernel"], "-c", self.selected["comp"], "-u", self.usr.get_text(), "-p", self.passwd.get_text():
cmd.append(name)
self.run_cmd(cmd)
else:
self.progressbar.set_show_text(1)
self.progressbar.set_text("not supported!")
print("not supported!")
def run_cmd(self, cmd):
def update(line):
self.progressbar.pulse()
self.progressbar.set_show_text(1)
self.progressbar.set_ellipsize(True)
self.progressbar.set_text(line)
return False
def run():
run = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr = subprocess.STDOUT)
while run.poll() is None:
line = run.stdout.readline().decode('utf-8')
if line:
yield line
def echo():
for line in run():
GLib.idle_add(update, line)
sys.stdout.write(line)
thread = threading.Thread(target=echo)
thread.daemon = True
thread.start()
#== Run ==#
if __name__ == "__main__":
win = MainWindow()
win.show_all()
win.connect("destroy", Gtk.main_quit)
Gtk.main()