-
Notifications
You must be signed in to change notification settings - Fork 2
/
egg.py
executable file
·81 lines (61 loc) · 2.55 KB
/
egg.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
#!/usr/bin/env python3
import json
import os
import sys
from egg.app import App
from egg.type_event import TypeEvent
from egg.language_management import LanguageManagement
gtk_found = False
try:
from ui.gtk.app import GtkApp
gtk_found = True
except (ValueError, ImportError):
pass
def load_lang_files(locale_general: LanguageManagement, config_general: dict) -> None:
locale_general.locales_folder = config_general['locales_folder']
locale_general.change_language_all_files(config_general['default_language_code'])
for current_language_file in config_general['language_files']:
locale_general.change_language_file(locale_general.current_language, current_language_file)
def load_config_from_files(config_files: dict) -> dict:
config_files_path = {}
prefix_path = './'
prefix_path_dev = os.getcwd() + '/'
suffix_dev = '_dev'
for item in config_files:
if __debug__:
file_path = prefix_path_dev + 'config/' + item + suffix_dev + '.json'
if not os.path.isfile(file_path):
file_path = prefix_path + 'config/' + item + '.json'
else:
file_path = prefix_path + 'config/' + item + '.json'
config_files_path[item] = file_path
return config_files_path
def load_config_files() -> (dict, dict):
config_general = None
config_main_window = None
config_files = {'general': 'general', 'main_window': 'main_window'}
config_files_path = load_config_from_files(config_files)
with open(config_files_path['general'], 'r') as datafile:
config_general = json.load(datafile)
with open(config_files_path['main_window'], 'r') as datafile:
config_main_window = json.load(datafile)
return config_general, config_main_window
def main() -> None:
config_general, config_main_window = load_config_files()
locale_general = LanguageManagement(config_general, None)
load_lang_files(locale_general, config_general)
ui_app = App()
if gtk_found:
ui_app = GtkApp(locale_general, config_general, config_main_window)
else:
print(locale_general.translate_msg('general', 'no_ui_found'))
sys.exit(1)
if not config_general['launch_without_root']:
if os.geteuid() != 0:
ui_app.display_popup(locale_general.translate_msg('popup', 'not_admin_title_popup'),
locale_general.translate_msg('popup', 'not_admin_desc_popup'),
TypeEvent.INFO)
sys.exit(1)
ui_app.launch()
if __name__ == '__main__':
main()