aboutsummaryrefslogtreecommitdiff
blob: 9618ed371a7f4b8bb162bd7de383831c0d84cabb (plain)
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
#!/usr/bin/python

# Copyright 1999-2005 Gentoo Foundation
# This source code is distributed under the terms of version 2 of the GNU
# General Public License as published by the Free Software Foundation, a copy
# of which can be found in the main directory of this project.

import sys
sys.path.append("../..")

import os
import GLIInstallProfile
import GLIClientController
import GLIUtility
from SplashScreen import SplashScreen
import gtk
from gettext import gettext as _
import TextBufferMarkup
from ProgressDialog import *

class Installer:

	SHOW_BUTTON_FORWARD = 1
	SHOW_BUTTON_BACK = 1
	install_profile_xml_file = ""
	install_window = None
#	install_type = "standard"
	install_type = "networkless"
	cur_screen = None
	install_done = False

	screens = {
#	  "InstallMode": None,
	  "Partition": None,
	  "LocalMounts": None,
#	  "NetworkMounts": None,
#	  "Stage": None,
#	  "PortageTree": None,
#	  "MakeDotConf": None,
	  "RootPass": None,
	  "Timezone": None,
#	  "Kernel": None,
#	  "KernelSources": None,
#	  "KernelConfig": None,
	  "Networking": None,
#	  "Logger": None,
#	  "CronDaemon": None,
#	  "Bootloader": None,
	  "Users": None,
	  "ExtraPackages": None,
	  "StartupServices": None,
	  "OtherSettings": None,
	  "InstallDone": None,
	  "InstallFailed": None
	}

	bootloaders = {
	  'none':  [ "none" ],
	  'x86':   [ "grub", "lilo" ],
	  'amd64': [ "grub" ],
	  'ppc':   [ "yaboot" ],
	  'hppa':  [ "palo" ],
	  'mips':  [ "arcload", "arcboot", "colo" ],
	  'sparc': [ "silo" ]
	}

	def __init__(self):
		self.window = None
		self.panel = None
		self._cur_panel = 0
		self.__full_path = self.get_current_path()

		# Show splash screen
		self.splash = SplashScreen(self.__full_path)
		self.splash.show()
		while gtk.events_pending():
			gtk.main_iteration()

		# Import screen modules
		for screen in self.screens:
			self.screens[screen] = __import__(screen)

		# Instantiate installer objects
		self.install_profile = GLIInstallProfile.InstallProfile()
		if '-d' in sys.argv or '--debug' in sys.argv:
			# Enable debug mode via commandline argument
			self.install_profile.set_verbose(None, True, None)
		self.cc = GLIClientController.GLIClientController(self.install_profile)

		self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
		self.title = _("Gentoo Linux Installer")
		self.window.realize()
		self.window.connect("delete_event", self.delete_event)
		self.window.connect("destroy", self.destroy)
		self.window.set_border_width(0)
		self.window.set_default_size(800,600)
		self.window.set_geometry_hints(None, min_width=800, min_height=600, max_width=800, max_height=600)
		self.window.set_title(_("Gentoo Linux Installer"))
		self.globalbox = gtk.VBox(False, 0)
		self.window.add(self.globalbox)

		# Banner image
		self.headerbox = gtk.HBox(False, 0)
		headerimg = gtk.Image()
		headerimg.set_from_file(self.__full_path + '/installer-banner-800x64.png')
		self.headerbox.pack_start(headerimg, padding=0)
		self.globalbox.pack_start(self.headerbox, expand=False, fill=False, padding=0)

		# Progress bar
