-
Notifications
You must be signed in to change notification settings - Fork 5
/
yali-bin
317 lines (243 loc) · 10 KB
/
yali-bin
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2006-2010 TUBITAK/UEKAE
#
# This program 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 2 of the License, or (at your option)
# any later version.
#
# Please read the COPYING file.
#
import os
import sys
try:
from PyQt5.QtCore import QCoreApplication
_ = QCoreApplication.translate
except Exception:
_ = lambda x,y : " ".join(x,y)
# if os.path.exists("build/lib.linux-x86_64-2.7/yali/"):
# sys.path.append("build/lib.linux-x86_64-2.7/yali/")
import yali
import yali.context as ctx
from PyQt5.QtWidgets import QApplication
def load_modules():
"""
Load modules.
"""
os.system("modprobe -bqa dm-mod raid0 raid1 raid456 raid10")
def load_config(options):
"""
Load configuration.
Arguments:
parser: Options parsed with ConfigParser module
options: Options parsed with optparse module
"""
# Read configuration file
if options.conffile:
if not os.path.exists(options.conffile):
if not os.path.exists(ctx.consts.conf_file):
ctx.logger.debug(_("General", "%s is missing") % ctx.consts.conf_file)
sys.exit(1)
elif not os.path.exists(ctx.consts.conf_file):
ctx.logger.debug(_("General", "%s is missing") % ctx.consts.conf_file)
sys.exit(1)
import ConfigParser
parser = ConfigParser.ConfigParser()
try:
if options.conffile and os.path.exists(options.conffile):
parser.read(options.conffile)
else:
parser.read(ctx.consts.conf_file)
except IOError:
ctx.logger.debug(_("General", "%s is corrupted") % ctx.consts.conf_file)
sys.exit(1)
if parser.has_option("general", "installation") and options.install_type == ctx.STEP_DEFAULT:
if parser.get("general", "installation") == "system":
options.install_type = ctx.STEP_BASE
elif parser.get("general", "installation") == "firstboot":
options.install_type = ctx.STEP_FIRST_BOOT
elif parser.get("general", "installation") == "rescue":
options.install_type = ctx.STEP_RESCUE
elif parser.get("general", "installation") == "oem":
options.install_type = ctx.STEP_OEM_INSTALL
else:
options.install_type = ctx.STEP_DEFAULT
if parser.has_option("general", "debug"):
if parser.get("general", "debug") == "True":
options.debug = True
else:
options.debug = False
if parser.has_option("general", "collection"):
if parser.get("general", "collection") == "False":
options.collection = False
else:
options.collection = True
if parser.has_option("general", "baseonly"):
if parser.get("general", "baseonly") == "True":
options.baseonly = True
else:
options.baseonly = False
if parser.has_option("general", "dryrun"):
if parser.get("general", "dryrun") == "True":
options.dryRun = True
else:
options.dryRun = False
if parser.has_option("general", "theme"):
options.theme = parser.get("general", "theme")
if parser.has_option("general", "branding"):
options.theme = parser.get("general", "branding")
if parser.has_option("repo", "name"):
ctx.consts.pisilinux_repo_name = parser.get("repo", "name")
else:
ctx.consts.pisilinux_repo_name = "@REPO_NAME@"
raise Exception(_("repo name not found. set repo name on yali.conf"))
if parser.has_option("repo", "uri"):
ctx.consts.pisilinux_repo_uri = parser.get("repo", "uri")
else:
ctx.consts.pisilinux_repo_uri = "@REPO_URI@"
raise Exception(_("repo uri not found. set repo uri on yali.conf"))
print(ctx.consts.pisilinux_repo_name)
print(ctx.consts.pisilinux_repo_uri)
# if options.conffile:
# if not os.path.exists(options.conffile):
# if not os.path.exists(ctx.consts.conf_file):
# ctx.logger.debug(_("General", "%s is missing") % ctx.consts.conf_file)
# sys.exit(1)
# elif not os.path.exists(ctx.consts.conf_file):
if not os.path.exists(ctx.consts.repo_file): # FIXME: ?pisilinux_repo_*
ctx.logger.debug(_("General", "%s is missing") % ctx.consts.repo_file)
sys.exit(1)
import json
from collections import OrderedDict
try:
repo_file = open(ctx.consts.repo_file)
ctx.consts.pisilinux_repos = json.load(repo_file, object_pairs_hook=OrderedDict)
except IOError:
ctx.logger.debug(_("General", "%s is corrupted") % ctx.consts.repo_file)
sys.exit(1)
# FIXME: pisilinux_repos veya (pisilinux_repo_name, pisilinux_repo_uri)
# den en az biri yüklü olmalı aksi halde uyarı ile çıkış yapılmalı!
def setup_environment():
"""
Setup environment.
"""
import locale
# FIXME:Why do we need this?
locale.setlocale(locale.LC_ALL, "")
os.environ['LC_NUMERIC'] = 'C'
os.environ["LVM_SUPPRESS_FD_WARNINGS"] = "1"
def setup_exception_handler():
import signal
import traceback
import cStringIO
def signal_handler(sig, frame):
if sig == signal.SIGTERM:
sys.exit(1)
def exception_handler(exception, value, error_traceback):
""" YALI exception handler for showing exceptions in GUI """
signal.signal(signal.SIGINT, signal.SIG_IGN) # disable further interrupts
sio = cStringIO.StringIO()
sio.write(_("General", "Please file a bug report to <http://bugs.pisilinux.org>.\n"))
_value = ''
for arg in value.args:
_value += str(arg) + '\n'
sio.write(_value)
sio.write(str(exception))
sio.write('\n\n')
sio.write(_("General", "Backtrace:"))
sio.write('\n')
traceback.print_tb(error_traceback, None, sio)
sio.seek(0)
exception_traceback = unicode(sio.read())
ctx.logger.debug(_("General", "Unhandled internal YALI exception:%s") % exception_traceback)
if ctx.interface:
ctx.interface.exceptionWindow(exception, exception_traceback)
sys.excepthook = exception_handler
signal.signal(signal.SIGTERM, signal_handler)
def init_gui_interface():
from yali.gui.interface import Interface
ctx.interface = Interface()
def init_gui_runner(app):
from yali.gui.runner import Runner
gui_runner = Runner(app)
gui_runner.run()
def load_options(argv=None):
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-d", "--debug", dest="debug",
action="store_true", default=False,
help="enable debug")
parser.add_option("-c", "--config", dest="conffile",
help="Use alternate configuration file", metavar="FILE")
parser.add_option("--dryRun", dest="dryRun",
action="store_true",
help="only show the result")
parser.add_option("--baseonly", dest="baseonly",
action="store_true",
help="install base system packages")
parser.add_option("--enable-collection", dest="collection",
action="store_true", default=False,
help="install collection base installation"
" if collections exist")
parser.add_option("--system", dest="install_type", default=0,
action="store_const", const=1,
help="start system installation")
parser.add_option("--firstboot", dest="install_type",
action="store_const", const=2,
help="start with first boot options")
parser.add_option("--rescue", dest="install_type",
action="store_const", const=3,
help="start Yali with rescue mode")
parser.add_option("--oem", dest="install_type",
action="store_const", const=4,
help="start Yali with oem mode")
parser.add_option("--kahya", dest="kahya",
help="run with Kahya file", metavar="FILE")
parser.add_option("-s", "--startFrom", dest="startFrom",
type="int", default=0,
help="start from the given screen (num)")
parser.add_option("-t", "--theme", dest="theme",
help="load given theme", type="str", default="pisilinux")
parser.add_option("-b", "--branding", dest="branding",
help="load given branding", type="str",
default="pisilinux")
return parser.parse_args(argv)
def main():
# Only root can run that application
if os.getuid() != 0:
print("{} must be run as root.".format(sys.argv[0]))
return 1
# Terminate plymouth daemon if needed
if os.path.exists("/bin/plymouth") and not os.system("/bin/plymouth --ping"):
os.system("/bin/plymouth quit --retain-splash")
ctx.logger.debug("Yali has been started")
load_modules()
setup_environment()
init_gui_interface()
setup_exception_handler()
(options, args) = load_options()
load_config(options)
ctx.flags.install_type = options.install_type
ctx.flags.startup = options.startFrom
ctx.flags.debug = options.debug
ctx.flags.dryRun = options.dryRun
ctx.flags.collection = options.collection
ctx.flags.baseonly = options.baseonly
ctx.flags.theme = options.theme
ctx.flags.branding = options.branding
if options.kahya:
ctx.flags.kahya = True
ctx.flags.kahyaFile = options.kahya
app = QApplication(sys.argv)
if not ctx.storage:
from yali.storage import Storage
ctx.storage = Storage()
if not ctx.bootloader:
from yali.storage.bootloader import BootLoader
ctx.bootloader = BootLoader(ctx.storage)
ctx.flags.parse_kernel_options(ctx)
init_gui_runner(app)
if __name__ == "__main__":
sys.exit(main())