/usr/lib/live-installer/frontend/gtk_interface.py
Python | 1480 lines | 1298 code | 95 blank | 87 comment | 70 complexity | fab6603d186f99e0a33750414eff2f93 MD5 | raw file
Possible License(s): BSD-3-Clause
Large files files are truncated, but you can click here to view the full file
- #!/usr/bin/env python
- import sys
- sys.path.append('/usr/lib/live-installer')
- from installer import InstallerEngine, Setup, PartitionSetup
- try:
- import pygtk
- pygtk.require("2.0")
- import gtk
- import gtk.glade
- import gettext
- import os
- import commands
- import subprocess
- import sys
- sys.path.append('/usr/lib/live-installer')
- import pango
- import threading
- import xml.dom.minidom
- from xml.dom.minidom import parse
- import gobject
- import time
- import webkit
- import GeoIP
- import urllib
- import string
- import parted
- except Exception, detail:
- print detail
- gettext.install("live-installer", "/usr/share/locale")
- gtk.gdk.threads_init()
- INDEX_PARTITION_PATH=0
- INDEX_PARTITION_TYPE=1
- INDEX_PARTITION_DESCRIPTION=2
- INDEX_PARTITION_FORMAT_AS=3
- INDEX_PARTITION_MOUNT_AS=4
- INDEX_PARTITION_SIZE=5
- INDEX_PARTITION_FREE_SPACE=6
- INDEX_PARTITION_OBJECT=7
- class ProgressDialog:
-
- def __init__(self):
- self.glade = '/usr/share/live-installer/interface.glade'
- self.dTree = gtk.glade.XML(self.glade, 'progress_window')
- self.window = self.dTree.get_widget('progress_window')
- self.progressbar = self.dTree.get_widget('progressbar_operation')
- self.label = self.dTree.get_widget('label_operation')
- self.should_pulse = False
-
- def show(self, label=None, title=None):
- def pbar_pulse():
- if(not self.should_pulse):
- return False
- self.progressbar.pulse()
- return self.should_pulse
- if(label is not None):
- self.label.set_markup(label)
- if(title is not None):
- self.window.set_title(title)
- self.should_pulse = True
- self.window.show_all()
- gobject.timeout_add(100, pbar_pulse)
-
- def hide(self):
- self.should_pulse = False
- self.window.hide()
- ''' Handy. Makes message dialogs easy :D '''
- class MessageDialog(object):
- def __init__(self, title, message, style):
- self.title = title
- self.message = message
- self.style = style
- ''' Show me on screen '''
- def show(self):
- dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, self.style, gtk.BUTTONS_OK, self.message)
- dialog.set_title(self.title)
- dialog.set_position(gtk.WIN_POS_CENTER)
- dialog.set_icon_from_file("/usr/share/icons/live-installer.png")
- dialog.run()
- dialog.destroy()
-
- class QuestionDialog(object):
- def __init__(self, title, message):
- self.title = title
- self.message = message
- ''' Show me on screen '''
- def show(self):
- dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, self.message)
- dialog.set_title(self.title)
- dialog.set_position(gtk.WIN_POS_CENTER)
- dialog.set_icon_from_file("/usr/share/icons/live-installer.png")
- answer = dialog.run()
- if answer==gtk.RESPONSE_YES:
- return_value = True
- else:
- return_value = False
- dialog.destroy()
- return return_value
- class WizardPage:
- def __init__(self, help_text, icon):
- self.help_text = help_text
- self.icon = icon
-
- class InstallerWindow:
- def __init__(self, fullscreen=False):
-
- #Build the Setup object (where we put all our choices)
- self.setup = Setup()
-
- self.resource_dir = '/usr/share/live-installer/'
- #self.glade = 'interface.glade'
- self.glade = os.path.join(self.resource_dir, 'interface.glade')
- self.wTree = gtk.glade.XML(self.glade, 'main_window')
- # should be set early
- self.done = False
- self.fail = False
- # here comes the installer engine
- self.installer = InstallerEngine()
- # the distribution name
- DISTRIBUTION_NAME = self.installer.get_distribution_name()
- # load the window object
- self.window = self.wTree.get_widget("main_window")
- if "--debug" in sys.argv:
- self.window.set_title((_("%s Installer") % DISTRIBUTION_NAME) + " (debug)")
- else:
- self.window.set_title(_("%s Installer") % DISTRIBUTION_NAME)
- self.window.connect("destroy", self.quit_cb)
- # Wizard pages
- [self.PAGE_LANGUAGE, self.PAGE_PARTITIONS, self.PAGE_USER, self.PAGE_ADVANCED, self.PAGE_KEYBOARD, self.PAGE_OVERVIEW, self.PAGE_INSTALL, self.PAGE_TIMEZONE, self.PAGE_HDD] = range(9)
- self.wizard_pages = range(9)
- self.wizard_pages[self.PAGE_LANGUAGE] = WizardPage(_("Choose your language"), "locales.png")
- self.wizard_pages[self.PAGE_TIMEZONE] = WizardPage(_("Choose your timezone"), "time.png")
- self.wizard_pages[self.PAGE_KEYBOARD] = WizardPage(_("Choose your keyboard layout"), "keyboard.png")
- self.wizard_pages[self.PAGE_HDD] = WizardPage(_("On which hard drive do you want to install Kazsid?"), "hdd.svg")
- self.wizard_pages[self.PAGE_PARTITIONS] = WizardPage(_("Select where you want to install Kazsid"), "hdd.svg")
- self.wizard_pages[self.PAGE_USER] = WizardPage(_("Please indicate your name and select a username, a password and a hostname"), "user.png")
- self.wizard_pages[self.PAGE_ADVANCED] = WizardPage(_("Please review the following advanced options"), "advanced.png")
- self.wizard_pages[self.PAGE_OVERVIEW] = WizardPage(_("Please review this summary and make sure everything is correct"), "summary.png")
- self.wizard_pages[self.PAGE_INSTALL] = WizardPage(_("Please wait while Kazsid is being installed on your computer"), "install.png")
-
- # set the button events (wizard_cb)
- self.wTree.get_widget("button_next").connect("clicked", self.wizard_cb, False)
- self.wTree.get_widget("button_back").connect("clicked", self.wizard_cb, True)
- self.wTree.get_widget("button_quit").connect("clicked", self.quit_cb)
- ren = gtk.CellRendererPixbuf()
- column = gtk.TreeViewColumn("Flags", ren)
- column.add_attribute(ren, "pixbuf", 2)
- self.wTree.get_widget("treeview_language_list").append_column(column)
- ren = gtk.CellRendererText()
- column = gtk.TreeViewColumn("Languages", ren)
- column.add_attribute(ren, "text", 0)
- self.wTree.get_widget("treeview_language_list").append_column(column)
- self.wTree.get_widget("treeview_language_list").connect("cursor-changed", self.assign_language)
- # build the language list
- self.build_lang_list()
- ren = gtk.CellRendererText()
- column = gtk.TreeViewColumn("Timezones", ren)
- column.add_attribute(ren, "text", 0)
- self.wTree.get_widget("treeview_timezones").append_column(column)
- self.wTree.get_widget("treeview_timezones").connect("cursor-changed", self.assign_timezone)
- self.build_timezones()
- # disk view
- ren = gtk.CellRendererText()
- self.column1 = gtk.TreeViewColumn("Hard drive", ren)
- self.column1.add_attribute(ren, "text", 0)
- self.wTree.get_widget("treeview_hdds").append_column(self.column1)
- self.column2 = gtk.TreeViewColumn("Description", ren)
- self.column2.add_attribute(ren, "text", 1)
- self.wTree.get_widget("treeview_hdds").append_column(self.column2)
- self.wTree.get_widget("treeview_hdds").connect("cursor-changed", self.assign_hdd)
- self.build_hdds()
- #self.build_grub_partitions()
-
- self.wTree.get_widget("button_edit").connect("clicked", self.edit_partitions)
- self.wTree.get_widget("label_edit_partitions").set_label(_("Edit partitions"))
- self.wTree.get_widget("button_refresh").connect("clicked", self.refresh_partitions)
- self.wTree.get_widget("treeview_disks").connect("row_activated", self.assign_partition)
- self.wTree.get_widget("treeview_disks").connect( "button-release-event", self.partitions_popup_menu)
-
- # device
- ren = gtk.CellRendererText()
- self.column3 = gtk.TreeViewColumn(_("Device"), ren)
- self.column3.add_attribute(ren, "markup", INDEX_PARTITION_PATH)
- self.wTree.get_widget("treeview_disks").append_column(self.column3)
- # Type
- ren = gtk.CellRendererText()
- self.column4 = gtk.TreeViewColumn(_("Type"), ren)
- self.column4.add_attribute(ren, "markup", INDEX_PARTITION_TYPE)
- self.wTree.get_widget("treeview_disks").append_column(self.column4)
- # description
- ren = gtk.CellRendererText()
- self.column5 = gtk.TreeViewColumn(_("Operating system"), ren)
- self.column5.add_attribute(ren, "markup", INDEX_PARTITION_DESCRIPTION)
- self.wTree.get_widget("treeview_disks").append_column(self.column5)
- # mount point
- ren = gtk.CellRendererText()
- self.column6 = gtk.TreeViewColumn(_("Mount point"), ren)
- self.column6.add_attribute(ren, "markup", INDEX_PARTITION_MOUNT_AS)
- self.wTree.get_widget("treeview_disks").append_column(self.column6)
- # format
- ren = gtk.CellRendererText()
- self.column7 = gtk.TreeViewColumn(_("Format?"), ren)
- self.column7.add_attribute(ren, "markup", INDEX_PARTITION_FORMAT_AS)
- self.wTree.get_widget("treeview_disks").append_column(self.column7)
- # size
- ren = gtk.CellRendererText()
- self.column8 = gtk.TreeViewColumn(_("Size"), ren)
- self.column8.add_attribute(ren, "markup", INDEX_PARTITION_SIZE)
- self.wTree.get_widget("treeview_disks").append_column(self.column8)
- # Used space
- ren = gtk.CellRendererText()
- self.column9 = gtk.TreeViewColumn(_("Free space"), ren)
- self.column9.add_attribute(ren, "markup", INDEX_PARTITION_FREE_SPACE)
- self.wTree.get_widget("treeview_disks").append_column(self.column9)
- self.wTree.get_widget("entry_your_name").connect("notify::text", self.assign_realname)
- self.wTree.get_widget("entry_username").connect("notify::text", self.assign_username)
- self.wTree.get_widget("entry_hostname").connect("notify::text", self.assign_hostname)
- # events for detecting password mismatch..
- self.wTree.get_widget("entry_userpass1").connect("changed", self.assign_password)
- self.wTree.get_widget("entry_userpass2").connect("changed", self.assign_password)
- # link the checkbutton to the combobox
- grub_check = self.wTree.get_widget("checkbutton_grub")
- grub_box = self.wTree.get_widget("combobox_grub")
- grub_check.connect("clicked", self.assign_grub_install, grub_box)
- grub_box.connect("changed", self.assign_grub_device)
- # Install Grub by default
- grub_check.set_active(True)
- grub_box.set_sensitive(True)
-
- # kb models
- cell = gtk.CellRendererText()
- self.wTree.get_widget("combobox_kb_model").pack_start(cell, True)
- self.wTree.get_widget("combobox_kb_model").add_attribute(cell, 'text', 0)
- self.wTree.get_widget("combobox_kb_model").connect("changed", self.assign_keyboard_model)
- # kb layouts
- ren = gtk.CellRendererText()
- self.column10 = gtk.TreeViewColumn(_("Layout"), ren)
- self.column10.add_attribute(ren, "text", 0)
- self.wTree.get_widget("treeview_layouts").append_column(self.column10)
- self.wTree.get_widget("treeview_layouts").connect("cursor-changed", self.assign_keyboard_layout)
-
- ren = gtk.CellRendererText()
- self.column11 = gtk.TreeViewColumn(_("Variant"), ren)
- self.column11.add_attribute(ren, "text", 0)
- self.wTree.get_widget("treeview_variants").append_column(self.column11)
- self.wTree.get_widget("treeview_variants").connect("cursor-changed", self.assign_keyboard_variant)
-
- #self.build_kb_lists()
- # 'about to install' aka overview
- ren = gtk.CellRendererText()
- self.column12 = gtk.TreeViewColumn(_("Overview"), ren)
- self.column12.add_attribute(ren, "markup", 0)
- self.wTree.get_widget("treeview_overview").append_column(self.column12)
- # install page
- self.wTree.get_widget("label_install_progress").set_markup("<i>%s</i>" % _("Calculating file indexes..."))
-
- #i18n
- self.i18n()
- # build partition list
- self.should_pulse = False
- # make sure we're on the right page (no pun.)
- self.activate_page(0)
- # this is a hack atm to steal the menubar's background color
- self.wTree.get_widget("menubar").realize()
- style = self.wTree.get_widget("menubar").style.copy()
- self.wTree.get_widget("menubar").hide()
- # apply to the header
- self.wTree.get_widget("help_label").realize()
- self.wTree.get_widget("help_label").modify_fg(gtk.STATE_NORMAL, style.fg[gtk.STATE_NORMAL])
- if(fullscreen):
- # dedicated installer mode thingum
- self.window.maximize()
- self.window.fullscreen()
-
- #''' Launch the Slideshow '''
- #if ("_" in self.setup.language):
- # locale_code = self.setup.language.split("_")[0]
- #else:
- # locale_code = self.setup.language
-
- #slideshow_path = "/usr/share/live-installer-slideshow/slides/index.html"
- #if os.path.exists(slideshow_path):
- # browser = webkit.WebView()
- # s = browser.get_settings()
- # s.set_property('enable-file-access-from-file-uris', True)
- # s.set_property('enable-default-context-menu', False)
- # browser.open("file://" + slideshow_path + "#?locale=" + locale_code)
- # self.wTree.get_widget("vbox_install").add(browser)
- # self.wTree.get_widget("vbox_install").show_all()
-
- self.browser = webkit.WebView()
- s = self.browser.get_settings()
- s.set_property('enable-file-access-from-file-uris', True)
- s.set_property('enable-default-context-menu', False)
- self.wTree.get_widget("scrolled_partitions").add(self.browser)
-
- self.window.show_all()
-
- def i18n(self):
- # about you
- self.wTree.get_widget("label_your_name").set_markup("<b>%s</b>" % _("Your full name"))
- self.wTree.get_widget("label_your_name_help").set_label(_("This will be shown in the About Me application"))
- self.wTree.get_widget("label_username").set_markup("<b>%s</b>" % _("Your username"))
- self.wTree.get_widget("label_username_help").set_label(_("This is the name you will use to login to your computer"))
- self.wTree.get_widget("label_choose_pass").set_markup("<b>%s</b>" % _("Your password"))
- self.wTree.get_widget("label_pass_help").set_label(_("Please enter your password twice to ensure it is correct"))
- self.wTree.get_widget("label_hostname").set_markup("<b>%s</b>" % _("Hostname"))
- self.wTree.get_widget("label_hostname_help").set_label(_("This hostname will be the computers name on the network"))
-
- # grub
- self.wTree.get_widget("label_grub").set_markup("<b>%s</b>" % _("Bootloader"))
- self.wTree.get_widget("checkbutton_grub").set_label(_("Install GRUB"))
- self.wTree.get_widget("label_grub_help").set_label(_("GRUB is a bootloader used to load the Linux kernel"))
-
- # keyboard page
- self.wTree.get_widget("label_test_kb").set_label(_("Use this box to test your keyboard layout"))
- self.wTree.get_widget("label_kb_model").set_label(_("Model"))
-
- #Installation
- self.wTree.get_widget("label_install_1").set_label(_("Please wait while the operating system is installed on your computer."))
- self.wTree.get_widget("label_install_2").set_label(_("The installation should take approximately 10 minutes."))
- self.wTree.get_widget("label_install_3").set_label(_("We hope you enjoy this new release. Thank you for choosing Kazsid."))
-
- #Columns
- self.column1.set_title(_("Hard drive"))
- self.column2.set_title(_("Description"))
- self.column3.set_title(_("Device"))
- self.column4.set_title(_("Type"))
- self.column5.set_title(_("Operating system"))
- self.column6.set_title(_("Mount point"))
- self.column7.set_title(_("Format?"))
- self.column8.set_title(_("Size"))
- self.column9.set_title(_("Free space"))
- self.column10.set_title(_("Layout"))
- self.column11.set_title(_("Variant"))
- self.column12.set_title(_("Overview"))
- def assign_realname(self, entry, prop):
- self.setup.real_name = entry.props.text
- text = entry.props.text.strip().lower()
- if " " in entry.props.text:
- elements = text.split()
- text = elements[0]
- self.setup.username = text
- self.wTree.get_widget("entry_username").set_text(text)
- self.setup.print_setup()
- def assign_username(self, entry, prop):
- self.setup.username = entry.props.text
- self.setup.print_setup()
- def assign_hostname(self, entry, prop):
- self.setup.hostname = entry.props.text
- self.setup.print_setup()
-
- def quit_cb(self, widget, data=None):
- ''' ask whether we should quit. because touchpads do happen '''
- gtk.main_quit()
- def assign_partition(self, widget, data=None, data2=None):
- ''' assign the partition ... '''
- model, iter = self.wTree.get_widget("treeview_disks").get_selection().get_selected()
- if iter is not None:
- row = model[iter]
- partition = row[INDEX_PARTITION_OBJECT]
- if not partition.partition.type == parted.PARTITION_EXTENDED and not partition.partition.number == -1:
- dlg = PartitionDialog(row[INDEX_PARTITION_PATH], row[INDEX_PARTITION_MOUNT_AS], row[INDEX_PARTITION_FORMAT_AS], row[INDEX_PARTITION_TYPE])
- (mount_as, format_as) = dlg.show()
- self.assign_mount_point(partition, mount_as, format_as)
-
- def partitions_popup_menu( self, widget, event ):
- if event.button == 3:
- model, iter = self.wTree.get_widget("treeview_disks").get_selection().get_selected()
- if iter is not None:
- partition = model.get_value(iter, INDEX_PARTITION_OBJECT)
- partition_type = model.get_value(iter, INDEX_PARTITION_TYPE)
- if not partition.partition.type == parted.PARTITION_EXTENDED and not partition.partition.number == -1 and "swap" not in partition_type:
- menu = gtk.Menu()
- menuItem = gtk.MenuItem(_("Edit"))
- menuItem.connect( "activate", self.assign_partition, partition)
- menu.append(menuItem)
- menuItem = gtk.SeparatorMenuItem()
- menu.append(menuItem)
- menuItem = gtk.MenuItem(_("Assign to /"))
- menuItem.connect( "activate", self.assign_mount_point_context_menu_wrapper, partition, "/", "ext4")
- menu.append(menuItem)
- menuItem = gtk.MenuItem(_("Assign to /home"))
- menuItem.connect( "activate", self.assign_mount_point_context_menu_wrapper, partition, "/home", "")
- menu.append(menuItem)
- menu.show_all()
- menu.popup( None, None, None, event.button, event.time )
- def assign_mount_point_context_menu_wrapper(self, menu, partition, mount_point, filesystem):
- self.assign_mount_point(partition, mount_point, filesystem)
- def assign_mount_point(self, partition, mount_point, filesystem):
-
- #Assign it in the treeview
- model = self.wTree.get_widget("treeview_disks").get_model()
- iter = model.get_iter_first()
- while iter is not None:
- iter_partition = model.get_value(iter, INDEX_PARTITION_OBJECT)
- if iter_partition == partition:
- model.set_value(iter, INDEX_PARTITION_MOUNT_AS, mount_point)
- model.set_value(iter, INDEX_PARTITION_FORMAT_AS, filesystem)
- else:
- mountpoint = model.get_value(iter, INDEX_PARTITION_MOUNT_AS)
- if mountpoint == mount_point:
- model.set_value(iter, INDEX_PARTITION_MOUNT_AS, "")
- model.set_value(iter, INDEX_PARTITION_FORMAT_AS, "")
- iter = model.iter_next(iter)
- #Assign it in our setup
- for apartition in self.setup.partitions:
- if (apartition.partition.path == partition.partition.path):
- apartition.mount_as = mount_point
- apartition.format_as = filesystem
- else:
- if apartition.mount_as == mount_point:
- apartition.mount_as = None
- apartition.format_as = None
- self.setup.print_setup()
-
- def refresh_partitions(self, widget, data=None):
- ''' refresh the partitions ... '''
- self.build_partitions()
- def edit_partitions(self, widget, data=None):
- ''' edit the partitions ... '''
- os.popen("gparted &")
- def build_lang_list(self):
- #Try to find out where we're located...
- cur_country_code = None
- # try:
- # whatismyip = 'http://debian.linuxmint.com/installer/show_my_ip.php'
- # ip = urllib.urlopen(whatismyip).readlines()[0]
- # gi = GeoIP.new(GeoIP.GEOIP_MEMORY_CACHE)
- # cur_country_code = gi.country_code_by_addr(ip)
- # except:
- # pass #best effort, we get here if we're not connected to the Internet
- #Plan B... find out what locale we're in (i.e. USA on the live session)
- cur_lang = os.environ['LANG']
- if("." in cur_lang):
- cur_lang = cur_lang.split(".")[0]
- model = gtk.ListStore(str,str,gtk.gdk.Pixbuf)
- model.set_sort_column_id(0, gtk.SORT_ASCENDING)
- #Load countries into memory
- countries = {}
- file = open(os.path.join(self.resource_dir, 'countries'), "r")
- for line in file:
- line = line.strip()
- split = line.split("=")
- if len(split) == 2:
- countries[split[0]] = split[1]
- file.close()
- #Load languages into memory
- languages = {}
- file = open(os.path.join(self.resource_dir, 'languages'), "r")
- for line in file:
- line = line.strip()
- split = line.split("=")
- if len(split) == 2:
- languages[split[0]] = split[1]
- file.close()
- path = os.path.join(self.resource_dir, 'locales')
- locales = open(path, "r")
- cur_index = -1 # find the locale :P
- set_index = None
- for line in locales:
- cur_index += 1
- if "UTF-8" in line:
- locale_code = line.replace("UTF-8", "")
- locale_code = locale_code.replace(".", "")
- locale_code = locale_code.strip()
- if "_" in locale_code:
- split = locale_code.split("_")
- if len(split) == 2:
- language_code = split[0]
- if language_code in languages:
- language = languages[language_code]
- else:
- language = language_code
- country_code = split[1].lower()
- if country_code in countries:
- country = countries[country_code]
- else:
- country = country_code
- language_label = "%s (%s)" % (language, country)
- #language_label = "%s - %s" % (country, language)
- iter = model.append()
- model.set_value(iter, 0, language_label)
- model.set_value(iter, 1, locale_code)
- flag_path = self.resource_dir + '/flags/16/' + country_code + '.png'
- if os.path.exists(flag_path):
- model.set_value(iter, 2, gtk.gdk.pixbuf_new_from_file(flag_path))
- else:
- flag_path = self.resource_dir + '/flags/16/generic.png'
- model.set_value(iter, 2, gtk.gdk.pixbuf_new_from_file(flag_path))
- # If it's matching our country code, that's our language right there..
- if ((cur_country_code is not None) and (cur_country_code.lower() == country_code)):
- if (set_index is None):
- set_index = iter
- else:
- # If we find more than one language for a particular country, one of them being English, go for English by default.
- if (language_code == "en"):
- set_index = iter
- # Guesswork... handy for countries which have their own language (fr_FR, de_DE, es_ES.. etc. )
- elif (country_code == language_code):
- set_index = iter
-
- # as a plan B... use the locale (USA)
- if((set_index is None) and (locale_code == cur_lang)):
- set_index = iter
- #print "Set via locale: " + cur_lang
- treeview = self.wTree.get_widget("treeview_language_list")
- treeview.set_model(model)
- if(set_index is not None):
- column = treeview.get_column(0)
- path = model.get_path(set_index)
- treeview.set_cursor(path, focus_column=column)
- treeview.scroll_to_cell(path, column=column)
- treeview.set_search_column(0)
- def build_timezones(self):
- model = gtk.ListStore(str, str)
- model.set_sort_column_id(0, gtk.SORT_ASCENDING)
- path = os.path.join(self.resource_dir, 'timezones')
- timezones = open(path, "r")
- cur_index = -1 # find the timezone :P
- set_index = None
- for line in timezones:
- cur_index += 1
- content = line.strip().split()
- if len(content) == 2:
- country_code = content[0]
- timezone = content[1]
- iter = model.append()
- model.set_value(iter, 0, timezone)
- model.set_value(iter, 1, country_code)
- treeview = self.wTree.get_widget("treeview_timezones")
- treeview.set_model(model)
- treeview.set_search_column(0)
-
- def build_hdds(self):
- self.setup.disks = []
- model = gtk.ListStore(str, str)
- inxi = subprocess.Popen("inxi -c0 -D", shell=True, stdout=subprocess.PIPE)
- for line in inxi.stdout:
- line = line.rstrip("\r\n")
- if(line.startswith("Disks:")):
- line = line.replace("Disks:", "")
- sections = line.split(":")
- for section in sections:
- section = section.strip()
- if("/dev/" in section):
- elements = section.split()
- for element in elements:
- if "/dev/" in element:
- self.setup.disks.append(element)
- description = section.replace(element, "").strip()
- iter = model.append([element, description]);
-
- self.wTree.get_widget("treeview_hdds").set_model(model)
-
- if(len(self.setup.disks) > 0):
- # select the first HDD
- treeview = self.wTree.get_widget("treeview_hdds")
- column = treeview.get_column(0)
- path = model.get_path(model.get_iter_first())
- treeview.set_cursor(path, focus_column=column)
- treeview.scroll_to_cell(path, column=column)
- self.setup.target_disk = model.get_value(model.get_iter_first(), 0)
-
- def build_grub_partitions(self):
- grub_model = gtk.ListStore(str)
- # Add disks
- for disk in self.setup.disks:
- grub_model.append([disk])
- # Add partitions
- partitions = commands.getoutput("fdisk -l | grep ^/dev/").split("\n")
- for partition in partitions:
- try:
- partition = partition.split()[0].strip()
- if partition.startswith("/dev/"):
- grub_model.append([partition])
- except Exception, detail:
- print detail
- self.wTree.get_widget("combobox_grub").set_model(grub_model)
- self.wTree.get_widget("combobox_grub").set_active(0)
-
- def build_partitions(self):
- self.window.set_sensitive(False)
- # "busy" cursor.
- cursor = gtk.gdk.Cursor(gtk.gdk.WATCH)
- self.window.window.set_cursor(cursor)
-
- os.popen('mkdir -p /tmp/live-installer/tmpmount')
-
- try:
- #grub_model = gtk.ListStore(str)
- self.setup.partitions = []
-
- html_partitions = ""
- model = gtk.ListStore(str,str,str,str,str,str,str, object, bool, str, str, bool)
- model2 = gtk.ListStore(str)
-
- swap_found = False
-
- if self.setup.target_disk is not None:
- path = self.setup.target_disk # i.e. /dev/sda
- #grub_model.append([path])
- device = parted.getDevice(path)
- try:
- disk = parted.Disk(device)
- except Exception:
- dialog = QuestionDialog(_("Installation Tool"), _("No partition table was found on the hard drive. Do you want the installer to create a set of partitions for you? Note: This will erase any data present on the disk."))
- if (dialog.show()):
- # Create a default partition set up
- disk = parted.freshDisk(device, 'msdos')
- disk.commit()
- #Swap
- regions = disk.getFreeSpaceRegions()
- if len(regions) > 0:
- region = regions[-1]
- ram_size = int(commands.getoutput("cat /proc/meminfo | grep MemTotal | awk {'print $2'}")) # in KiB
- post_mbr_gap = parted.sizeToSectors(1, "MiB", device.sectorSize) # Grub2 requires a post-MBR gap
- start = post_mbr_gap
- num_sectors = parted.sizeToSectors(ram_size, "KiB", device.sectorSize)
- num_sectors = int(float(num_sectors) * 1.5) # Swap is 1.5 times bigger than RAM
- end = start + num_sectors
- cylinder = device.endSectorToCylinder(end)
- end = device.endCylinderToSector(cylinder)
- geometry = parted.Geometry(device=device, start=start, end=end)
- if end < region.length:
- partition = parted.Partition(disk=disk, type=parted.PARTITION_NORMAL, geometry=geometry)
- constraint = parted.Constraint(exactGeom=geometry)
- disk.addPartition(partition=partition, constraint=constraint)
- disk.commit()
- os.system("mkswap %s" % partition.path)
- #Root
- regions = disk.getFreeSpaceRegions()
- if len(regions) > 0:
- region = regions[-1]
- partition = parted.Partition(disk=disk, type=parted.PARTITION_NORMAL, geometry=region)
- constraint = parted.Constraint(exactGeom=region)
- disk.addPartition(partition=partition, constraint=constraint)
- disk.commit()
- os.system("mkfs.ext4 %s" % partition.path)
-
- self.build_partitions()
- return
- else:
- # Do nothing... just get out of here..
- raise
- partition = disk.getFirstPartition()
- last_added_partition = PartitionSetup(partition)
- #self.setup.partitions.append(last_added_partition)
- partition = partition.nextPartition()
- html_partitions = html_partitions + "<table width='100%'><tr>"
- while (partition is not None):
- if last_added_partition.partition.number == -1 and partition.number == -1:
- last_added_partition.add_partition(partition)
- else:
- last_added_partition = PartitionSetup(partition)
-
- if "swap" in last_added_partition.type:
- last_added_partition.type = "swap"
- if partition.number != -1 and "swap" not in last_added_partition.type and partition.type != parted.PARTITION_EXTENDED:
-
- #grub_model.append([partition.path])
- #Umount temp folder
- if ('/tmp/live-installer/tmpmount' in commands.getoutput('mount')):
- os.popen('umount /tmp/live-installer/tmpmount')
- #Mount partition if not mounted
- if (partition.path not in commands.getoutput('mount')):
- os.system("mount %s /tmp/live-installer/tmpmount" % partition.path)
- #Identify partition's description and used space
- if (partition.path in commands.getoutput('mount')):
- df_lines = commands.getoutput("df 2>/dev/null | grep %s" % partition.path).split('\n')
- for df_line in df_lines:
- df_elements = df_line.split()
- if df_elements[0] == partition.path:
- last_added_partition.used_space = df_elements[4]
- mount_point = df_elements[5]
- if "%" in last_added_partition.used_space:
- used_space_pct = int(last_added_partition.used_space.replace("%", "").strip())
- last_added_partition.free_space = int(float(last_added_partition.size) * (float(100) - float(used_space_pct)) / float(100))
-
- if os.path.exists(os.path.join(mount_point, 'etc/lsb-release')):
- last_added_partition.description = commands.getoutput("cat " + os.path.join(mount_point, 'etc/lsb-release') + " | grep DISTRIB_DESCRIPTION").replace('DISTRIB_DESCRIPTION', '').replace('=', '').replace('"', '').strip()
- if os.path.exists(os.path.join(mount_point, 'etc/issue')):
- last_added_partition.description = commands.getoutput("cat " + os.path.join(mount_point, 'etc/issue')).replace('\\n', '').replace('\l', '').strip()
- if os.path.exists(os.path.join(mount_point, 'Windows/servicing/Version')):
- version = commands.getoutput("ls %s" % os.path.join(mount_point, 'Windows/servicing/Version'))
- if version.startswith("6.1"):
- last_added_partition.description = "Windows 7"
- elif version.startswith("6.0"):
- last_added_partition.description = "Windows Vista"
- elif version.startswith("5.1") or version.startswith("5.2"):
- last_added_partition.description = "Windows XP"
- elif version.startswith("5.0"):
- last_added_partition.description = "Windows 2000"
- elif version.startswith("4.90"):
- last_added_partition.description = "Windows Me"
- elif version.startswith("4.1"):
- last_added_partition.description = "Windows 98"
- elif version.startswith("4.0.1381"):
- last_added_partition.description = "Windows NT"
- elif version.startswith("4.0.950"):
- last_added_partition.description = "Windows 95"
- elif os.path.exists(os.path.join(mount_point, 'Boot/BCD')):
- if os.system("grep -qs \"V.i.s.t.a\" " + os.path.join(mount_point, 'Boot/BCD')) == 0:
- last_added_partition.description = "Windows Vista bootloader"
- elif os.system("grep -qs \"W.i.n.d.o.w.s. .7\" " + os.path.join(mount_point, 'Boot/BCD')) == 0:
- last_added_partition.description = "Windows 7 bootloader"
- elif os.system("grep -qs \"W.i.n.d.o.w.s. .R.e.c.o.v.e.r.y. .E.n.v.i.r.o.n.m.e.n.t\" " + os.path.join(mount_point, 'Boot/BCD')) == 0:
- last_added_partition.description = "Windows recovery"
- elif os.system("grep -qs \"W.i.n.d.o.w.s. .S.e.r.v.e.r. .2.0.0.8\" " + os.path.join(mount_point, 'Boot/BCD')) == 0:
- last_added_partition.description = "Windows Server 2008 bootloader"
- else:
- last_added_partition.description = "Windows bootloader"
- elif os.path.exists(os.path.join(mount_point, 'Windows/System32')):
- last_added_partition.description = "Windows"
- break
- else:
- print "Failed to mount %s" % partition.path
-
- #Umount temp folder
- if ('/tmp/live-installer/tmpmount' in commands.getoutput('mount')):
- os.popen('umount /tmp/live-installer/tmpmount')
-
- if last_added_partition.size > 1.0:
- if last_added_partition.partition.type == parted.PARTITION_LOGICAL:
- display_name = " " + last_added_partition.name
- else:
- display_name = last_added_partition.name
- iter = model.append([display_name, last_added_partition.type, last_added_partition.description, "", "", '%.0f' % round(last_added_partition.size, 0), last_added_partition.free_space, last_added_partition, False, last_added_partition.start, last_added_partition.end, False]);
- if last_added_partition.partition.number == -1:
- model.set_value(iter, INDEX_PARTITION_TYPE, "<span foreground='#a9a9a9'>%s</span>" % last_added_partition.type)
- elif last_added_partition.partition.type == parted.PARTITION_EXTENDED:
- model.set_value(iter, INDEX_PARTITION_TYPE, "<span foreground='#a9a9a9'>%s</span>" % _("Extended"))
- else:
- if last_added_partition.type == "ntfs":
- color = "#42e5ac"
- elif last_added_partition.type == "fat32":
- color = "#18d918"
- elif last_added_partition.type == "ext4":
- color = "#4b6983"
- elif last_added_partition.type == "ext3":
- color = "#7590ae"
- elif last_added_partition.type in ["linux-swap", "swap"]:
- color = "#c1665a"
- last_added_partition.mount_as = "swap"
- model.set_value(iter, INDEX_PARTITION_MOUNT_AS, "swap")
- else:
- color = "#a9a9a9"
- model.set_value(iter, INDEX_PARTITION_TYPE, "<span foreground='%s'>%s</span>" % (color, last_added_partition.type))
- html_partition = "<td class='partition-cell' title='$title' style='border: 3px solid $color;' width='$space%'><div class='partition'>\n <div style='width: $usage; background-color: #f8f8ba; height: 50px'></div>\n <div class='partition-text'>$path</div><div class='partition-os'>$OS</div>\n</div>\n</td>"
- deviceSize = float(device.getSize()) * float(0.9) # Hack.. reducing the real size to 90% of what it is, to make sure our partitions fit..
- space = int((float(partition.getSize()) / deviceSize) * float(80))
- subs = {}
- if (space >= 10):
- subs['path'] = display_name.replace("/dev/", "")
- subs['OS'] = last_added_partition.description
- elif (space >= 5):
- subs['path'] = display_name.replace("/dev/", "")
- subs['OS'] = ""
- else:
- #Not enough space, don't write the name
- subs['path'] = ""
- subs['OS'] = ""
- subs['color'] = color
- if (space == 0):
- space = 1
- subs['space'] = space
- subs['title'] = display_name + "\n" + last_added_partition.description
- if "%" in last_added_partition.used_space:
- subs['usage'] = last_added_partition.used_space.strip()
- html_partition = string.Template(html_partition).safe_substitute(subs)
- html_partitions = html_partitions + html_partition
- self.setup.partitions.append(last_added_partition)
-
- partition = partition.nextPartition()
- html_partitions = html_partitions + "</tr></table>"
- #self.wTree.get_widget("combobox_grub").set_model(grub_model)
- #self.wTree.get_widget("combobox_grub").set_active(0)
-
- import tempfile
- html_header = "<html><head><style>body {background-color:#d6d6d6;} \
- .partition{position:relative; width:100%; float: left; background: white;} \
- .partition-cell{ position:relative; margin: 2px 5px 2px 0; padding: 1px; float: left; background: white;} \
- .partition-text{ position:absolute; top:10; text-align: center; width=100px; left: 0; right: 0; margin: 0 auto; font-size:12px; } \
- .partition-os{ position:absolute; top:30; text-align: center; width=100px; left: 0; right: 0; margin: 0 auto; font-size:10px; font-style:italic;color:#555555;} </style></head><body>"
- html_footer = "</body></html>"
- html = html_header + html_partitions + html_footer
-
- # create temporary file
- f = tempfile.NamedTemporaryFile(delete=False)
- f.write(html)
- f.close()
-
- self.browser.open(f.name)
- #browser.load_html_string(html, "file://")
- self.wTree.get_widget("scrolled_partitions").show_all()
- self.wTree.get_widget("treeview_disks").set_model(model)
-
-
- except Exception, detail:
- print detail
-
- self.window.set_sensitive(True)
- self.window.window.set_cursor(None)
-
- def build_kb_lists(self):
- ''' Do some xml kung-fu and load the keyboard stuffs '''
- # firstly we'll determine the layouts in use
- p = subprocess.Popen("setxkbmap -print",shell=True,stdout=subprocess.PIPE)
- for line in p.stdout:
- # strip it
- line = line.rstrip("\r\n")
- line = line.replace("{","")
- line = line.replace("}","")
- line = line.replace(";","")
- if("xkb_symbols" in line):
- # decipher the layout in use
- section = line.split("\"")[1] # split by the " mark
- self.setup.keyboard_layout = section.split("+")[1]
- if("xkb_geometry" in line):
- first_bracket = line.index("(") +1
- substr = line[first_bracket:]
- last_bracket = substr.index(")")
- substr = substr[0:last_bracket]
- keyboard_geom = substr
- p.poll()
- xml_file = '/usr/share/X11/xkb/rules/xorg.xml'
- model_models = gtk.ListStore(str,str)
- model_models.set_sort_column_id(0, gtk.SORT_ASCENDING)
- model_layouts = gtk.ListStore(str,str)
- model_layouts.set_sort_column_id(0, gtk.SORT_ASCENDING)
- dom = parse(xml_file)
- # if we find the users keyboard info we can set it in the list
- set_keyboard_model = None
- set_keyboard_layout = None
- set_keyboard_variant = None
- # grab the root element
- root = dom.getElementsByTagName('xkbConfigRegistry')[0]
- # build the list of models
- root_models = root.getElementsByTagName('modelList')[0]
- for element in root_models.getElementsByTagName('model'):
- conf = element.getElementsByTagName('configItem')[0]
- name = conf.getElementsByTagName('name')[0]
- desc = conf.getElementsByTagName('description')[0]
- #vendor = conf.getElementsByTagName('vendor')[0] # presently unused..
- iter_model = model_models.append([self.getText(desc.childNodes), self.getText(name.childNodes)])
- item = self.getText(name.childNodes)
- if(item == keyboard_geom):
- set_keyboard_model = iter_model
- root_layouts = root.getElementsByTagName('layoutList')[0]
- for element in root_layouts.getElementsByTagName('layout'):
- conf = element.getElementsByTagName('configItem')[0]
- name = conf.getElementsByTagName('name')[0]
- desc = conf.getElementsByTagName('description')[0]
- iter_layout = model_layouts.append([self.getText(desc.childNodes), self.getText(name.childNodes)])
- item = self.getText(name.childNodes)
- if(item == self.setup.keyboard_layout):
- set_keyboard_layout = iter_layout
- # now set the model
- self.wTree.get_widget("combobox_kb_model").set_model(model_models)
- self.wTree.get_widget("treeview_layouts").set_model(model_layouts)
- if(set_keyboard_layout is not None):
- # show it in the list
- treeview = self.wTree.get_widget("treeview_layouts")
- model = treeview.get_model()
- column = treeview.get_column(0)
- path = model.get_path(set_keyboard_layout)
- treeview.set_cursor(path, focus_column=column)
- treeview.scroll_to_cell(path, column=column)
- if(set_keyboard_model is not None):
- # show it in the combo
- combo = self.wTree.get_widget("combobox_kb_model")
- model = combo.get_model()
- combo.set_active_iter(set_keyboard_model) …
Large files files are truncated, but you can click here to view the full file