-
Notifications
You must be signed in to change notification settings - Fork 6
/
mpis
executable file
·175 lines (170 loc) · 7.31 KB
/
mpis
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
#!/usr/bin/env python
#-*- coding: utf-8 -*-
#
# This file is part of MPIS (https://github.com/KernelPanicBlog/MPIS).
#
# MPIS(Manjaro Post Installation Script) is free software; you can redistribute
# it and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the License,or
# any later version.
#
# MPIS (Manjaro Post Installation Script):
# It allows users to choose different options such as
# install an application or CONFIG some tools and environments.
#
# MPIS is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with MPIS; If not, see <http://www.gnu.org/licenses/>.
# _____________________________________________________________________________
import sys
import traceback
import webbrowser
from mpislib.core import check_file
from mpislib.core import restor_file
from mpislib.core import db
from mpislib.core import GlobalResource
from mpislib.core import paramlist
from mpislib.core import user_input
from mpislib.core import pause
from mpislib.core import clear
from mpislib.core import mkopts
from mpislib.core import show_banner
from mpislib.core import sleep
from mpislib.core import execute_command
from mpislib.core import wizard_config
from mpislib.core import set_language
from mpislib.core import toggle_config
from mpislib.core import show_help
from mpislib.core import search
from mpislib.menu import GlobalMenu
from mpislib.traslate import tr
from mpislib.colorize import colorize
def main():
list_cmd_to_install = []
try:
show_banner()
sleep(2)
clear()
print(colorize.aplicar(1, 31)
+ tr("The '--noconfirm' parameter is enabled by default."))
print(tr("You can change this option in the Settings menu.")
+ colorize.reset())
sleep(2)
clear()
option = 0
menu_back = []
GlobalMenu.load_appearance()
menu = GlobalMenu.nodos[option]
GlobalMenu.show_menu(menu, True if list_cmd_to_install else False)
while True:
try:
option = user_input()
if option in mkopts("back"):
if menu_back:
menu = menu_back.pop()
elif option in mkopts("help"):
show_help()
elif option in mkopts("search"):
cmd_ = search()
if db.get_config('multi_install') == 'True':
list_cmd_to_install.append(cmd_)
pause(tr("The tasks was added to the installation list."))
else:
execute_command(cmd_)
elif option in mkopts("tasks"):
print(tr("We will proceed to install"
"the selected applications."))
for _cmd_ in list_cmd_to_install:
execute_command(_cmd_)
list_cmd_to_install.clear()
elif option in mkopts("exit"):
sys.exit(0)
elif int(option) <= len(menu.childern):
option = int(option)
if menu[option].childern:
menu_back.append(menu)
menu = menu.childern[option]
else:
arg_eval = menu.childern[option].name
if menu.name == "Look & Feel":
pause(tr("(not functional, yet)"))
elif arg_eval == "Appearance":
wizard_config()
GlobalMenu.load_appearance()
elif arg_eval == "Set language":
set_language()
elif arg_eval == "Toggle --noconfirm":
toggle_config("noconfirm")
elif arg_eval == "Toggle multi-install":
toggle_config("multi_install")
elif arg_eval == "About MPIS":
show_banner()
pause()
elif arg_eval == "Report bug!":
web_bug = "https://github.com/"
web_bug += "KernelPanicBlog/MPIS/issues"
webbrowser.open(web_bug)
clear()
pause(tr("Link is opening in your web browser."))
elif arg_eval == "See README File":
with open(GlobalResource.path_file("README.rst"),
"r") as _file:
pause(_file.read())
elif arg_eval == "See CHANGELOG File":
with open(GlobalResource.path_file("CHANGELOG.rst"),
"r") as _file:
pause(_file.read())
elif arg_eval == "See the content of mirrorlist file":
with open("/etc/pacman.d/mirrorlist",
"r") as _file:
pause(_file.read())
else:
parm = menu.parent.split()[0]
arg = True if parm == "Install" else False
cmd_ = db.get_command(menu.childern[option].name, arg)
if db.get_config('multi_install') == 'True':
list_cmd_to_install.append(cmd_)
pause(tr("The tasks was added to the installation"
" list."))
else:
execute_command(cmd_)
else:
pause(tr("Sorry not valid Option."))
except (ValueError, IndexError):
pause(tr("Error in option, this value is outside the range"
"of the list"))
clear()
GlobalMenu.show_menu(menu, len(list_cmd_to_install))
except KeyboardInterrupt:
print(colorize.aplicar(1, 31)
+ tr("You had press the Ctrl+C keys combination."
"Accepted exit request. Bye!") + colorize.reset())
sleep(2)
clear()
except Exception:
traceback.print_exc(file=sys.stdout)
sys.exit(0)
if __name__ == "__main__" and len(sys.argv) == 1:
for file_ in ["/.config/mpis/db", "/EN_us.tr", "/ES_es.tr"]:
_db = True if file_.endswith("db") else False
_val, _dir = check_file(file_, _db)
if not _val:
print("file:{0} not found.".format(file_))
print("Restoring . . .")
restor_file(_dir, file_, _db)
print("Done.")
main()
else:
if sys.argv[1] in paramlist:
param = sys.argv[1]
argv = sys.argv[2]
if param in ["-i", "--install"]:
cmd = db.get_command(argv)
execute_command(cmd)
elif param in ["-u", "--uninstall"]:
cmd = db.get_command(argv, False)
execute_command(cmd)