#		progress_box = gtk.HBox(False, 0)
#		progress_box.pack_start(gtk.Label("Install Progress"), expand=False, fill=False, padding=10)
#		self.progress_bar = gtk.ProgressBar()
#		progress_box.pack_start(self.progress_bar, expand=True, fill=True, padding=10)
#		self.globalbox.pack_start(progress_box, expand=False, fill=False, padding=5)
#		self.globalbox.pack_start(gtk.HSeparator(), expand=False, fill=False, padding=0)

		# Top box
		self.topbox = gtk.HBox(False, 0)
		self.globalbox.pack_start(self.topbox, expand=True, fill=True, padding=5)

		# Left frame
		self.leftframe = gtk.Frame()
		self.leftframe.set_size_request(200, -1)
		self.leftframe.set_shadow_type(gtk.SHADOW_ETCHED_OUT)
		self.textbuff = TextBufferMarkup.PangoBuffer()
		self.textview = gtk.TextView(self.textbuff)
		self.textview.set_editable(False)
		self.textview.set_wrap_mode(gtk.WRAP_WORD)
		self.textview.set_left_margin(5)
		self.textview.set_right_margin(5)
		self.textview.set_sensitive(False)
		self.textviewscroll = gtk.ScrolledWindow()
		self.textviewscroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
		self.textviewscroll.add(self.textview)
		self.leftframe.add(self.textviewscroll)
		self.topbox.pack_start(self.leftframe, expand=True, fill=True, padding=5)

		# Right frame
		self.rightframe = gtk.VBox(False, 0)
		self.rightframe.set_size_request(570, -1)
		self.topbox.pack_end(self.rightframe, expand=True, fill=True, padding=5)
		self.globalbox.show_all();

		# Bottom box
		self.bottombox = gtk.HBox(False, 0)
		self.globalbox.pack_end(self.bottombox, expand=False, fill=False, padding=5)
		self.globalbox.pack_end(gtk.HSeparator(), expand=False, fill=False, padding=0)

		buttons_info = [ ('exit', _(" _Exit "), '/button_images/stock_exit.png', self.exit_button, 'start'),
#		                 ('load', _(" _Load "), '/button_images/stock_open.png', self.load_button, 'start'),
#		                 ('save', _(" _Save "), '/button_images/stock_save.png', self.save_button, 'start'),
		                 ('log', _(" _View Log "), '', self.log_button, 'start'),
		                 ('next', _(" _Next "), '/button_images/stock_right.png', self.next, 'end'),
		                 ('previous', _(" _Previous "), '/button_images/stock_left.png', self.previous, 'end')
                               ]
		self.buttons = {}
		for button in buttons_info:
			self.buttons[button[0]] = gtk.Button()
			tmpbuttonbox = gtk.HBox(False, 0)
			if button[2]:
				tmpbuttonimg = gtk.Image()
				tmpbuttonimg.set_from_file(self.__full_path + button[2])
				tmpbuttonbox.pack_start(tmpbuttonimg)
			tmpbuttonlabel = gtk.Label(button[1])
			tmpbuttonlabel.set_use_underline(True)
			tmpbuttonbox.pack_start(tmpbuttonlabel)
			self.buttons[button[0]].add(tmpbuttonbox)
			self.buttons[button[0]].connect("clicked", button[3], None)
			if button[4] == "start":
				self.bottombox.pack_start(self.buttons[button[0]], expand=False, fill=False, padding=5)
			else:
				self.bottombox.pack_end(self.buttons[button[0]], expand=False, fill=False, padding=5)

		self.splash.destroy()
		self.window.show_all()
		self.load_screen("Partition")

	def redraw_buttons(self):
		self.bottombox.hide_all()
		self.buttons['next'].set_sensitive(self.SHOW_BUTTON_FORWARD)
		self.buttons['previous'].set_sensitive(self.SHOW_BUTTON_BACK)
		self.bottombox.show_all()

	def get_current_path(self):
		# this will return the absolute path to the
		# directory containing this file
		# it will only work if this file is imported somewhere,
		# not if it is run directly (__file__ will be undefined)
		import os.path
		return os.path.abspath(os.path.dirname(__file__))

	def load_screen(self, name):
		if self.cur_screen:
			self.rightframe.remove(self.cur_screen)
			del self.cur_screen
		self.cur_screen = self.screens[name].Panel(self)
#		percent = int((i) / float(len(self.screens) - 1) * 100)
#		self.progress_bar.set_fraction(float(percent) / 100)
#		self.progress_bar.set_text(str(percent) + "%")
		self.rightframe.add(self.cur_screen)
		self.cur_screen.activate()
		helptext = self.cur_screen._helptext
