Revrite the program

This commit is contained in:
Filippo Bedendo Bordon 2011-11-13 18:04:35 +01:00
parent 2834485f12
commit 045652dcd8
6 changed files with 378 additions and 427 deletions

View File

@ -51,17 +51,15 @@ install-dirs:
install: install-dirs install-locales install: install-dirs install-locales
$(INSTALL_PROGRAM) src/usbinstall.py $(DESTDIR)$(mambadir)/usbinstall/usbinstall.py $(INSTALL_PROGRAM) src/usbinstall.py $(DESTDIR)$(mambadir)/usbinstall/usbinstall.py
$(INSTALL_SCRIPT) src/usbinstall.sh $(DESTDIR)$(mambadir)/usbinstall/usbinstall.sh $(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/fdisk_template $(DESTDIR)$(mambadir)/usbinstall/fdisk_template
$(INSTALL_DATA) src/img/*.png $(DESTDIR)$(mambadir)/usbinstall/img/ $(INSTALL_DATA) src/img/*.png $(DESTDIR)$(mambadir)/usbinstall/img/
# Crea un link in /usr/bin agli eseguibili in $(mambadir)/usbinstall # Crea un link in /usr/bin agli eseguibili in $(mambadir)/usbinstall
ln -s $(DESTDIR)$(mambadir)/usbinstall/usbinstall.py $(DESTDIR)$(bindir)/usbinstall.py ln -s $(mambadir)/usbinstall/usbinstall.py $(DESTDIR)$(bindir)/usbinstall.py
ln -s $(DESTDIR)$(mambadir)/usbinstall/usbinstall.sh $(DESTDIR)$(bindir)/usbinstall.sh ln -s $(mambadir)/usbinstall/usbinstall.sh $(DESTDIR)$(bindir)/usbinstall.sh
clean: clean:
rm -f $(pck_catalogs:.po=.mo) rm -f $(pck_catalogs:.po=.mo)
rm -f *.pyc
rm -f $(dist_archive) rm -f $(dist_archive)
dist: clean dist: clean

View File

@ -1 +1 @@
VERSION=0.3 VERSION=0.4

View File

@ -91,3 +91,9 @@ msgstr "Processo di installazione avviato"
msgid "Installation process completed" msgid "Installation process completed"
msgstr "Installazione terminata correttamente" 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?"

View File

@ -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))

View File

@ -1,12 +1,14 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
#!/usr/bin/env python #!/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 from subprocess import Popen
# La parte di dbus import gettext # To translate
import gobject import gobject
import dbus import dbus
import dbus.service import dbus.service
@ -14,308 +16,413 @@ from dbus.mainloop.glib import DBusGMainLoop
if getattr(dbus, 'version', (0,0,0)) >= (0,41,0): if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
import dbus.glib import dbus.glib
gettext.install('usbinstall', '/usr/share/locale', unicode=1)
# Variabili globali #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
passo = 1 #1)-------------------------------(VARIABILI)----------------------------------------
p = "" # Processo del file .sh #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
ext = "" # Vedi apri_file() # Icons
path_Boot = "" # Percorso file.cpio.gz img_help = "/usr/share/icons/gnome/24x24/status/dialog-question.png"
path_Iso = "" # Percorso file.iso img_fOpen = "/usr/share/icons/gnome/32x32/actions/document-open.png"
sel_usb_file= ""# Chiavetta per l'installazione (file) img_refresh = "/usr/share/icons/gnome/24x24/actions/view-refresh.png"
sel_usb_nome= ""# Modello img_pach1 = "/usr/share/openmamba/usbinstall/img/pach1.png"
usb_file = [] # Lista chiavette disponibili img_cloud = "/usr/share/openmamba/usbinstall/img/nuvola.png"
usb_nome = [] # Rispettivi modelli 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)########################################
## 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)
## Gestione del bottone b_avanti #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
def avanti(): #2)-------------------------------(WINDOW CODE)--------------------------------------
# Prima controlla che tutto sia a posto per passare al passo successivo #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
global passo, path_Boot, path_Iso, sel_usb_file, sel_usb_nome # 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()
if passo == 1: # Write window and objects
if path_Boot == "": 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")) msg_warn(_("A file .cpio is required"))
return return
else: else:
passo += 1 step += 1
passo2() step2()
# Step n°2 to n°3
elif passo == 2: elif step == 2:
if path_Iso == "": if path_iso == "":
msg_warn(_("An openmamba's iso is required")) msg_warn(_("An openmamba's iso is required"))
return return
else: else:
passo += 1 step += 1
passo3() step3()
# Step n°3 to n°4
elif passo == 3: elif step == 3:
if sel_usb_file == "": if path_dev == "":
msg_warn(_("You must choose a usb key")) msg_warn(_("You must choose a usb key"))
return return
else: else:
msg = QtGui.QMessageBox.question(None, _("Attention"), _("All data on the key ") + sel_usb_nome + _(" will be lost. \n")+_("Are you sure to continue?"), 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.Yes) QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No)
# Continua solo se l'utente preme il bottone Yes # Go on only if was pressed yes button
if msg == QtGui.QMessageBox.Yes: if msg == QtGui.QMessageBox.Yes:
passo += 1 step += 1
passo4() step4()
else: else:
return return
# Event n°2
def go_back():
## Gestione del bottone b_indietro global step
def indietro(): step -= 1
global passo cloud_hide()
passo -= 1 obj_chang_hide()
# Step n°1 to n°0 -> exit
if passo == 0: if step == 0:
app.exit(1) app.exit(1)
print _("Application terminated by pressing \"cancel\" button") print _("Application terminated by pressing \"cancel\" button")
# 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()
elif passo == 1: # Event n°3
passo1() 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)
elif passo == 2: # Event n°4
passo2() def manage_cloud():
global step
elif passo == 3: if step == 1:
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))
## Visualizza l'aiuto
def gestisci_nuvola():
global passo
# Aiuto in base al passo corrente
if passo == 1:
aiuto = _("This archive is designed to make the usb bootable.") + _(" You can find this file <a style=\"color: green; \"href=\"http://www.openmamba.org/distribution/media/bootusb.html?lang=en\">here</a>") aiuto = _("This archive is designed to make the usb bootable.") + _(" You can find this file <a style=\"color: green; \"href=\"http://www.openmamba.org/distribution/media/bootusb.html?lang=en\">here</a>")
# Cambiata anche la lingua della pagina (lang=en) elif step == 2:
elif passo == 2:
aiuto = _("The file .iso contains the operating system. You can download it from <a style=\"color: green; \"href=\"http://www.openmamba.org/distribution/download.html?lang=en\">here</a>") aiuto = _("The file .iso contains the operating system. You can download it from <a style=\"color: green; \"href=\"http://www.openmamba.org/distribution/download.html?lang=en\">here</a>")
elif passo == 3: elif step == 3:
aiuto = _("Choose an usb key for the installation. <span style=\"color:red;\">All data will be lost</span>") aiuto = _("Choose an usb key for the installation. <span style=\"color:red;\">All data will be lost</span>")
ui.n_testo.setText(QtGui.QApplication.translate("Dialog", aiuto, None, QtGui.QApplication.UnicodeUTF8)) window.l_cloud.setText(aiuto)
ui.n_img.show() # Immagine della nuvola cloud_show()
ui.n_testo.show() # Testo della nuvola
ui.n_chiudi.show()
## Nasconde la nuvola # Event n°5
def chiudi_nuvola(): def close_cloud():
ui.n_img.hide() cloud_hide()
ui.n_testo.hide()
ui.n_chiudi.hide()
## Lista periferiche usb e le aggiuge alla lista (widget) # Event n°6
def lista_usb(): def get_list():
import dbus global a_path_dev, a_dev_model
global usb_file, usb_nome
# Cancella i valori precedenti # Clear array and comboBox
usb_file = [] a_path_dev = []
usb_nome = [] a_dev_model = []
ui.l_usb.clear() window.c_usb.clear()
i = 0 i = 0
# Riceve da dbus le chiavette collegate al pc # Get list form dbus
bus = dbus.SystemBus() bus = dbus.SystemBus()
ud_manager_obj = bus.get_object('org.freedesktop.UDisks', '/org/freedesktop/UDisks') ud_manager_obj = bus.get_object('org.freedesktop.UDisks', '/org/freedesktop/UDisks')
ud_manager = dbus.Interface(ud_manager_obj, 'org.freedesktop.UDisks') ud_manager = dbus.Interface(ud_manager_obj, 'org.freedesktop.UDisks')
for dev in ud_manager.EnumerateDevices(): for dev in ud_manager.EnumerateDevices():
device_obj = bus.get_object('org.freedesktop.UDisks', dev) device_obj = bus.get_object('org.freedesktop.UDisks', dev)
device_props = dbus.Interface(device_obj, dbus.PROPERTIES_IFACE) 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: 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')): if(device_props.Get('org.freedesktop.UDisks.Device', 'DeviceIsRemovable')):
usb_file.append(device_props.Get('org.freedesktop.UDisks.Device', 'DeviceFile')) # Populate the arrays
usb_nome.append(device_props.Get('org.freedesktop.UDisks.Device', 'DriveModel')) a_path_dev.append(device_props.Get('org.freedesktop.UDisks.Device', 'DeviceFile'))
ui.l_usb.addItem(usb_file[i] + " " + usb_nome[i]) 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 i += 1
# Imposta il primo come quello di default # First dev is default
if len(usb_file) != 0: if len(a_path_dev) != 0:
seleziona_usb(0) set_usb(0)
else: else:
print _("No usb available > 1 Gb") print _("No usb available > 1 Gb")
# Event n°7
## Abbreviazione di un warning def set_usb(i):
def msg_warn(testo): global path_dev, dev_model, a_path_dev, a_dev_model
msg = QtGui.QMessageBox.warning(None, _("Attention"), testo) path_dev = a_path_dev[i]
dev_model = a_dev_model[i]
## Aggiorna gli oggetti al cambio del passo #3)#############################(EVENTS HANDLER)#####################################
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): #4)-------------------------------(DBUS CODE)----------------------------------------
global sel_usb_file, usb_file, sel_usb_nome, usb_nome #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
sel_usb_file = usb_file[i] # Class for dbus_start()
sel_usb_nome = usb_nome[i] 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)
@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
@dbus.service.method('org.openmamba.usbinstall')
def Set_description(self, descr):
window.l_descr.setText(descr)
return 0
### Inizio dei vari passi def dbus_start():
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"))
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")
def init_ascolto():
session_bus = dbus.SessionBus() session_bus = dbus.SessionBus()
bus_name = dbus.service.BusName('org.openmamba.usbinstall', bus=session_bus) 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) 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): #5)------------------------------(PROGRAM CODE)--------------------------------------
ui.p_installazione.setProperty("value", int(p)) #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
if p == 100: # Show all cloud objects
installazione_terminata() def cloud_show():
return 0 window.i_cloud.show()
window.b_cloud.show()
window.l_cloud.show()
@dbus.service.method('org.openmamba.usbinstall') # Hide all cloud objects
def Descrizione(self, desc): def cloud_hide():
ui.l_descrizione.setText(QtGui.QApplication.translate("Dialog",desc, None, QtGui.QApplication.UnicodeUTF8)) window.i_cloud.hide()
return 0 window.b_cloud.hide()
window.l_cloud.hide()
@dbus.service.method('org.openmamba.usbinstall') # Warning dialog abbreviation
def Esci(self): 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() mainloop.quit()
app.exit(0) app.exit(0)
print _("Installation process completed")
# Termina lo scipt e dbus insieme alla finestra def end_forced(event):
def closeEvent(form, event): global process_sh, mainloop
installazione_terminata() 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()
# Program start
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
app = QtGui.QApplication([]) app = QtGui.QApplication([])
Dialog = QtGui.QDialog() gettext.install('usbinstall', '/usr/share/locale', unicode=1)
ui = Ui_MainWindow() window = create_window()
ui.setupUi(Dialog)
mainloop = gobject.MainLoop() mainloop = gobject.MainLoop()
def run(): def run():
assegna_eventi() add_events()
passo1() step1()
Dialog.show() # Mostra il dialog precedentemente creato
return app.exec_() return app.exec_()
if __name__ == "__main__": if __name__ == "__main__":
run() run()
#5)##############################(PROGRAM CODE)######################################

View File

@ -28,7 +28,7 @@ inst_new_part()
#3 Formatta la partizione (e la monta) #3 Formatta la partizione (e la monta)
inst_format() inst_format()
{ {
#add_progress 5 29 1 &
sudo mkfs.ext3 ${1}1 -L openmamba_live sudo mkfs.ext3 ${1}1 -L openmamba_live
mkdir -p ~/tmpmamba mkdir -p ~/tmpmamba
sudo mount ${1}1 ~/tmpmamba sudo mount ${1}1 ~/tmpmamba
@ -70,28 +70,31 @@ inst_copy_iso()
#7 Smonta la chiavetta #7 Smonta la chiavetta
inst_dir_umount() inst_dir_umount()
{ {
# So it attend up to umount return without errors sleep 5
sudo umount ${1}1
while [ 1 ] ; do
sudo umount ${1}
if [ $? != 1 ]; then
break
fi
done
echo "Done" 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 == % # Aggiorna la progressbar $1 == %
pbar() 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() descrizione()
{ {
dbus-send --print-reply --session --dest=org.openmamba.usbinstall /org/openmamba/usbinstall org.openmamba.usbinstall.Set_description "string:$1"
dbus-send --print-reply --session --dest=org.openmamba.usbinstall /org/openmamba/usbinstall org.openmamba.usbinstall.Descrizione "string:$1"
} }
@ -104,7 +107,7 @@ if [ $1 == "start" ]; then
inst_new_part $2 inst_new_part $2
pbar 5 pbar 5
inst_format $2 inst_format $2
pbar 20 pbar 30
descrizione "Estrazione del file di boot in corso..." descrizione "Estrazione del file di boot in corso..."
inst_extr_boot $3 inst_extr_boot $3
@ -125,5 +128,4 @@ if [ $1 == "start" ]; then
else else
echo $1 "Parametri non validi" echo $1 "Parametri non validi"
fi fi