diff --git a/Makefile b/Makefile index 0a4875e..38d33db 100644 --- a/Makefile +++ b/Makefile @@ -51,17 +51,15 @@ install-dirs: install: install-dirs install-locales $(INSTALL_PROGRAM) src/usbinstall.py $(DESTDIR)$(mambadir)/usbinstall/usbinstall.py $(INSTALL_SCRIPT) src/usbinstall.sh $(DESTDIR)$(mambadir)/usbinstall/usbinstall.sh - $(INSTALL_PROGRAM) src/gui.py $(DESTDIR)$(mambadir)/usbinstall/gui.py $(INSTALL_DATA) src/fdisk_template $(DESTDIR)$(mambadir)/usbinstall/fdisk_template $(INSTALL_DATA) src/img/*.png $(DESTDIR)$(mambadir)/usbinstall/img/ # Crea un link in /usr/bin agli eseguibili in $(mambadir)/usbinstall - ln -s $(DESTDIR)$(mambadir)/usbinstall/usbinstall.py $(DESTDIR)$(bindir)/usbinstall.py - ln -s $(DESTDIR)$(mambadir)/usbinstall/usbinstall.sh $(DESTDIR)$(bindir)/usbinstall.sh + ln -s $(mambadir)/usbinstall/usbinstall.py $(DESTDIR)$(bindir)/usbinstall.py + ln -s $(mambadir)/usbinstall/usbinstall.sh $(DESTDIR)$(bindir)/usbinstall.sh clean: rm -f $(pck_catalogs:.po=.mo) - rm -f *.pyc rm -f $(dist_archive) dist: clean diff --git a/VERSION b/VERSION index 61acab0..eadcafc 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -VERSION=0.3 +VERSION=0.4 diff --git a/po/it.po b/po/it.po index e3d20e5..85a2174 100644 --- a/po/it.po +++ b/po/it.po @@ -91,3 +91,9 @@ msgstr "Processo di installazione avviato" msgid "Installation process completed" msgstr "Installazione terminata correttamente" + +msgid "Installation aborted" +msgstr "L'installazione è stata annullata" + +msgid "Are you sure to abort?" +msgstr "Sei sicuro di voler annullare l'installazione?" diff --git a/src/gui.py b/src/gui.py deleted file mode 100644 index d52b8f4..0000000 --- a/src/gui.py +++ /dev/null @@ -1,162 +0,0 @@ -# -*- coding: utf-8 -*- - -# Form implementation generated from reading ui file 'usbinstall.ui' -# -# Created: Fri Oct 14 18:57:57 2011 -# by: PyQt4 UI code generator 4.8.3 -# -# WARNING! All changes made in this file will be lost! - -from PyQt4 import QtCore, QtGui - -try: - _fromUtf8 = QtCore.QString.fromUtf8 -except AttributeError: - _fromUtf8 = lambda s: s - -class Ui_MainWindow(object): - def setupUi(self, MainWindow): - - - # Percorsi delle immagini del form (da scommentare le vars. delle icone che si voglono usare) - #---GNOME--- - img_help = "/usr/share/icons/gnome/24x24/status/dialog-question.png" - img_fOpen = "/usr/share/icons/gnome/32x32/actions/document-open.png" - img_refresh = "/usr/share/icons/gnome/24x24/actions/view-refresh.png" - window_icon = "/usr/share/icons/hicolor/32x32/apps/mamba.png" - - #---KDE--- (***Da testare***) - #img_help = "/opt/kde/share/icons/oxygen/22x22/status/dialog-information.png" - #img_fOpen = "/opt/kde/share/icons/oxygen/32x32/actions/document-open-folder.png" - #img_refresh = "/opt/kde/share/icons/oxygen/22x22/actions/view-refresh.png" - #window_icon = "/usr/share/icons/hicolor/32x32/apps/mamba.png" - - # Codice per la finestra - MainWindow.setObjectName(_fromUtf8("MainWindow")) - MainWindow.resize(500, 405) - MainWindow.setWindowIcon(QtGui.QIcon(_fromUtf8(window_icon))) - MainWindow.setWindowTitle(_fromUtf8("")) - self.centralwidget = QtGui.QWidget(MainWindow) - self.centralwidget.setObjectName(_fromUtf8("centralwidget")) - - # Immagine di sfondo - self.i_back = QtGui.QLabel(self.centralwidget) - self.i_back.setGeometry(QtCore.QRect(10, 10, 480, 300)) - self.i_back.setText(_fromUtf8("")) - self.i_back.setObjectName(_fromUtf8("i_back")) - - # Label della descrizione - self.l_descrizione = QtGui.QLabel(self.centralwidget) - self.l_descrizione.setGeometry(QtCore.QRect(10, 317, 251, 31)) - self.l_descrizione.setText(_fromUtf8("")) - self.l_descrizione.setObjectName(_fromUtf8("l_descrizione")) - - # Linea orizzontale di separazione - self.line = QtGui.QFrame(self.centralwidget) - self.line.setGeometry(QtCore.QRect(10, 350, 481, 20)) - self.line.setFrameShape(QtGui.QFrame.HLine) - self.line.setFrameShadow(QtGui.QFrame.Sunken) - self.line.setObjectName(_fromUtf8("line")) - - # Bottone Avanti - self.b_avanti = QtGui.QPushButton(self.centralwidget) - self.b_avanti.setGeometry(QtCore.QRect(400, 370, 90, 29)) - self.b_avanti.setObjectName(_fromUtf8("b_avanti")) - - # Bottone Indietro - self.b_indietro = QtGui.QPushButton(self.centralwidget) - self.b_indietro.setGeometry(QtCore.QRect(300, 370, 90, 29)) - self.b_indietro.setText(_fromUtf8("")) - self.b_indietro.setObjectName(_fromUtf8("b_indietro")) - - # Bottone di help - self.b_help = QtGui.QPushButton(self.centralwidget) - self.b_help.setGeometry(QtCore.QRect(464, 320, 26, 26)) - self.b_help.setText(_fromUtf8("")) - icon = QtGui.QIcon() - icon.addPixmap(QtGui.QPixmap(_fromUtf8(img_help)), QtGui.QIcon.Normal, QtGui.QIcon.Off) - self.b_help.setIcon(icon) - self.b_help.setIconSize(QtCore.QSize(24, 24)) - self.b_help.setFlat(True) - self.b_help.setObjectName(_fromUtf8("b_help")) - - # Casella di testo con il percorso del file scelto - self.t_file = QtGui.QLineEdit(self.centralwidget) - self.t_file.setGeometry(QtCore.QRect(212, 321, 222, 25)) - self.t_file.setObjectName(_fromUtf8("t_file")) - - # Immagine che rende piu lunga la casella di testo - self.pach1 = QtGui.QLabel(self.centralwidget) - self.pach1.setGeometry(QtCore.QRect(430, 320, 32, 27)) - self.pach1.setText(_fromUtf8("")) - self.pach1.setPixmap(QtGui.QPixmap(_fromUtf8("/usr/share/openmamba/usbinstall/img/pach1.png"))) - self.pach1.setObjectName(_fromUtf8("pach1")) - - # Bottone sopra la parte della finta casella di testo - self.b_apri_file = QtGui.QPushButton(self.centralwidget) - self.b_apri_file.setGeometry(QtCore.QRect(431, 320, 31, 27)) - self.b_apri_file.setText(_fromUtf8("")) - icon1 = QtGui.QIcon() - icon1.addPixmap(QtGui.QPixmap(_fromUtf8(img_fOpen)), QtGui.QIcon.Normal, QtGui.QIcon.Off) - self.b_apri_file.setIcon(icon1) - self.b_apri_file.setFlat(True) - self.b_apri_file.setObjectName(_fromUtf8("b_apri_file")) - - # Immagine del fumetto - self.n_img = QtGui.QLabel(self.centralwidget) - self.n_img.setGeometry(QtCore.QRect(289, 200, 211, 121)) - self.n_img.setText(_fromUtf8("")) - self.n_img.setPixmap(QtGui.QPixmap(_fromUtf8("/usr/share/openmamba/usbinstall/img/nuvola.png"))) - self.n_img.setObjectName(_fromUtf8("n_img")) - self.n_img.hide() - - # Testo del fumetto - self.n_testo = QtGui.QLabel(self.centralwidget) - self.n_testo.setGeometry(QtCore.QRect(298, 200, 181, 101)) - self.n_testo.setText(_fromUtf8("")) - self.n_testo.setOpenExternalLinks(True) - self.n_testo.setWordWrap(True) - self.n_testo.setObjectName(_fromUtf8("n_testo")) - self.n_testo.hide() - - # Croce del fumetto - self.n_chiudi = QtGui.QPushButton(self.centralwidget) - self.n_chiudi.setGeometry(QtCore.QRect(471, 202, 14, 14)) - self.n_chiudi.setText(_fromUtf8("")) - icon1 = QtGui.QIcon() - icon1.addPixmap(QtGui.QPixmap(_fromUtf8("/usr/share/openmamba/usbinstall/img/exit.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) - self.n_chiudi.setIcon(icon1) - self.n_chiudi.setFlat(True) - self.n_chiudi.hide() - - # Bottone del refresh della lista usb - self.b_refresh = QtGui.QPushButton(self.centralwidget) - self.b_refresh.setGeometry(QtCore.QRect(435, 320, 26, 26)) - self.b_refresh.setText(_fromUtf8("")) - icon2 = QtGui.QIcon() - icon2.addPixmap(QtGui.QPixmap(_fromUtf8(img_refresh)), QtGui.QIcon.Normal, QtGui.QIcon.Off) - self.b_refresh.setIcon(icon2) - self.b_refresh.setIconSize(QtCore.QSize(24, 24)) - self.b_refresh.setFlat(True) - self.b_refresh.setObjectName(_fromUtf8("pushButton_5")) - - # comboBox con la lista delle periferiche usb - self.l_usb = QtGui.QComboBox(self.centralwidget) - self.l_usb.setEnabled(True) - self.l_usb.setGeometry(QtCore.QRect(158, 320, 271, 25)) - self.l_usb.setEditable(False) - self.l_usb.setObjectName(_fromUtf8("comboBox")) - - #inizializza la progressbar - self.p_installazione = QtGui.QProgressBar(self.centralwidget) - self.p_installazione.setGeometry(QtCore.QRect(10, 354, 480, 36)) - self.p_installazione.setProperty("value", 0) - self.p_installazione.setObjectName("progressBar") - self.p_installazione.hide() - - self.retranslateUi(MainWindow) - QtCore.QMetaObject.connectSlotsByName(MainWindow) - - def retranslateUi(self, MainWindow): - self.b_avanti.setText(QtGui.QApplication.translate("MainWindow", "Avanti", None, QtGui.QApplication.UnicodeUTF8)) - diff --git a/src/usbinstall.py b/src/usbinstall.py index 509c270..b1787db 100644 --- a/src/usbinstall.py +++ b/src/usbinstall.py @@ -1,321 +1,428 @@ # -*- coding: utf-8 -*- #!/usr/bin/env python -from gui import * # Importa la parte grafica +# Copyright 2011 michiamophil (openmamba user :-) +# ChangeLog: +# (michiamophil on 11/11/11) Rewrited all the graphic code and removed gui.py -import gettext +from PyQt4 import QtGui, QtCore from subprocess import Popen -# La parte di dbus +import gettext # To translate import gobject import dbus import dbus.service from dbus.mainloop.glib import DBusGMainLoop if getattr(dbus, 'version', (0,0,0)) >= (0,41,0): import dbus.glib - -gettext.install('usbinstall', '/usr/share/locale', unicode=1) - -# Variabili globali -passo = 1 -p = "" # Processo del file .sh -ext = "" # Vedi apri_file() -path_Boot = "" # Percorso file.cpio.gz -path_Iso = "" # Percorso file.iso -sel_usb_file= ""# Chiavetta per l'installazione (file) -sel_usb_nome= ""# Modello -usb_file = [] # Lista chiavette disponibili -usb_nome = [] # Rispettivi modelli -## Assegna gli eventi agli oggetti del form -def assegna_eventi(): - app.connect(ui.b_avanti, QtCore.SIGNAL('clicked()'), avanti) - app.connect(ui.b_indietro, QtCore.SIGNAL('clicked()'), indietro) - app.connect(ui.b_apri_file, QtCore.SIGNAL('clicked()'), apri_file) - app.connect(ui.b_help, QtCore.SIGNAL('clicked()'), gestisci_nuvola) - app.connect(ui.n_chiudi, QtCore.SIGNAL('clicked()'), chiudi_nuvola) - app.connect(ui.b_refresh, QtCore.SIGNAL('clicked()'), lista_usb) - app.connect(ui.l_usb, QtCore.SIGNAL("activated(int)"), seleziona_usb) +#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ +#1)-------------------------------(VARIABILI)---------------------------------------- +#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ +# Icons +img_help = "/usr/share/icons/gnome/24x24/status/dialog-question.png" +img_fOpen = "/usr/share/icons/gnome/32x32/actions/document-open.png" +img_refresh = "/usr/share/icons/gnome/24x24/actions/view-refresh.png" +img_pach1 = "/usr/share/openmamba/usbinstall/img/pach1.png" +img_cloud = "/usr/share/openmamba/usbinstall/img/nuvola.png" +img_exit = "/usr/share/openmamba/usbinstall/img/exit.png" +window_icon = "/usr/share/icons/hicolor/32x32/apps/mamba.png" +# Global path +path_cpio = "" +path_iso = "" +path_dev = "" +# General vars +dev_model = "" +a_path_dev = [] # Array of choosen devices +a_dev_model = [] # Their models. +step = 1 +choose_type = "" # Type of dialog in choose_file() +#1)###############################(VARIABILI)######################################## -## Gestione del bottone b_avanti -def avanti(): - # Prima controlla che tutto sia a posto per passare al passo successivo - global passo, path_Boot, path_Iso, sel_usb_file, sel_usb_nome - - if passo == 1: - if path_Boot == "": + + +#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ +#2)-------------------------------(WINDOW CODE)-------------------------------------- +#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ +# Contains program's graphic +class create_window(QtGui.QDialog): + # Call when is called create_window() + def __init__(self): + super(create_window, self).__init__() # Register eventClose() + self.add_elements() + + # Write window and objects + def add_elements(self): + # Window proprieties + self.resize(500, 405) + self.setWindowIcon(QtGui.QIcon(window_icon)) + # Background image + self.i_back = QtGui.QLabel(self) + self.i_back.setGeometry(QtCore.QRect(10, 10, 480, 300)) + # Description label + self.l_descr = QtGui.QLabel(self) + self.l_descr.setGeometry(QtCore.QRect(10, 317, 251, 31)) + # Orizontal line + self.line = QtGui.QFrame(self) + self.line.setGeometry(QtCore.QRect(10, 350, 481, 20)) + self.line.setFrameShape(QtGui.QFrame.HLine) + self.line.setFrameShadow(QtGui.QFrame.Sunken) + # "Next" button + self.b_next = QtGui.QPushButton(self) + self.b_next.setGeometry(QtCore.QRect(400, 370, 90, 29)) + self.b_next.setText(_("Go on")) + # "Go Back" button + self.b_back = QtGui.QPushButton(self) + self.b_back.setGeometry(QtCore.QRect(300, 370, 90, 29)) + # "Help" button + self.b_help = QtGui.QPushButton(QtGui.QIcon(img_help), "", self) + self.b_help.setGeometry(QtCore.QRect(464, 320, 26, 26)) + self.b_help.setIconSize(QtCore.QSize(24, 24)) + self.b_help.setFlat(True) + # Path line edit + self.t_file = QtGui.QLineEdit(self) + self.t_file.setGeometry(QtCore.QRect(212, 321, 222, 25)) + # Pach line edit + self.pach1 = QtGui.QLabel(self) + self.pach1.setGeometry(QtCore.QRect(430, 320, 32, 27)) + self.pach1.setPixmap(QtGui.QPixmap(img_pach1)) + # Open file button + self.b_open_file = QtGui.QPushButton(QtGui.QIcon(img_fOpen), "", self) + self.b_open_file.setGeometry(QtCore.QRect(431, 320, 31, 27)) + self.b_open_file.setFlat(True) + # Help dialog image + self.i_cloud = QtGui.QLabel(self) + self.i_cloud.setGeometry(QtCore.QRect(289, 200, 211, 121)) + self.i_cloud.setPixmap(QtGui.QPixmap(img_cloud)) + self.i_cloud.hide() + # Help dialog text + self.l_cloud = QtGui.QLabel(self) + self.l_cloud.setGeometry(QtCore.QRect(298, 200, 181, 101)) + self.l_cloud.setOpenExternalLinks(True) + self.l_cloud.setWordWrap(True) + self.l_cloud.hide() + # Help dialog exit + self.b_cloud = QtGui.QPushButton(QtGui.QIcon(img_exit), "", self) + self.b_cloud.setGeometry(QtCore.QRect(471, 202, 14, 14)) + self.b_cloud.setFlat(True) + self.b_cloud.hide() + # Refresh button + self.b_refresh = QtGui.QPushButton(QtGui.QIcon(img_refresh), "", self) + self.b_refresh.setGeometry(QtCore.QRect(435, 320, 26, 26)) + self.b_refresh.setIconSize(QtCore.QSize(24, 24)) + self.b_refresh.setFlat(True) + # List of usb (combobox) + self.c_usb = QtGui.QComboBox(self) + self.c_usb.setGeometry(QtCore.QRect(158, 320, 271, 25)) + # Progressbar + self.p_install = QtGui.QProgressBar(self) + self.p_install.setGeometry(QtCore.QRect(10, 354, 480, 36)) + self.p_install.hide() + # Show the window + self.show() + + # Intercept close event + def closeEvent(self, event): + end_forced(event) +#2)###############################(WINDOW CODE)###################################### + + + + + +#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ +#3)-----------------------------(EVENTS HANDLER)------------------------------------- +#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ +def add_events(): + app.connect(window.b_next, QtCore.SIGNAL('clicked()'), go_on) # Event n°1 + app.connect(window.b_back, QtCore.SIGNAL('clicked()'), go_back) # Event n°2 + app.connect(window.b_open_file, QtCore.SIGNAL('clicked()'), choose_file) # Event n°3 + app.connect(window.b_help, QtCore.SIGNAL('clicked()'), manage_cloud) # Event n°4 + app.connect(window.b_cloud, QtCore.SIGNAL('clicked()'), close_cloud) # Event n°5 + app.connect(window.b_refresh, QtCore.SIGNAL('clicked()'), get_list) # Event n°6 + app.connect(window.c_usb, QtCore.SIGNAL("activated(int)"), set_usb) # Event n°7 + +# Event n°1 +def go_on(): + global step, path_cpio, path_iso, path_dev, dev_model + cloud_hide() + # Step n°1 to n°2 + if step == 1: + if path_cpio == "": msg_warn(_("A file .cpio is required")) return else: - passo += 1 - passo2() - - elif passo == 2: - if path_Iso == "": + step += 1 + step2() + # Step n°2 to n°3 + elif step == 2: + if path_iso == "": msg_warn(_("An openmamba's iso is required")) return else: - passo += 1 - passo3() - - elif passo == 3: - if sel_usb_file == "": + step += 1 + step3() + # Step n°3 to n°4 + elif step == 3: + if path_dev == "": msg_warn(_("You must choose a usb key")) return else: - msg = QtGui.QMessageBox.question(None, _("Attention"), _("All data on the key ") + sel_usb_nome + _(" will be lost. \n")+_("Are you sure to continue?"), - QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.Yes) - # Continua solo se l'utente preme il bottone Yes + msg = QtGui.QMessageBox.question(window, _("Attention"), _("All data on the key ") + dev_model + _(" will be lost. \n")+ _("Are you sure to continue?"), + QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No) + # Go on only if was pressed yes button if msg == QtGui.QMessageBox.Yes: - passo += 1 - passo4() + step += 1 + step4() else: return - - -## Gestione del bottone b_indietro -def indietro(): - global passo - passo -= 1 - - if passo == 0: +# Event n°2 +def go_back(): + global step + step -= 1 + cloud_hide() + obj_chang_hide() + # Step n°1 to n°0 -> exit + if step == 0: app.exit(1) print _("Application terminated by pressing \"cancel\" button") - - elif passo == 1: - passo1() - - elif passo == 2: - passo2() - - elif passo == 3: - passo3() - - -## Dialogo in cui si scegle i file per l'installazione -## Inoltre setta le variabili path_Boot e path_Iso e aggiorna la casella di testo con il percorso -def apri_file(): - global path_Boot, path_Iso, ext - if ext == "boot": - fileType = QtCore.QString("cpio *.cpio.gz") - nfileName = QtGui.QFileDialog.getOpenFileName(None, _("Choose the boot file"), "~", "File .cpio.gz (*.cpio.gz)", fileType) - path_Boot = nfileName - ui.t_file.setText(QtGui.QApplication.translate("Dialog", nfileName, None, QtGui.QApplication.UnicodeUTF8)) - elif ext == "iso": - fileType = QtCore.QString("iso *.iso") - nfileName = QtGui.QFileDialog.getOpenFileName(None, _("Choose the iso file"), "~", "File .iso (*.iso)", fileType) #26/10 path_Boot -> "~" - path_Iso = nfileName - ui.t_file.setText(QtGui.QApplication.translate("Dialog", nfileName, None, QtGui.QApplication.UnicodeUTF8)) + # Step n°2 to n°1 + elif step == 1: + step1() + # Step n°3 to n°2 + elif step == 2: + step2() + #~ NON SONO SICURO SERVA (DA TESTARE) + # Step n°4 to n°3 + elif step == 3: + step3() +# Event n°3 +def choose_file(): + global path_cpio, path_iso, choose_type + # If step in n°1 + if choose_type == "boot": + nfileName = QtGui.QFileDialog.getOpenFileName(window, _("Choose the boot file"), "/home", "File .cpio.gz (*.cpio.gz)", "cpio *.cpio.gz") + path_cpio = nfileName + window.t_file.setText(nfileName) + # Else if step is n°2 + elif choose_type == "iso": + nfileName = QtGui.QFileDialog.getOpenFileName(window, _("Choose the iso file"), "/home", "File .iso (*.iso)", "iso *.iso") + path_iso = nfileName + window.t_file.setText(nfileName) -## Visualizza l'aiuto -def gestisci_nuvola(): - global passo - # Aiuto in base al passo corrente - if passo == 1: +# Event n°4 +def manage_cloud(): + global step + if step == 1: aiuto = _("This archive is designed to make the usb bootable.") + _(" You can find this file here") - # Cambiata anche la lingua della pagina (lang=en) - elif passo == 2: + elif step == 2: aiuto = _("The file .iso contains the operating system. You can download it from here") - elif passo == 3: + elif step == 3: aiuto = _("Choose an usb key for the installation. All data will be lost") - ui.n_testo.setText(QtGui.QApplication.translate("Dialog", aiuto, None, QtGui.QApplication.UnicodeUTF8)) - ui.n_img.show() # Immagine della nuvola - ui.n_testo.show() # Testo della nuvola - ui.n_chiudi.show() + window.l_cloud.setText(aiuto) + cloud_show() -## Nasconde la nuvola -def chiudi_nuvola(): - ui.n_img.hide() - ui.n_testo.hide() - ui.n_chiudi.hide() +# Event n°5 +def close_cloud(): + cloud_hide() -## Lista periferiche usb e le aggiuge alla lista (widget) -def lista_usb(): - import dbus - global usb_file, usb_nome +# Event n°6 +def get_list(): + global a_path_dev, a_dev_model - # Cancella i valori precedenti - usb_file = [] - usb_nome = [] - ui.l_usb.clear() + # Clear array and comboBox + a_path_dev = [] + a_dev_model = [] + window.c_usb.clear() i = 0 - # Riceve da dbus le chiavette collegate al pc + # Get list form dbus bus = dbus.SystemBus() ud_manager_obj = bus.get_object('org.freedesktop.UDisks', '/org/freedesktop/UDisks') ud_manager = dbus.Interface(ud_manager_obj, 'org.freedesktop.UDisks') for dev in ud_manager.EnumerateDevices(): device_obj = bus.get_object('org.freedesktop.UDisks', dev) device_props = dbus.Interface(device_obj, dbus.PROPERTIES_IFACE) - # Se lo spazio e' minore di 1GB salta l'usb corrente + # If dev.space > 1 Gb if(device_props.Get('org.freedesktop.UDisks.Device', 'PartitionSize')) > 1073741823: - # Se e' un device rimuovibile (== chiavetta usb) + # If dev is removable if(device_props.Get('org.freedesktop.UDisks.Device', 'DeviceIsRemovable')): - usb_file.append(device_props.Get('org.freedesktop.UDisks.Device', 'DeviceFile')) - usb_nome.append(device_props.Get('org.freedesktop.UDisks.Device', 'DriveModel')) - ui.l_usb.addItem(usb_file[i] + " " + usb_nome[i]) + # Populate the arrays + a_path_dev.append(device_props.Get('org.freedesktop.UDisks.Device', 'DeviceFile')) + a_dev_model.append(device_props.Get('org.freedesktop.UDisks.Device', 'DriveModel')) + # And add element to comboBox + window.c_usb.addItem(a_path_dev[i] + " " + a_dev_model[i]) i += 1 - - # Imposta il primo come quello di default - if len(usb_file) != 0: - seleziona_usb(0) + + # First dev is default + if len(a_path_dev) != 0: + set_usb(0) else: print _("No usb available > 1 Gb") - - -## Abbreviazione di un warning -def msg_warn(testo): - msg = QtGui.QMessageBox.warning(None, _("Attention"), testo) -## Aggiorna gli oggetti al cambio del passo -def aggiorna_oggetti(immagine, titolo, descrizione): - # Funzioni che servono solo qua dentro - def nascondi_oggetti(): - ui.l_usb.hide() - ui.b_refresh.hide() - ui.t_file.hide() - ui.pach1.hide() - ui.b_apri_file.hide() - - def visualizza_lista_usb(): - ui.l_usb.show() - ui.b_refresh.show() - - def visualizza_scegli_file(): - ui.t_file.show() - ui.pach1.show() - ui.b_apri_file.show() - - global passo, ext, path_Boot, path_Iso - - nascondi_oggetti() - if passo == 1: - ext = "boot" - path_Boot = "" - ui.b_indietro.setText(QtGui.QApplication.translate("Dialog", _("Cancel"), None, QtGui.QApplication.UnicodeUTF8)) - # Visualizzo gli oggetti del passo 1 - visualizza_scegli_file() - # Chiudi la nuovola dell'help al cambio di passo - chiudi_nuvola() - elif passo == 2: - ext = "iso" - path_Iso = "" - ui.b_indietro.setText(QtGui.QApplication.translate("Dialog", _("Go back"), None, QtGui.QApplication.UnicodeUTF8)) - visualizza_scegli_file() - # Chiudi la nuovola dell'help al cambio di passo - chiudi_nuvola() - elif passo == 3: - visualizza_lista_usb() - lista_usb() - # Chiudi la nuovola dell'help al cambio di passo - chiudi_nuvola() - elif passo == 4: - chiudi_nuvola() - ui.t_file.setText(QtGui.QApplication.translate("Dialog", "", None, QtGui.QApplication.UnicodeUTF8)) - ui.i_back.setPixmap(QtGui.QPixmap(immagine)) - Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", titolo, None, QtGui.QApplication.UnicodeUTF8)) - ui.l_descrizione.setText(QtGui.QApplication.translate("Dialog", descrizione, None, QtGui.QApplication.UnicodeUTF8)) - - - -## Setta la variabili globali sel_usb_* con l'usb scelto -def seleziona_usb(i): - global sel_usb_file, usb_file, sel_usb_nome, usb_nome - sel_usb_file = usb_file[i] - sel_usb_nome = usb_nome[i] - +# Event n°7 +def set_usb(i): + global path_dev, dev_model, a_path_dev, a_dev_model + path_dev = a_path_dev[i] + dev_model = a_dev_model[i] +#3)#############################(EVENTS HANDLER)##################################### -### Inizio dei vari passi +#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ +#4)-------------------------------(DBUS CODE)---------------------------------------- +#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ +# Class for dbus_start() +class set_dbus(dbus.service.Object): + def __init__(self, bus_name, object_path='/org/openmamba/usbinstall'): + dbus.service.Object.__init__(self, bus_name, object_path) -def passo1(): - ui.b_avanti.setText(QtGui.QApplication.translate("Dialog", _("Go on"), None, QtGui.QApplication.UnicodeUTF8)) - aggiorna_oggetti("/usr/share/openmamba/usbinstall/img/back1.png", _("Step 1/4 - choice of boot file"), _("Choose the .cpio file")) - -def passo2(): - aggiorna_oggetti("/usr/share/openmamba/usbinstall/img/back2.png", _("Step 2/4 - choice of iso file"), _("Choose the openmamba .iso file")) - -def passo3(): - aggiorna_oggetti("/usr/share/openmamba/usbinstall/img/back3.png", _("Step 3/4 - choice of usb key"), _("Choose the usb key")) - + @dbus.service.method('org.openmamba.usbinstall') + def Set_progressBar(self, p): + window.p_install.setProperty("value", int(p)) + if p == 100: + end_with_success() + return 0 - -def passo4(): - global p - aggiorna_oggetti("/usr/share/openmamba/usbinstall/img/back4.png", _("Step 4/4 - installation of openmamba to usb"), _("Installation in progress...")) - - # Nasconde gli oggetti superflui: - ui.b_help.hide() - ui.line.hide() - ui.b_indietro.hide() - ui.b_avanti.hide() - # Mostra la progressBar - ui.p_installazione.show() - init_ascolto() - p = Popen(["./usbinstall.sh", "start", sel_usb_file, path_Boot, path_Iso]) - print _("Installation process started") + @dbus.service.method('org.openmamba.usbinstall') + def Set_description(self, descr): + window.l_descr.setText(descr) + return 0 - -def init_ascolto(): +def dbus_start(): session_bus = dbus.SessionBus() bus_name = dbus.service.BusName('org.openmamba.usbinstall', bus=session_bus) - dbus_loop = setta_dbus(bus_name) + dbus_loop = set_dbus(bus_name) bus = dbus.SessionBus(mainloop=dbus_loop) +#4)###############################(DBUS CODE)######################################## -class setta_dbus(dbus.service.Object): - def __init__(self, bus_name, object_path='/org/openmamba/usbinstall'): - dbus.service.Object.__init__(self, bus_name, object_path) - - @dbus.service.method('org.openmamba.usbinstall') - def Pbar_aggiorna(self, p): - ui.p_installazione.setProperty("value", int(p)) - if p == 100: - installazione_terminata() - return 0 - @dbus.service.method('org.openmamba.usbinstall') - def Descrizione(self, desc): - ui.l_descrizione.setText(QtGui.QApplication.translate("Dialog",desc, None, QtGui.QApplication.UnicodeUTF8)) - return 0 +#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ +#5)------------------------------(PROGRAM CODE)-------------------------------------- +#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ +# Show all cloud objects +def cloud_show(): + window.i_cloud.show() + window.b_cloud.show() + window.l_cloud.show() - @dbus.service.method('org.openmamba.usbinstall') - def Esci(self): +# Hide all cloud objects +def cloud_hide(): + window.i_cloud.hide() + window.b_cloud.hide() + window.l_cloud.hide() + +# Warning dialog abbreviation +def msg_warn(txt): + msg = QtGui.QMessageBox.warning(window, _("Attention"), txt) + +# Called when b_next was pressed +def set_objs(i_back, title, descr): + + window.i_back.setPixmap(QtGui.QPixmap(i_back)) + window.setWindowTitle(title) + window.l_descr.setText(descr) + + +def step1(): + global choose_type, path_cpio + choose_type = "boot" + path_cpio = "" + window.t_file.setText(path_cpio) # Clean path box + window.b_back.setText(_("Cancel")) + set_objs("/usr/share/openmamba/usbinstall/img/back1.png", _("Step 1/4 - choice of boot file"), _("Choose the .cpio file")) + obj_chang_hide() + list_obj1() # Show a set of object + +def step2(): + global choose_type, path_iso + choose_type = "iso" + path_iso = "" + window.t_file.setText(path_iso) # Clean path box + window.b_back.setText(_("Go back")) + set_objs("/usr/share/openmamba/usbinstall/img/back2.png", _("Step 2/4 - choice of iso file"), _("Choose the openmamba .iso file")) + obj_chang_hide() + list_obj1() # Show a set of object + +def step3(): + set_objs("/usr/share/openmamba/usbinstall/img/back3.png", _("Step 3/4 - choice of usb key"), _("Choose the usb key")) + obj_chang_hide() + list_obj2() + get_list() # Get available devices + +def step4(): + global process_sh + set_objs("/usr/share/openmamba/usbinstall/img/back4.png", _("Step 4/4 - installation of openmamba to usb"), _("Installation in progress...")) + # Hide all unnecessary objects + obj_chang_hide() + window.b_help.hide() + window.line.hide() + window.b_back.hide() + window.b_next.hide() + # Show the progressBar + window.p_install.show() + dbus_start() + process_sh = Popen(["/usr/bin/usbinstall.sh", "start", path_dev, path_cpio, path_iso]) + + +# Show a list of object (step 1 and 2) +def list_obj1(): + window.t_file.show() + window.pach1.show() + window.b_open_file.show() + +# Show a list of object (step 3) +def list_obj2(): + window.c_usb.show() + window.b_refresh.show() + +# Hide all object that when b_next or b_back was pressed are changing +def obj_chang_hide(): + window.t_file.hide() + window.pach1.hide() + window.b_open_file.hide() + window.c_usb.hide() + window.b_refresh.hide() + +def end_with_success(): + global process_sh, mainloop + msg = QtGui.QMessageBox.information(window, _("Information"), _("Installation process completed")) + process_sh.terminate() mainloop.quit() app.exit(0) + print _("Installation process completed") -# Termina lo scipt e dbus insieme alla finestra -def closeEvent(form, event): - installazione_terminata() +def end_forced(event): + global process_sh, mainloop + msg = QtGui.QMessageBox.question(window, _("Attention"), _("Are you sure to abort?"), QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No) + # Exit if was pressed yes button + if msg == QtGui.QMessageBox.Yes: + process_sh.kill() + mainloop.quit() + print _("Installation aborted") + app.exit(1) + else: + event.ignore() - -def installazione_terminata(): - global p - msg = QtGui.QMessageBox.information(None, _("Information"), _("Installation process completed")) - p.terminate() - mainloop.quit() - app.exit(0) - -# Inizializza la parte grafica +# Program start app = QtGui.QApplication([]) -Dialog = QtGui.QDialog() -ui = Ui_MainWindow() -ui.setupUi(Dialog) +gettext.install('usbinstall', '/usr/share/locale', unicode=1) +window = create_window() mainloop = gobject.MainLoop() def run(): - assegna_eventi() - passo1() - Dialog.show() # Mostra il dialog precedentemente creato + add_events() + step1() return app.exec_() - if __name__ == "__main__": run() - - +#5)##############################(PROGRAM CODE)###################################### + + + diff --git a/src/usbinstall.sh b/src/usbinstall.sh index 73fd5ce..033bcbe 100755 --- a/src/usbinstall.sh +++ b/src/usbinstall.sh @@ -28,8 +28,8 @@ inst_new_part() #3 Formatta la partizione (e la monta) inst_format() { - - sudo mkfs.ext3 ${1}1 -L openmamba_live + #add_progress 5 29 1 & + sudo mkfs.ext3 ${1}1 -L openmamba_live mkdir -p ~/tmpmamba sudo mount ${1}1 ~/tmpmamba sudo chmod 777 ~/tmpmamba @@ -70,28 +70,31 @@ inst_copy_iso() #7 Smonta la chiavetta inst_dir_umount() { - # So it attend up to umount return without errors - - while [ 1 ] ; do - sudo umount ${1} - if [ $? != 1 ]; then - break - fi - done + sleep 5 + sudo umount ${1}1 echo "Done" - rmdir ~/tmpmamba } +# $1 begin value; $2 max value; $3 sleep time; +#add_progress() +#{ +# while [ $1 <= $2 ] ; do +# $1 += 1 +# dbus-send --print-reply --session --dest=org.openmamba.usbinstall /org/openmamba/usbinstall org.openmamba.usbinstall.Set_progressBar int32:$1 +# sleep $3 +# done + +#} + # Aggiorna la progressbar $1 == % pbar() { - dbus-send --print-reply --session --dest=org.openmamba.usbinstall /org/openmamba/usbinstall org.openmamba.usbinstall.Pbar_aggiorna int32:$1 + dbus-send --print-reply --session --dest=org.openmamba.usbinstall /org/openmamba/usbinstall org.openmamba.usbinstall.Set_progressBar int32:$1 } descrizione() { - - dbus-send --print-reply --session --dest=org.openmamba.usbinstall /org/openmamba/usbinstall org.openmamba.usbinstall.Descrizione "string:$1" + dbus-send --print-reply --session --dest=org.openmamba.usbinstall /org/openmamba/usbinstall org.openmamba.usbinstall.Set_description "string:$1" } @@ -104,7 +107,7 @@ if [ $1 == "start" ]; then inst_new_part $2 pbar 5 inst_format $2 - pbar 20 + pbar 30 descrizione "Estrazione del file di boot in corso..." inst_extr_boot $3 @@ -121,9 +124,8 @@ if [ $1 == "start" ]; then descrizione "Smonto la chiavetta" inst_dir_umount $2 pbar 100 - + else echo $1 "Parametri non validi" - fi