#		helptext = " ".join(helptext.split("\n"))
#		helptext = "\n".join(helptext.split('<br>'))
		self.textbuff.set_text(helptext)
		self.rightframe.show_all()
		self.redraw_buttons()

	def run(self):
		gtk.gdk.threads_init()
		gtk.main()

	def previous(self, widget, data=None):
		self.cur_screen.previous()

	def next(self, widget, data=None):
		self.cur_screen.next()

	def exit_button(self, widget, data=None):
		if not self.install_done:
			msgdlg = gtk.MessageDialog(parent=self.window, type=gtk.MESSAGE_QUESTION, buttons=gtk.BUTTONS_YES_NO, message_format="Are you sure you want to exit?")
			resp = msgdlg.run()
			msgdlg.destroy()
			if resp == gtk.RESPONSE_YES:
				msgdlg = gtk.MessageDialog(parent=self.window, type=gtk.MESSAGE_QUESTION, buttons=gtk.BUTTONS_YES_NO, message_format="Do you want the installer to clean up after itself before exiting?")
				resp = msgdlg.run()
				msgdlg.destroy()
				if resp == gtk.RESPONSE_YES:
					progress = ProgressDialog(self, ("install_failed_cleanup", ), self.exit_callback)
					progress.run()
				else:
					self.exit()
		else:
			self.exit()

	def exit_callback(self, result):
		self.exit()

	def load_button(self, widget, data=None):
		filesel = gtk.FileSelection(_("Select the install profile to load"))
		if self.install_profile_xml_file == "":
			filesel.set_filename("installprofile.xml")
		else:
			filesel.set_filename(self.install_profile_xml_file)
		resp = filesel.run()
		filename = filesel.get_filename()
		filesel.destroy()
		if resp == gtk.RESPONSE_OK:
			self.install_profile_xml_file = filename
			try:
				tmp_install_profile = GLIInstallProfile.InstallProfile()
				tmp_install_profile.parse(self.install_profile_xml_file)
				self.install_profile = tmp_install_profile
				msgdlg = gtk.MessageDialog(parent=self.window, type=gtk.MESSAGE_INFO, buttons=gtk.BUTTONS_OK, message_format=_("Install profile loaded successfully!"))
				msgdlg.run()
				msgdlg.destroy()
			except:
				errdlg = gtk.MessageDialog(parent=self.window, type=gtk.MESSAGE_ERROR, buttons=gtk.BUTTONS_OK, message_format=_("An error occured loading the install profile"))
				errdlg.run()
				errdlg.destroy()

	def save_button(self, widget, data=None):
		filesel = gtk.FileSelection(_("Select the location to save the install profile"))
		if self.install_profile_xml_file == "":
			filesel.set_filename("installprofile.xml")
		else:
			filesel.set_filename(self.install_profile_xml_file)
		resp = filesel.run()
		filename = filesel.get_filename()
		filesel.destroy()
		if resp == gtk.RESPONSE_OK:
			self.install_profile_xml_file = filename
			try:
				configuration = open(filename, "w")
				configuration.write(self.install_profile.serialize())
				configuration.close()
				msgdlg = gtk.MessageDialog(parent=self.window, type=gtk.MESSAGE_INFO, buttons=gtk.BUTTONS_OK, message_format=_("Install profile saved successfully!"))
				msgdlg.run()
				msgdlg.destroy()
			except:
				errdlg = gtk.MessageDialog(parent=self.window, type=gtk.MESSAGE_ERROR, buttons=gtk.BUTTONS_OK, message_format=_("An error occured saving the install profile"))
				errdlg.run()
				errdlg.destroy()

	def log_button(self, widget, data=None):
		if os.path.isfile("/var/log/install.log"):
			os.system("xterm -e 'tail -f /var/log/install.log' &")
		elif os.path.isfile("/var/log/install.log.failed"):
			os.system("xterm -e 'tail -f /var/log/install.log.failed' &")
		else:
			errdlg = gtk.MessageDialog(parent=self.window, type=gtk.MESSAGE_ERROR, buttons=gtk.BUTTONS_OK, message_format=_("Could not find the log file"))
			errdlg.run()
			errdlg.destroy()

	def delete_event(self, widget, event, data=None):
		self.exit_button(self.buttons['exit'])
		return True

	def destroy(self, widget, data=None):
		gtk.main_quit()
		return True
	
	def exit(self, status=0):
		gtk.main_quit()
		sys.exit(status)

if __name__ == "__main__":
	install = Installer()
	install.run()