2011-10-23 13:28:28 +02:00
# -*- coding: utf-8 -*-
#!/usr/bin/env python
from gui import * # Importa la parte grafica
2011-11-07 17:33:46 +01:00
import gettext
2011-10-23 16:38:52 +02:00
from subprocess import Popen
2011-10-23 13:28:28 +02:00
# La parte di dbus
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
2011-11-07 17:33:46 +01:00
gettext . install ( ' usbinstall ' , ' /usr/share/locale ' , unicode = 1 )
2011-10-23 13:28:28 +02:00
# Variabili globali
passo = 1
2011-10-23 16:38:52 +02:00
p = " " # Processo del file .sh
2011-10-23 13:28:28 +02:00
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 )
## 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 == " " :
2011-11-07 17:33:46 +01:00
msg_warn ( _ ( " A file .cpio is required " ) )
2011-10-23 13:28:28 +02:00
return
else :
passo + = 1
passo2 ( )
elif passo == 2 :
if path_Iso == " " :
2011-11-07 17:33:46 +01:00
msg_warn ( _ ( " An openmamba ' s iso is required " ) )
2011-10-23 13:28:28 +02:00
return
else :
passo + = 1
passo3 ( )
elif passo == 3 :
if sel_usb_file == " " :
2011-11-07 17:33:46 +01:00
msg_warn ( _ ( " You must choose a usb key " ) )
2011-10-23 13:28:28 +02:00
return
else :
2011-11-07 17:33:46 +01:00
msg = QtGui . QMessageBox . question ( None , _ ( " Attention " ) , _ ( " All data on the key " ) + sel_usb_nome + _ ( " will be lost. \n " ) + _ ( " Are you sure to continue? " ) ,
2011-10-23 13:28:28 +02:00
QtGui . QMessageBox . Yes | QtGui . QMessageBox . No , QtGui . QMessageBox . Yes )
# Continua solo se l'utente preme il bottone Yes
if msg == QtGui . QMessageBox . Yes :
passo + = 1
passo4 ( )
else :
return
## Gestione del bottone b_indietro
def indietro ( ) :
global passo
passo - = 1
if passo == 0 :
app . exit ( 1 )
2011-11-07 17:33:46 +01:00
print _ ( " Application terminated by pressing \" cancel \" button " )
2011-10-23 13:28:28 +02:00
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 " )
2011-11-07 17:33:46 +01:00
nfileName = QtGui . QFileDialog . getOpenFileName ( None , _ ( " Choose the boot file " ) , " ~ " , " File .cpio.gz (*.cpio.gz) " , fileType )
2011-10-23 13:28:28 +02:00
path_Boot = nfileName
ui . t_file . setText ( QtGui . QApplication . translate ( " Dialog " , nfileName , None , QtGui . QApplication . UnicodeUTF8 ) )
elif ext == " iso " :
fileType = QtCore . QString ( " iso *.iso " )
2011-11-07 17:33:46 +01:00
nfileName = QtGui . QFileDialog . getOpenFileName ( None , _ ( " Choose the iso file " ) , " ~ " , " File .iso (*.iso) " , fileType ) #26/10 path_Boot -> "~"
2011-10-23 13:28:28 +02:00
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 :
2011-11-07 17:33:46 +01:00
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)
2011-10-23 13:28:28 +02:00
elif passo == 2 :
2011-11-07 17:33:46 +01:00
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> " )
2011-10-23 13:28:28 +02:00
elif passo == 3 :
2011-11-07 17:33:46 +01:00
aiuto = _ ( " Choose an usb key for the installation. <span style= \" color:red; \" >All data will be lost</span> " )
2011-10-23 13:28:28 +02:00
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 ( )
## Nasconde la nuvola
def chiudi_nuvola ( ) :
ui . n_img . hide ( )
ui . n_testo . hide ( )
ui . n_chiudi . hide ( )
## Lista periferiche usb e le aggiuge alla lista (widget)
def lista_usb ( ) :
import dbus
global usb_file , usb_nome
# Cancella i valori precedenti
usb_file = [ ]
usb_nome = [ ]
ui . l_usb . clear ( )
i = 0
# Riceve da dbus le chiavette collegate al pc
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 ( device_props . Get ( ' org.freedesktop.UDisks.Device ' , ' PartitionSize ' ) ) > 1073741823 :
# Se e' un device rimuovibile (== chiavetta usb)
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 ] )
i + = 1
# Imposta il primo come quello di default
if len ( usb_file ) != 0 :
seleziona_usb ( 0 )
else :
2011-11-07 17:33:46 +01:00
print _ ( " No usb available > 1 Gb " )
2011-10-23 13:28:28 +02:00
## Abbreviazione di un warning
def msg_warn ( testo ) :
2011-11-07 17:33:46 +01:00
msg = QtGui . QMessageBox . warning ( None , _ ( " Attention " ) , testo )
2011-10-23 13:28:28 +02:00
## 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 = " "
2011-11-07 17:33:46 +01:00
ui . b_indietro . setText ( QtGui . QApplication . translate ( " Dialog " , _ ( " Cancel " ) , None , QtGui . QApplication . UnicodeUTF8 ) )
2011-10-23 13:28:28 +02:00
# Visualizzo gli oggetti del passo 1
visualizza_scegli_file ( )
2011-10-23 13:31:50 +02:00
# Chiudi la nuovola dell'help al cambio di passo
chiudi_nuvola ( )
2011-10-23 13:28:28 +02:00
elif passo == 2 :
ext = " iso "
path_Iso = " "
2011-11-07 17:33:46 +01:00
ui . b_indietro . setText ( QtGui . QApplication . translate ( " Dialog " , _ ( " Go back " ) , None , QtGui . QApplication . UnicodeUTF8 ) )
2011-10-23 13:28:28 +02:00
visualizza_scegli_file ( )
2011-10-23 13:31:50 +02:00
# Chiudi la nuovola dell'help al cambio di passo
2011-10-23 16:38:52 +02:00
chiudi_nuvola ( )
2011-10-23 13:28:28 +02:00
elif passo == 3 :
visualizza_lista_usb ( )
lista_usb ( )
2011-10-23 13:31:50 +02:00
# Chiudi la nuovola dell'help al cambio di passo
2011-10-23 16:38:52 +02:00
chiudi_nuvola ( )
elif passo == 4 :
chiudi_nuvola ( )
2011-10-23 13:28:28 +02:00
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 ]
### Inizio dei vari passi
def passo1 ( ) :
2011-11-07 17:33:46 +01:00
aggiorna_oggetti ( " img/back1.png " , _ ( " Step 1/4 - choice the boot file " ) , _ ( " Choose the .cpio file " ) )
2011-10-23 13:28:28 +02:00
def passo2 ( ) :
2011-11-07 17:33:46 +01:00
aggiorna_oggetti ( " img/back2.png " , _ ( " Step 2/4 - choice the iso file " ) , _ ( " Choose the openmamba .iso file " ) )
2011-10-23 13:28:28 +02:00
def passo3 ( ) :
2011-11-07 17:33:46 +01:00
aggiorna_oggetti ( " img/back3.png " , _ ( " Step 3/4 - choice of usb key " ) , _ ( " Choose the usb key " ) )
2011-10-23 13:28:28 +02:00
def passo4 ( ) :
2011-10-23 16:38:52 +02:00
global p
2011-11-07 17:33:46 +01:00
aggiorna_oggetti ( " img/back4.png " , _ ( " Step 4/4 - installation of openmamba to usb " ) , _ ( " Installation in progress... " ) )
2011-10-23 13:28:28 +02:00
# 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 ] )
2011-11-07 17:33:46 +01:00
print _ ( " Installation process started " )
2011-10-23 13:28:28 +02:00
def init_ascolto ( ) :
session_bus = dbus . SessionBus ( )
bus_name = dbus . service . BusName ( ' org.openmamba.usbinstall ' , bus = session_bus )
dbus_loop = setta_dbus ( bus_name )
bus = dbus . SessionBus ( mainloop = dbus_loop )
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
@dbus.service.method ( ' org.openmamba.usbinstall ' )
def Esci ( self ) :
mainloop . quit ( )
app . exit ( 0 )
2011-10-23 16:38:52 +02:00
# Termina lo scipt e dbus insieme alla finestra
def closeEvent ( form , event ) :
installazione_terminata ( )
2011-10-23 13:28:28 +02:00
def installazione_terminata ( ) :
2011-10-23 16:38:52 +02:00
global p
2011-11-07 17:33:46 +01:00
msg = QtGui . QMessageBox . information ( None , _ ( " Information " ) , _ ( " Installation process completed " ) )
2011-10-23 16:38:52 +02:00
p . terminate ( )
mainloop . quit ( )
2011-10-23 13:28:28 +02:00
app . exit ( 0 )
# Inizializza la parte grafica
app = QtGui . QApplication ( [ ] )
Dialog = QtGui . QDialog ( )
ui = Ui_MainWindow ( )
ui . setupUi ( Dialog )
mainloop = gobject . MainLoop ( )
def run ( ) :
assegna_eventi ( )
passo1 ( )
2011-11-07 17:33:46 +01:00
ui . b_avanti . setText ( QtGui . QApplication . translate ( " Dialog " , _ ( " Go on " ) , None , QtGui . QApplication . UnicodeUTF8 ) )
2011-10-23 16:38:52 +02:00
Dialog . show ( ) # Mostra il dialog precedentemente creato
2011-10-23 13:28:28 +02:00
return app . exec_ ( )
if __name__ == " __main__ " :
run ( )