Manage some errors and bugfixes
This commit is contained in:
parent
97ee7491ce
commit
250d669a02
@ -8,6 +8,7 @@
|
||||
|
||||
from PyQt4 import QtGui, QtCore
|
||||
from subprocess import Popen
|
||||
import signal
|
||||
import gettext # To translate
|
||||
import gobject
|
||||
import dbus
|
||||
@ -16,7 +17,6 @@ from dbus.mainloop.glib import DBusGMainLoop
|
||||
if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
|
||||
import dbus.glib
|
||||
|
||||
|
||||
#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
|
||||
#1)-------------------------------(VARIABILI)----------------------------------------
|
||||
#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
|
||||
@ -125,7 +125,13 @@ class create_window(QtGui.QDialog):
|
||||
|
||||
# Intercept close event
|
||||
def closeEvent(self, event):
|
||||
end_forced(event)
|
||||
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:
|
||||
end_forced()
|
||||
else:
|
||||
event.ignore()
|
||||
|
||||
#2)###############################(WINDOW CODE)######################################
|
||||
|
||||
|
||||
@ -135,6 +141,9 @@ class create_window(QtGui.QDialog):
|
||||
#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
|
||||
#3)-----------------------------(EVENTS HANDLER)-------------------------------------
|
||||
#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
|
||||
# Add SIGNINT event
|
||||
#signal.signal(signal.SIGINT, zz)
|
||||
|
||||
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
|
||||
@ -284,8 +293,15 @@ class set_dbus(dbus.service.Object):
|
||||
@dbus.service.method('org.openmamba.usbinstall')
|
||||
def Set_progressBar(self, p):
|
||||
window.p_install.setProperty("value", int(p))
|
||||
if p == 100:
|
||||
return 0
|
||||
|
||||
@dbus.service.method('org.openmamba.usbinstall')
|
||||
def Exit(self, errMsg):
|
||||
if errMsg == "":
|
||||
end_with_success()
|
||||
else:
|
||||
msg = QtGui.QMessageBox.critical(window, _("Script Error"), _(errMsg))
|
||||
end_forced()
|
||||
return 0
|
||||
|
||||
@dbus.service.method('org.openmamba.usbinstall')
|
||||
@ -392,25 +408,19 @@ def obj_chang_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")
|
||||
|
||||
def end_forced(event):
|
||||
def end_forced():
|
||||
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()
|
||||
mainloop.quit()
|
||||
print _("Installation aborted")
|
||||
app.exit(1)
|
||||
|
||||
|
||||
# Program start
|
||||
app = QtGui.QApplication([])
|
||||
app = QtGui.QApplication(['usbinstall'])
|
||||
gettext.install('usbinstall', '/usr/share/locale', unicode=1)
|
||||
window = create_window()
|
||||
mainloop = gobject.MainLoop()
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
trap "echo 'LOLOLOLOLOLO'" SIGHUP INT QUIT ABRT KILL TERM
|
||||
#usbinstall.sh
|
||||
# Arg 1: usb device for installation
|
||||
# Arg 2: boot file
|
||||
@ -68,7 +68,11 @@ function dbus_properties_get_bool() {
|
||||
set_pbar()
|
||||
{
|
||||
if [ "$DBUS_USBINSTALL" == "1" ]; then
|
||||
dbus-send --system --print-reply --dest=org.openmamba.usbinstall /org/openmamba/usbinstall org.openmamba.usbinstall.Set_progressBar int32:$1 >/dev/null
|
||||
dbus-send --system --print-reply --dest=org.openmamba.usbinstall /org/openmamba/usbinstall org.openmamba.usbinstall.Set_progressBar int32:$1 &>/dev/null
|
||||
if [ "$?" != "0" ]; then
|
||||
[ "$CPPID" ] && kill -9 $CPPID
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
@ -77,9 +81,27 @@ set_pbar()
|
||||
set_status()
|
||||
{
|
||||
if [ "$DBUS_USBINSTALL" == "1" ]; then
|
||||
dbus-send --system --print-reply --dest=org.openmamba.usbinstall /org/openmamba/usbinstall org.openmamba.usbinstall.Set_description "string:$1" >/dev/null
|
||||
dbus-send --system --print-reply --dest=org.openmamba.usbinstall /org/openmamba/usbinstall org.openmamba.usbinstall.Set_description "string:$1" &>/dev/null
|
||||
if [ "$?" != "0" ]; then
|
||||
[ "$CPPID" ] && kill -9 $CPPID
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Terminate the frontend (only if $DBUS_USBINSTALL = 1)
|
||||
exit_frontend()
|
||||
{
|
||||
|
||||
if [ "$DBUS_USBINSTALL" == "1" ]; then
|
||||
dbus-send --system --print-reply --dest=org.openmamba.usbinstall /org/openmamba/usbinstall org.openmamba.usbinstall.Exit "string:$1" &>/dev/null
|
||||
if [ "$?" != "0" ]; then
|
||||
[ "$CPPID" ] && kill -9 $CPPID
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
####################################(DBUS)###########################################
|
||||
|
||||
|
||||
@ -90,6 +112,7 @@ function errorAndExit()
|
||||
if [ -n "$2" ]; then
|
||||
usage
|
||||
fi
|
||||
exit_frontend "$1" # Termina il frontend con codice di errore 1
|
||||
exit 1
|
||||
}
|
||||
|
||||
@ -107,6 +130,16 @@ function usage()
|
||||
#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
|
||||
#--------------------------------(INITIAL-CHECK)-------------------------------------
|
||||
#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
|
||||
# Confirm
|
||||
if [ "$4" = "-y" ]; then
|
||||
CONFIRM=0
|
||||
elif [ "$4" = "-d" ]; then
|
||||
CONFIRM=0
|
||||
DBUS_USBINSTALL=1 # First set this
|
||||
else
|
||||
CONFIRM=1
|
||||
fi
|
||||
|
||||
# Help
|
||||
if [ "$1" = "-h" -o "$1" = "--help" ]; then
|
||||
usage
|
||||
@ -169,16 +202,6 @@ fi
|
||||
if [ "${3##*.}" != "iso" ]; then
|
||||
errorAndExit "Error(Arg 3): you must chose a iso file" 1
|
||||
fi
|
||||
|
||||
# Confirm
|
||||
if [ "$4" = "-y" ]; then
|
||||
CONFIRM=0
|
||||
elif [ "$4" = "-d" ]; then
|
||||
CONFIRM=0
|
||||
DBUS_USBINSTALL=1
|
||||
else
|
||||
CONFIRM=1
|
||||
fi
|
||||
#################################(INITIAL-CHECK)#####################################
|
||||
|
||||
|
||||
@ -188,6 +211,7 @@ fi
|
||||
#--------------------------------(INSTALLATION)--------------------------------------
|
||||
#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
|
||||
export LOGFILE=/var/log/usbinstall.log
|
||||
trap "[ \"$CPPID\" ] && kill -9 $CPPID" HUP INT QUIT ABRT KILL TERM
|
||||
set_status "Smonto la chiavetta"
|
||||
|
||||
DEVICEISMOUNTED=`dbus_properties_get_bool org.freedesktop.UDisks /org/freedesktop/UDisks/devices/${SELECT_USB/*\/}1 \
|
||||
@ -223,11 +247,12 @@ set_pbar 5
|
||||
|
||||
set_status "Formattazione della chiavetta in corso..."
|
||||
echo "Formatting..."
|
||||
sudo mkfs.ext3 ${SELECT_USB}1 -L openmamba_live &>>$LOGFILE
|
||||
#sudo mkfs.ext3 ${SELECT_USB}1 -L openmamba_live &>>$LOGFILE
|
||||
if [ "$?" != "0" ]; then
|
||||
errorAndExit "Error: \"mkfs.ext3\" exit with error (see $LOGFILE)"
|
||||
fi
|
||||
|
||||
sleep 1
|
||||
LANG=C udisks --mount ${SELECT_USB}1 &>>$LOGFILE
|
||||
if [ "$?" != "0" ]; then
|
||||
errorAndExit "Error: \"udisks --mount\" exit with error (see $LOGFILE)"
|
||||
@ -248,9 +273,11 @@ echo "Extracting bootusb archive..."
|
||||
pushd $MOUNTDIR >/dev/null
|
||||
sudo chmod 777 ./
|
||||
gunzip -c $SELECT_BOOT | cpio -i
|
||||
if [ ! -d "./boot" ]; then
|
||||
errorAndExit "Error: Invalid bootusb archive"
|
||||
fi
|
||||
set_pbar 38
|
||||
|
||||
|
||||
set_status "Scrittura del bootloader in corso..."
|
||||
sudo extlinux --install boot
|
||||
sudo install-mbr -e 1 $SELECT_USB
|
||||
@ -262,26 +289,28 @@ echo "Copying ISO..."
|
||||
# Copy code
|
||||
ORIG_SIZE=`stat -c %s $SELECT_ISO`
|
||||
cp $SELECT_ISO ./ &
|
||||
export CPPID=$!
|
||||
DEST_SIZE=0
|
||||
DEST_FILE=./"`basename $SELECT_ISO`"
|
||||
while [ $ORIG_SIZE -gt $DEST_SIZE ]; do
|
||||
CPSTATE=`ps $CPPID | grep "cp"`
|
||||
while [ "$CPSTATE" != "" ]; do
|
||||
if [ -e $DEST_FILE ]; then
|
||||
DEST_SIZE=$(stat -c %s $DEST_FILE)
|
||||
percentuale=$((45 + ( 50 * $DEST_SIZE ) / $ORIG_SIZE ))
|
||||
set_pbar $percentuale
|
||||
fi
|
||||
sleep 2
|
||||
CPSTATE=`ps $CPPID | grep "cp"`
|
||||
done
|
||||
ln -fs `basename $SELECT_ISO` ./openmamba-live.iso
|
||||
popd >/dev/null
|
||||
set_pbar 98
|
||||
|
||||
|
||||
set_status "Smonto la chiavetta"
|
||||
LANG=C udisks --unmount ${SELECT_USB}1 | grep failed && {
|
||||
echo "Error: fail to umount the usb key (${SELECT_USB}1)"
|
||||
exit 2
|
||||
errorAndExit "Error: fail to umount the usb key (${SELECT_USB}1)"
|
||||
}
|
||||
set_pbar 100
|
||||
exit_frontend ""
|
||||
echo "Done."
|
||||
#################################(INSTALLATION)######################################
|
||||
|
Loading…
Reference in New Issue
Block a user