-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
1228 lines (1089 loc) · 54.7 KB
/
main.py
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# RebornOS Welcome
# Please refer to the file `LICENSE` in the main directory for license information.
# For a high level documentation, please visit https://github.com/RebornOS-Team/rebornos-welcome
# AUTHORS
# 1. Shivanand Pattanshetti ([email protected])
# 2.
# IMPORTS
import os # for filepath related methods
import gi # Python GObject introspection module which contains Python bindings and support for Gtk
gi.require_version('Gtk', '3.0') # make sure that the Gtk version is at the required level
from gi.repository import Gtk, GLib, GdkPixbuf, Gdk # Gtk related modules for the graphical interface
from argparse import Namespace
from typing import List, Union, Tuple, Optional, Any
from pathlib import Path
import logging
import functools
import sys
from pysetting import JSONConfiguration
from pyrunning import LoggingHandler, LogMessage, Command, LoggingLevel, BatchJob, Function
logger = logging.getLogger('rebornos_welcome.ui.gtk.code'+'.'+ Path(__file__).stem)
# THE EVENT HANDLER
class Main:
"""
Specify how this particular Gtk container handles user interaction events.
The names of handler functions (also called `signals` in Gtk) can be assigned in `Glade` under "Signals
TODO
----
- Splash screen before loading the pages and the main window, to avoid delay in getting some UI up for the user
"""
log_color: dict = {
"CRITICAL": "#a40000" ,
"ERROR": "#ff0000",
"EXCEPTION": "#ff0000",
"WARNING": "#ffa500",
"INFO": "#0000ff",
"DEBUG": "#808080",
"NOTSET": "#808080",
"": "#808080",
None: "#808080"
}
def __init__(self, commandline_arguments: Namespace, application_settings: JSONConfiguration) -> None:
"""
Initialize the main window in Gtk
Parameters
----------
commandline_arguments: Namespace
Contains the command line arguments
"""
self.is_iso = False
self.initialized = False
self.expander_deactivate_clicked = False
self.expander_previous_height=-1
self.commandline_arguments = commandline_arguments
self.logging_handler = LoggingHandler(
logger=logger,
logging_functions=[
self.log_console,
self.log_status,
]
)
self.application_settings: JSONConfiguration = application_settings
LogMessage.Info("Loading CSS styles...").write(self.logging_handler)
provider = Gtk.CssProvider()
provider.load_from_path("user_interface/gtk/forms/style.css")
Gtk.StyleContext.add_provider_for_screen(
Gdk.Screen.get_default(),
provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
)
LogMessage.Info("Creating a Gtk Builder and importing the UI from glade files...").write(self.logging_handler)
self.builder = Gtk.Builder()
self.builder.add_from_file( # extract the main form from the glade file
os.path.join(
"user_interface",
commandline_arguments.user_interface,
"forms",
"main.glade"
)
)
self.builder.connect_signals(self) # connect the signals from the Gtk forms to our event handlers (which are all defined in a class)
self.builder.get_object("main_window").set_title("Welcome to RebornOS!")
self.console_buffer = self.builder.get_object("console_text_view").get_buffer()
self.status_label = self.builder.get_object("status_label")
self.builder.get_object("console_text_view").modify_base(Gtk.StateFlags.NORMAL, Gdk.color_parse('black'))
LogMessage.Debug("Detecting if the application is enabled at startup...").write(self.logging_handler)
if self.application_settings["auto_start_enabled"]:
self.builder.get_object("startup_toggle").set_active(True)
else:
self.builder.get_object("startup_toggle").set_active(False)
self.builder.get_object("green_light").set_visible(True)
self.builder.get_object("red_light").set_visible(True)
self.builder.get_object("show_installinfo_again").set_active(self.settings_safe_get("show_install_info", True))
page_stack = self.builder.get_object("page_stack")
if commandline_arguments.iso:
self.is_iso = True
LogMessage.Info("Running in the 'ISO' mode...").write(self.logging_handler)
self.builder.get_object("main_window").resize(1,1) # resize the window to fit contents
self.show_update_toggle = self.settings_safe_get("show_update_toggle", True)
if not self.show_update_toggle:
self.builder.get_object("installer_update_switch_box").hide()
LogMessage.Info("Update toggle is hidden...").write(self.logging_handler)
self.show_git_toggle = self.settings_safe_get("show_git_toggle", True)
if not self.show_git_toggle:
self.builder.get_object("git_switch_box").hide()
LogMessage.Info("Git toggle is hidden...").write(self.logging_handler)
self.use_github_toggle = self.settings_safe_get("show_from_github_toggle", True)
if not self.use_github_toggle:
self.builder.get_object("use_github_switch_box").hide()
LogMessage.Info("\"from GitHub\" toggle is hidden...").write(self.logging_handler)
self.installer_package_name_stub = self.settings_safe_get("installer_package_name_stub", "calamares-core")
LogMessage.Info(f"Set to detect installer package name {self.installer_package_name_stub}...").write(self.logging_handler)
self.installer_config_package_name_stub = self.settings_safe_get("installer_config_package_name_stub", "calamares-configuration")
LogMessage.Info(f"Set to detect installer config package name {self.installer_config_package_name_stub}...").write(self.logging_handler)
self.installer_github_url_stub = self.settings_safe_get("installer_github_url_stub", "rebornos-team/calamares-core")
self.installer_config_github_url_stub = self.settings_safe_get("installer_config_github_url_stub", "rebornos-team/calamares-configuration")
LogMessage.Info("Loading the 'Install' tab...").write(self.logging_handler)
install_page = self.builder.get_object("install_page")
page_stack.add_titled(
child = install_page,
name = "install_page",
title = "Install"
)
self.builder.get_object("startup_toggle").hide()
self.builder.get_object("startup_toggle_text").hide()
rebornos_iso_welcome_icon_path = "media/icons/rebornos_iso_welcome_logo.svg"
self.builder.get_object("main_window").set_icon_from_file(rebornos_iso_welcome_icon_path)
about_dialog = self.builder.get_object("about")
about_dialog.set_icon_from_file(rebornos_iso_welcome_icon_path)
about_dialog.set_title("About RebornOS ISO Welcome Application")
self.builder.get_object("internet_check").set_active(self.settings_safe_get("internet_check_toggled", True))
self.builder.get_object("memory_check").set_active(self.settings_safe_get("memory_check_toggled", True))
self.builder.get_object("storage_check").set_active(self.settings_safe_get("storage_check_toggled", True))
self.builder.get_object("isp_dns_radio_button").set_active(self.settings_safe_get("isp_dns_toggled", True))
self.builder.get_object("cloudflare_dns_radio_button").set_active(self.settings_safe_get("cloudflare_dns_toggled", False))
self.builder.get_object("google_dns_radio_button").set_active(self.settings_safe_get("google_dns_toggled", False))
self.builder.get_object("about_application_name").set_label("RebornOS ISO Welcome Application")
self.builder.get_object("about_logo").set_from_file(rebornos_iso_welcome_icon_path)
else:
self.builder.get_object("about").set_title("About RebornOS Welcome Application")
LogMessage.Info("Loading the 'Links' tab...").write(self.logging_handler)
links_page = self.builder.get_object("links_page")
page_stack.add_titled(
child = links_page,
name = "links_page",
title = "Links"
)
LogMessage.Info("Loading the 'Utilities' tab...").write(self.logging_handler)
utilities_page = self.builder.get_object("utilities_page")
page_stack.add_titled(
child = utilities_page,
name = "utilities_page",
title = "Utilities"
)
LogMessage.Info("Displaying the main window...").write(self.logging_handler)
self.builder.get_object("main_window").resize(1,1) # resize the window to fit contents
self.builder.get_object("main_window").show() # get the main form object and make it visible
self.initialized = True
LogMessage.Info("Starting the event loop...").write(self.logging_handler)
Gtk.main() # start the GUI event loop
def settings_safe_get(self, key: str, default_value: Any) -> Any :
try:
return self.application_settings[key]
except KeyError as _:
self.application_settings[key] = default_value
self.application_settings.write_data()
return default_value
def get_confirmation_from_dialog(self, message: str) -> bool:
message_dialog = Gtk.MessageDialog(
parent= self.builder.get_object("main_window"),
flags= Gtk.DialogFlags.DESTROY_WITH_PARENT,
type= Gtk.MessageType.QUESTION,
buttons= Gtk.ButtonsType.YES_NO,
message_format= message
)
image = Gtk.Image()
image.set_from_stock(Gtk.STOCK_DIALOG_QUESTION, Gtk.IconSize.DIALOG)
image.show()
message_dialog.set_image(image)
user_response = message_dialog.run()
message_dialog.destroy()
return user_response == Gtk.ResponseType.YES
def is_any_package_missing(
self,
package_name: Union[str, List[str]]
):
package_lookup_command = None
if type(package_name) == str:
package_lookup_command = Command(
[
"pacman",
"-Q",
package_name
]
)
elif type(package_name) == list:
package_lookup_command = Command(
[
"pacman",
"-Q",
*package_name
]
)
LogMessage.Debug("Checking if missing: " + str(package_name)).write(logging_handler=self.logging_handler)
if package_lookup_command is not None:
output = package_lookup_command.run_and_wait()
output = output.strip()
package_lookup_return_code = package_lookup_command.return_code
LogMessage.Debug("Package lookup command output: " + output).write(logging_handler=self.logging_handler)
LogMessage.Debug("Package lookup command return code: " + str(package_lookup_return_code)).write(logging_handler=self.logging_handler)
if package_lookup_return_code == 0:
LogMessage.Info("Package(s) found installed: " + str(package_name)).write(logging_handler=self.logging_handler)
return False
else:
LogMessage.Debug("Package(s) not found installed: " + str(package_name)).write(logging_handler=self.logging_handler)
return True
else:
LogMessage.Warning("Wrong package_name format: " + str(package_name)).write(logging_handler=self.logging_handler)
return True
def run_executable(
self,
executable_name: Union[str, List[str]],
detached: bool = False,
batch_job: BatchJob = None
) -> Optional[BatchJob]:
import subprocess
import shlex
executable_name_joined: str = ""
if type(executable_name) == list:
executable_name_joined = ' '.join(executable_name)
elif type(executable_name) == str:
executable_name_joined = str(executable_name)
else:
executable_name_joined = str(executable_name)
launch_message = LogMessage.Info("Launching `" + executable_name_joined + "`...")
if detached:
run_command = Function(
subprocess.Popen,
shlex.split(executable_name_joined),
start_new_session=True
)
else:
run_command = Command(
shlex.split(executable_name_joined)
)
if batch_job is None:
launch_message.write(logging_handler=self.logging_handler)
run_command.run_log_and_wait(self.logging_handler)
return None
else:
batch_job += launch_message
batch_job += run_command
return batch_job
def is_package_old(self, single_package_name: str) -> bool:
version_check_command = Command.Shell(
f"vercmp \"$(pacman -Q {single_package_name} | cut -d \' \' -f 2)\" \"$(pacman -Ss {single_package_name} | head -n 1 | cut -d \' \' -f 2)\""
)
try:
version_check_command_output = version_check_command.run_and_wait().strip()
if int(version_check_command_output) < 0:
return True
else:
return False
except:
return True # For when the package is not found
def is_new_github_package_available(self, single_package_name: str, url_stub: str) -> Tuple[bool, str, str]:
import requests
local_version = Command.Shell(
f"pacman -Q {single_package_name} | cut -d \' \' -f 2 | cut -d \'-\' -f 1"
).run_and_wait().strip()
github_version = ""
try:
github_version = requests.get(f'https://api.github.com/repos/{url_stub}/releases/latest').json()["tag_name"];
except:
return (False, local_version, github_version)
if github_version[0] == 'v':
github_version = github_version[1:].strip()
version_check_command = Command.Shell(
f"vercmp {local_version} {github_version}"
)
try:
version_check_command_output = version_check_command.run_and_wait().strip()
if int(version_check_command_output) < 0:
return (True, local_version, github_version)
else:
return (False, local_version, github_version)
except:
return (False, local_version, github_version)
def filter_old_packages(
self,
package_names: Union[str, List[str]]
) -> Union[str, List[str]]:
if type(package_names) == list:
old_package_names = list(
filter(self.is_package_old, package_names)
)
return old_package_names
elif type(package_names) == str:
if self.is_package_old(str(package_names)):
return str(package_names)
else:
return ""
return []
def install_package(
self,
package_name: Union[str, List[str]],
post_install_command: Optional[Union[str, List[str]]] = None,
update: bool= False,
batch_job: BatchJob = None,
) -> Optional[BatchJob]:
import subprocess
import shlex
if update:
LogMessage.Debug("Checking if newer versions exist for: " + str(package_name)).write(logging_handler=self.logging_handler)
Command(["pkexec", "pacman", "-Sy"]).run_log_and_wait(self.logging_handler)
package_name = self.filter_old_packages(package_name)
LogMessage.Debug("Package(s) which need updates: " + str(package_name)).write(logging_handler=self.logging_handler)
package_name_joined: str = ""
if type(package_name) == list:
package_name_joined = ' '.join(package_name)
elif type(package_name) == str:
package_name_joined = str(package_name)
else:
package_name_joined = str(package_name)
package_name_joined = package_name_joined.strip()
if package_name_joined == "":
return batch_job
install_message = LogMessage.Info("Trying to update: `" + str(package_name) + "`...")
# install_command = Command.Shell(
# "pkexec bash -c \"pacman -S --needed --noconfirm " + package_name_joined + "\""
# )
install_command = Command(
[
"pkexec",
"pacman",
"-Sy",
"--needed",
"--noconfirm" ,
*shlex.split(package_name_joined),
]
)
else:
package_name_joined: str = ""
if type(package_name) == list:
package_name_joined = ' '.join(package_name)
elif type(package_name) == str:
package_name_joined = str(package_name)
else:
package_name_joined = str(package_name)
install_message = LogMessage.Info("Trying to install: `" + str(package_name) + "`...")
# install_command = Command.Shell(
# "pkexec bash -c \"pacman -Sy --needed --noconfirm " + package_name_joined + "\""
# )
install_command = Command(
[
"pkexec",
"pacman",
"-S",
"--needed",
"--noconfirm" ,
*shlex.split(package_name_joined),
]
)
if batch_job is None:
install_message.write(logging_handler=self.logging_handler)
install_command.run_log_and_wait(self.logging_handler)
if post_install_command is not None:
Command(post_install_command).run_log_and_wait(self.logging_handler)
return None
else:
batch_job += install_message
batch_job += install_command
if post_install_command is not None:
batch_job += Command(post_install_command)
return batch_job
def uninstall_package(
self,
package_name: Union[str, List[str]],
batch_job: BatchJob = None,
) -> Optional[BatchJob]:
import subprocess
import shlex
package_name_joined: str = ""
if type(package_name) == list:
filtered_package_list = list(
filter(
lambda p: not self.is_any_package_missing(p),
package_name
)
)
if not filtered_package_list:
return
package_name_joined = ' '.join(filtered_package_list)
elif type(package_name) == str:
if self.is_any_package_missing(package_name):
return None
package_name_joined = str(package_name)
else:
package_name_joined = str(package_name)
uninstall_message = LogMessage.Info("Trying to uninstall: `" + str(package_name) + "`...")
# uninstall_command = Command.Shell(
# "pkexec bash -c \"pacman -Rdd --noconfirm " + package_name_joined + "\""
# )
uninstall_command = Command(
[
"pkexec",
"pacman",
"-Rdd",
"--noconfirm" ,
*shlex.split(package_name_joined),
]
)
if batch_job is None:
uninstall_message.write(logging_handler=self.logging_handler)
uninstall_command.run_log_and_wait(self.logging_handler)
return None
else:
batch_job += uninstall_message
batch_job += uninstall_command
return batch_job
def launch_third_party_utility(
self,
package_name: Union[str, List[str]],
executable_name: Union[str, List[str]],
post_install_command: Optional[Union[str, List[str]]] = None,
detached: bool = True,
update: bool = False,
batch_job: BatchJob = None,
) -> BatchJob:
if batch_job is None:
self.display_busy()
batch_job = BatchJob(
logging_handler= self.logging_handler,
post_run_function=functools.partial(
self.display_ready
),
)
if update or self.is_any_package_missing(package_name):
batch_job = self.install_package(
package_name= package_name,
post_install_command= post_install_command,
update= update,
batch_job= batch_job
)
batch_job = self.run_executable(
executable_name= executable_name,
detached= detached,
batch_job= batch_job
)
if batch_job is not None:
batch_job.start()
def log_console(
self,
logging_level: int,
message: str,
*args,
loginfo_filename= "",
loginfo_line_number= -1,
loginfo_function_name= "",
loginfo_stack_info= None,
**kwargs
):
message = message.strip()
if message == "":
return
logging_level_name = LoggingLevel(logging_level).name
# Needed because Gtk doesn't prefer adding stuff on a different thread
GLib.idle_add(
lambda: ( # A temporary nameless function handle to make sure that console_buffer.get_end_iter() is valid by calling it right when the insert() method is called. They are both grouped together. Using GLib.idle_add directly was somehow invalidating get_end_iter(), resulting in runtime errors, which are now fixed
self.console_buffer.insert_markup(
self.console_buffer.get_end_iter(),
"".join(
(
"- ",
"<span color=\"{:s}\">",
logging_level_name.rjust(8, " "),
": ",
"</span>"
)
).format(self.log_color[logging_level_name]),
-1
)
)
)
if LoggingLevel(logging_level) != LoggingLevel.DEBUG:
# Needed because Gtk doesn't prefer adding stuff on a different thread
GLib.idle_add(
lambda: ( # A temporary nameless function handle to make sure that console_buffer.get_end_iter() is valid by calling it right when the insert() method is called. They are both grouped together. Using GLib.idle_add directly was somehow invalidating get_end_iter(), resulting in runtime errors, which are now fixed
self.console_buffer.insert(
self.console_buffer.get_end_iter(),
"".join(
(
message,
# "(", loginfo_filename, " > ", loginfo_function_name, "; ", "Line ", str(loginfo_line_number), ")"
"\n"
)
)
)
)
)
else:
GLib.idle_add(
lambda: ( # A temporary nameless function handle to make sure that console_buffer.get_end_iter() is valid by calling it right when the insert() method is called. They are both grouped together. Using GLib.idle_add directly was somehow invalidating get_end_iter(), resulting in runtime errors, which are now fixed
self.console_buffer.insert_markup(
self.console_buffer.get_end_iter(),
"".join(
(
"<span color=\"{:s}\">",
GLib.markup_escape_text(message),
# "(", loginfo_filename, " > ", loginfo_function_name, "; ", "Line ", str(loginfo_line_number), ")"
"</span>"
"\n",
)
).format(self.log_color[logging_level_name]),
-1,
)
)
)
def log_status(
self,
logging_level: int,
message: str,
*args,
loginfo_filename= "",
loginfo_line_number= -1,
loginfo_function_name= "",
loginfo_stack_info= None,
**kwargs
):
message = message.strip()
if message == "":
return
# logging_level_name = LoggingLevel(logging_level).name
# Needed because Gtk doesn't prefer adding stuff on a different thread
GLib.idle_add(self.status_label.set_text, message)
# def on_refresh_pacman_mirrors(self, _):
# LogMessage.Info("Refreshing pacman mirrors...").write(self.logging_handler)
# command = Command(
# command_strings= [
# "pkexec",
# "sudo",
# "reflector",
# "--latest", "50",
# "--protocol", "https",
# "--sort", "rate",
# "--save", "/etc/pacman.d/mirrorlist",
# ],
# post_start_function= functools.partial(
# LogMessage.Info("Reflector finished... Please check the above messages for errors").write,
# self.logging_handler
# )
# )
# command.run_log_and_wait(self.logging_handler)
def on_main_message_resized(self, label, size):
# A hack needed to wrap text dynamically, instead of Gtk making the window wide to accomodate it
label.set_size_request(size.width -1, -1)
def on_close(self, _):
"""
Quit the graphical interface
Called when the application is closedMainFormHandler
"""
LogMessage.Info("User closed the application. Exiting...").write(self.logging_handler)
# self.logging_handler.abort(wait=False)
Gtk.main_quit() # Quit from the Gtk UI
# exit(0)
def console_expander_activated(self, expander):
expander = self.builder.get_object("console_expander")
if expander.get_expanded():
self.expander_deactivate_clicked = True
def on_console_expander_resized(self, _item1, _item2):
expander = self.builder.get_object("console_expander")
height = expander.get_allocated_height()
if height == self.expander_previous_height:
return
if not self.expander_previous_height:
self.expander_previous_height = -1
if height < self.expander_previous_height and height < 105 and expander.get_expanded():
expander.set_expanded(False)
elif height > self.expander_previous_height and height > 20 and not expander.get_expanded() and self.expander_previous_height != -1:
expander.set_expanded(True)
elif height <= 20:
self.expander_deactivate_clicked = False
self.expander_previous_height = height
def display_busy(self):
green_light = self.builder.get_object("green_light")
green_light.set_from_file("media/icons/grey.svg")
red_light = self.builder.get_object("red_light")
red_light.set_from_file("media/icons/red.svg")
# self.builder.get_object("green_light").set_visible(False)
# self.builder.get_object("red_light").set_visible(False)
def display_ready(self):
green_light = self.builder.get_object("green_light")
green_light.set_from_file("media/icons/green.svg")
red_light = self.builder.get_object("red_light")
red_light.set_from_file("media/icons/grey.svg")
# self.builder.get_object("green_light").set_visible(False)
# self.builder.get_object("red_light").set_visible(False)
def on_about_clicked(self, _):
LogMessage.Debug("Bringing up the \"About\" dialog...").write(self.logging_handler)
self.builder.get_object("about").show_all()
def on_log_clicked(self, _):
LogMessage.Debug("Opening the log on the default editor...").write(self.logging_handler)
self.launch_third_party_utility(
package_name= "xdg-utils",
executable_name = ["xdg-open", self.application_settings["current_log_file_path"]],
)
def on_config_clicked(self, _):
from pathlib import Path
LogMessage.Debug("Opening the configuration file on the default editor...").write(self.logging_handler)
user_settings_filepath = Path(self.application_settings.filepath)
self.launch_third_party_utility(
package_name= "xdg-utils",
executable_name = [
"xdg-open",
str(user_settings_filepath.resolve())
],
)
def on_about_close(self, _):
LogMessage.Debug("Hiding the \"About\" dialog...").write(self.logging_handler)
self.builder.get_object("about").hide()
def on_shivanandvp_mail(self, button):
LogMessage.Debug("Opening mailing application for shivanandvp's email...").write(self.logging_handler)
self.launch_third_party_utility(
package_name= "xdg-utils",
executable_name = ["xdg-email", "[email protected]"],
)
def on_shivanandvp_git(self, button):
LogMessage.Debug("Opening the git page for shivanandvp...").write(self.logging_handler)
self.launch_third_party_utility(
package_name= "xdg-utils",
executable_name = ["xdg-open", "https://github.com/shiva-patt-oss"],
)
def on_startup_toggle(self, button):
LogMessage.Debug("Startup checkbox toggled...").write(self.logging_handler)
if button.get_active():
LogMessage.Debug("Enabling auto start...").write(self.logging_handler)
self.application_settings["auto_start_enabled"] = True
else:
LogMessage.Debug("Disabling auto start...").write(self.logging_handler)
self.application_settings["auto_start_enabled"] = False
self.application_settings.write_data()
def on_website_clicked(self, _):
LogMessage.Debug("Opening the RebornOS website on the default browser...").write(self.logging_handler)
self.launch_third_party_utility(
package_name= "xdg-utils",
executable_name = ["xdg-open", "https://rebornos.org/"],
)
def on_rebornos_wiki_clicked(self, _):
LogMessage.Debug("Opening RebornOS Wiki on the default browser...").write(self.logging_handler)
self.launch_third_party_utility(
package_name= "xdg-utils",
executable_name = ["xdg-open", "https://wiki.rebornos.org"],
)
def on_arch_wiki_clicked(self, _):
LogMessage.Debug("Opening Arch Wiki on the default browser...").write(self.logging_handler)
self.launch_third_party_utility(
package_name= "xdg-utils",
executable_name = ["xdg-open", "https://wiki.archlinux.org/"],
)
def on_service_status_clicked(self, _):
LogMessage.Debug("Opening Service Status page on the default browser...").write(self.logging_handler)
self.launch_third_party_utility(
package_name= "xdg-utils",
executable_name = ["xdg-open", "https://status.rebornos.org/"],
)
def on_discord_clicked(self, _):
LogMessage.Debug("Opening the Discord Server on the default browser...").write(self.logging_handler)
self.launch_third_party_utility(
package_name= "xdg-utils",
executable_name = ["xdg-open", "https://discord.gg/cU5s6MPpQH"],
)
def on_forum_clicked(self, _):
LogMessage.Debug("Opening the RebornOS Forum page on the default browser...").write(self.logging_handler)
self.launch_third_party_utility(
package_name= "xdg-utils",
executable_name = ["xdg-open", "https://rebornos.discourse.group/"],
)
def on_facebook_clicked(self, _):
LogMessage.Debug("Opening the Facebook page on the default browser...").write(self.logging_handler)
self.launch_third_party_utility(
package_name= "xdg-utils",
executable_name = ["xdg-open", "https://www.facebook.com/rebornos/"],
)
def on_twitter_clicked(self, _):
LogMessage.Debug("Opening the Twitter page on the default browser...").write(self.logging_handler)
self.launch_third_party_utility(
package_name= "xdg-utils",
executable_name = ["xdg-open", "https://twitter.com/rebornoslinux"],
)
def on_feedback_clicked(self, _):
LogMessage.Debug("Opening the Feedback page on the default browser...").write(self.logging_handler)
self.launch_third_party_utility(
package_name= "xdg-utils",
executable_name = ["xdg-open", "https://www.rebornos.org/contact"],
)
def on_donate_clicked(self, _):
LogMessage.Debug("Opening the donation page on the default browser...").write(self.logging_handler)
self.launch_third_party_utility(
package_name= "xdg-utils",
executable_name = ["xdg-open", "https://rebornos.org/donate/"],
)
def on_project_clicked(self, _):
LogMessage.Debug("Opening the GitHub page on the default browser...").write(self.logging_handler)
self.launch_third_party_utility(
package_name= "xdg-utils",
executable_name = ["xdg-open", "https://github.com/rebornos-team"],
)
def on_about_us_clicked(self, _):
LogMessage.Debug("Opening the \"About us\" page on the default browser...").write(self.logging_handler)
self.launch_third_party_utility(
package_name= "xdg-utils",
executable_name = ["xdg-open", "https://rebornos.org/about/"],
)
def on_pamac(self, _):
self.launch_third_party_utility(
package_name= "pamac-aur",
executable_name = "pamac-manager",
)
def on_stacer(self, _):
self.launch_third_party_utility(
package_name= "stacer",
executable_name = "stacer",
)
def on_hardinfo2(self, _):
self.launch_third_party_utility(
package_name= "hardinfo2",
executable_name = "hardinfo2",
)
def on_baobab(self, _):
self.launch_third_party_utility(
package_name= "baobab",
executable_name = "baobab",
)
def on_bleachbit(self, _):
self.launch_third_party_utility(
package_name= "bleachbit",
executable_name = "bleachbit",
)
def on_refresh_mirrors(self, _):
self.launch_third_party_utility(
package_name= "refresh-mirrors",
executable_name = ["gtk-launch", "refresh-mirrors"],
)
def on_pace(self, _):
self.launch_third_party_utility(
package_name= "pace",
executable_name = "pace",
)
def on_grub_customizer(self, _):
self.launch_third_party_utility(
package_name= "grub-customizer",
executable_name = "grub-customizer",
)
def on_gparted(self, _):
self.launch_third_party_utility(
package_name= "gparted",
executable_name = "gparted",
)
def on_timeshift(self, _):
self.launch_third_party_utility(
package_name= "timeshift",
executable_name = "timeshift-launcher",
)
def on_firewall(self, _):
self.launch_third_party_utility(
package_name= "gufw",
executable_name = [
"gtk-launch",
"gufw"
],
post_install_command= [
"pkexec",
"systemctl",
"enable",
"--now",
"ufw"
]
)
def install_latest_installer_github_release(
self,
batch_job: Optional[BatchJob] = None,
) -> Optional[BatchJob]:
LogMessage.Debug(f"Checking if a newer Github package exists for `{self.installer_config_package_name_stub}`...").write(logging_handler=self.logging_handler)
(is_new_installer_config_github_package_available, local_version, github_version) = self.is_new_github_package_available(self.installer_config_package_name_stub, self.installer_config_github_url_stub)
import re
local_version_parts = re.split('[._]', local_version)
github_version_parts = re.split('[._]', github_version)
# Ensure that a new package is assumed to exist only if there is a new patch version and not more major changes
for (local_version_part, github_version_part) in zip(local_version_parts[:-1], github_version_parts[:-1]):
if local_version_part != github_version_part:
is_new_installer_config_github_package_available = False
LogMessage.Info(f"New Github package exists for`{self.installer_config_package_name_stub}`, but has a major change, so a newer ISO is needed...").write(logging_handler=self.logging_handler)
break
if not is_new_installer_config_github_package_available:
LogMessage.Debug(f"No new compatible Github package exists for`{self.installer_config_package_name_stub}`...").write(logging_handler=self.logging_handler)
else:
LogMessage.Info(f"New Github package exists for `{self.installer_config_package_name_stub}`...").write(logging_handler=self.logging_handler)
LogMessage.Debug(f"Checking if a newer Github package exists for `{self.installer_package_name_stub}`...").write(logging_handler=self.logging_handler)
(is_new_installer_github_package_available, local_version, github_version) = self.is_new_github_package_available(self.installer_package_name_stub, self.installer_github_url_stub)
import re
local_version_parts = re.split('[._]', local_version)
github_version_parts = re.split('[._]', github_version)
# Ensure that a new package is assumed to exist only if there is a new patch version and not more major changes
for (local_version_part, github_version_part) in zip(local_version_parts[:-1], github_version_parts[:-1]):
if local_version_part != github_version_part:
is_new_installer_github_package_available = False
LogMessage.Info(f"New Github package exists for`{self.installer_package_name_stub}`, but has a major change, so a newer ISO is needed...").write(logging_handler=self.logging_handler)
break
if not is_new_installer_github_package_available:
LogMessage.Debug(f"No new compatible Github package exists for`{self.installer_package_name_stub}`...").write(logging_handler=self.logging_handler)
else:
LogMessage.Info(f"New Github package exists for `{self.installer_package_name_stub}`...").write(logging_handler=self.logging_handler)
if not is_new_installer_config_github_package_available and not is_new_installer_github_package_available:
return None
LogMessage.Info("Will download and install from GitHub...").write(self.logging_handler)
download_path = "/tmp/downloaded_from_github"
if batch_job is None:
self.display_busy()
batch_job = BatchJob(
logging_handler= self.logging_handler,
post_run_function=functools.partial(
self.display_ready
),
)
batch_job += LogMessage.Debug("Removing temporary download directory: " + download_path)
batch_job += Command.Shell(
"rm -rf" + " " + download_path
)
batch_job += LogMessage.Debug("(Re)creating temporary download directory: " + download_path)
batch_job += Command.Shell(
"mkdir -p" + " " + download_path
)
if is_new_installer_config_github_package_available:
batch_job += LogMessage.Debug(f"Downloading `{self.installer_config_package_name_stub}` from GitHub...")
batch_job += Command.Shell(
"curl --silent"
+ " " + "--output" + " " + download_path + "/" + f"{self.installer_config_package_name_stub}.pkg.tar.zst"
+ " " + "--location" + " " + f"$(curl --silent \'https://api.github.com/repos/{self.installer_config_github_url_stub}/releases/latest\' | jq \'.assets[] | select(.name | endswith(\".zst\")).browser_download_url\' | grep -v debug | cat | cut -d \'\"\' -f 2)"
)
if is_new_installer_github_package_available:
batch_job += LogMessage.Debug(f"Downloading `{self.installer_package_name_stub}` from GitHub...")
batch_job += Command.Shell(
"curl --silent"
+ " " + "--output" + " " + download_path + "/" + f"{self.installer_package_name_stub}.pkg.tar.zst"
+ " " + "--location" + " " + f"$(curl --silent \'https://api.github.com/repos/{self.installer_github_url_stub}/releases/latest\' | jq \'.assets[] | select(.name | endswith(\".zst\")).browser_download_url\' | grep -v debug | cat | cut -d \'\"\' -f 2)"
)
# batch_job += Command.Shell(
# "rm -rf" + " " + download_path + "/" + "*.md5sum"
# )
batch_job += LogMessage.Debug("Installing downloaded files...")
batch_job += Command.Shell(
"pkexec pacman -U --noconfirm" + " " + download_path + "/" + "*.pkg.tar.*",
)
batch_job += LogMessage.Debug("GitHub download and install task finished...")
return batch_job
def on_online_installer(self, _):
self.display_busy()
batch_job = BatchJob(
logging_handler= self.logging_handler,
post_run_function=functools.partial(
self.display_ready
),
)
if not self.builder.get_object("git_switch").get_active():
batch_job = self.uninstall_package(
[
f"{self.installer_package_name_stub}-git",
f"{self.installer_config_package_name_stub}-git",
f"{self.installer_package_name_stub}-local",
f"{self.installer_config_package_name_stub}-local",
],
batch_job= batch_job,
)
if self.builder.get_object("use_github_switch").get_active():
batch_job = self.install_latest_installer_github_release(batch_job= batch_job)
self.launch_third_party_utility(