[PATCH] GUI for live USB keys in Windows
Kushal Das
kushaldas at gmail.com
Mon Feb 4 15:00:24 UTC 2008
Hi,
This patch will create a small GUI in PyQt for the tool
diff --git a/livecd-iso-to-usb.py b/livecd-iso-to-usb.py
index 8a06090..4e940f0 100644
--- a/livecd-iso-to-usb.py
+++ b/livecd-iso-to-usb.py
@@ -1,130 +1,174 @@
-# This tool installs a Fedora Live ISO (F7+) on to a USB stick, from Windows.
-# For information regarding the installation of Fedora on USB drives, see
-# the wiki: http://fedoraproject.org/wiki/FedoraLiveCD/USBHowTo
-#
-# Copyright 2008 Red Hat, Inc.
-# Authors: Luke Macken <lmacken at redhat.com>
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; version 2 of the License.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Library General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-import win32file
-import win32api
-import shutil
-import os
-import re
-
-class LiveUSBCreator:
-
- iso = None # Fedora-8-Live-i686.iso
- drive = None # F:\
- label = "FEDORA" # if one doesn't already exist
-
- def detectRemovableDrives(self):
- """
- Detect all removable drives. If we find more than one, ask the user
- which they would like to use.
- """
- drives = []
- for drive in [l.upper() + ':' for l in 'abcdefghijklmnopqrstuvwxyz']:
- if win32file.GetDriveType(drive) == win32file.DRIVE_REMOVABLE:
- drives.append(drive)
- if not len(drives):
- raise Exception("Sorry, I couldn't find any devices")
- elif len(drives) > 1:
- drives[0] = raw_input("Which drive do you want to put Fedora
on: "
- "%s ? " % drives)
- drives[0] = drives[0].upper()
- if not drives[0].endswith(":"):
- drives[0] += ":"
- self.drive = drives[0] + os.sep
-
- def verifyFilesystem(self):
- """
- Verify our filesystem type, and set the volume label if necessary
- """
- try:
- vol = win32api.GetVolumeInformation(self.drive[:-1])
- except:
- raise Exception("Make sure your USB key is plugged in and
formatted"
- " using the FAT filesystem")
- if vol[-1] not in ('FAT32', 'FAT'):
- raise Exception("Unsupported filesystem: %s\nPlease backup and "
- "format your USB key with the FAT filesystem." %
- vol[-1])
- if vol[0] == '':
- win32file.SetVolumeLabel(self.drive[:-1], self.label)
- else:
- self.label = vol[0]
-
- def findISO(self):
- """
- Look in the current directory for our ISO image.
- """
- isos = [item for item in os.listdir(".") if item.endswith(".iso")]
- if not len(isos):
- raise Exception("Cannot find ISO file. Please drag it into
this "
- "directory. If you haven't downloaded Fedora
yet, "
- "please visit:
http://fedoraproject.org/get-fedora")
- if len(isos) > 1:
- print "I found the following ISOs:"
- for i, iso in enumerate(isos):
- print " [ %d ] %s" % (i + 1, iso)
- choice = raw_input("Which image do you want use: %s ? " %
- range(1, i + 2))
- isos[0] = isos[int(choice) - 1]
- self.iso = isos[0]
-
- def extractISO(self):
- """ Extract our ISO with 7-zip directly to the USB key """
- if os.path.isdir(os.path.join(self.drive, "LiveOS")):
- print "Your device already contains a LiveOS!"
- os.system("7-Zip%s7z.exe x %s -x![BOOT] -o%s" % (os.sep, self.iso,
- self.drive))
- if not os.path.isdir(os.path.join(self.drive, "LiveOS")):
- raise Exception("ISO extraction failed? Cannot find LiveOS")
-
- def updateConfigs(self):
- """ Generate our syslinux.cfg """
- isolinux =
file(os.path.join(self.drive,"isolinux","isolinux.cfg"),'r')
- syslinux =
file(os.path.join(self.drive,"isolinux","syslinux.cfg"),'w')
- for line in isolinux.readlines():
- if "CDLABEL" in line:
- line = re.sub("CDLABEL=[^ ]*", "LABEL=" + self.label, line)
- line = re.sub("rootfstype=[^ ]*", "rootfstype=vfat", line)
- syslinux.write(line)
- isolinux.close()
- syslinux.close()
-
- def installBootloader(self):
- print "Installing bootloader"
- shutil.move(os.path.join(self.drive, "isolinux"),
- os.path.join(self.drive, "syslinux"))
- os.unlink(os.path.join(self.drive, "syslinux", "isolinux.cfg"))
- os.system("syslinux -d %s %s" %
(os.path.join(self.drive, "syslinux"),
- self.drive[:-1]))
-
-if __name__ == '__main__':
- try:
- live = LiveUSBCreator()
- live.detectRemovableDrives()
- live.verifyFilesystem()
- live.findISO()
- live.extractISO()
- live.updateConfigs()
- live.installBootloader()
- except Exception, e:
- print "Oops! Something went wrong:"
- print str(e)
-
- x = raw_input("\nDone!")
+# This tool installs a Fedora Live ISO (F7+) on to a USB stick, from Windows.
+# For information regarding the installation of Fedora on USB drives, see
+# the wiki: http://fedoraproject.org/wiki/FedoraLiveCD/USBHowTo
+#
+# Copyright 2008 Red Hat, Inc.
+# Authors: Luke Macken <lmacken at redhat.com>
+# Copyright 2008 Kushal Das <kushal at fedoraproject.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Library General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+from luDialog import Ui_luDialog
+from PyQt4 import QtCore, QtGui
+import sys
+import win32file
+import win32api
+import shutil
+import os
+import re
+
+class LiveUSBCreator:
+
+ iso = None # Fedora-8-Live-i686.iso
+ drive = None # F:\
+ label = "FEDORA" # if one doesn't already exist
+
+ def detectRemovableDrives(self):
+ """
+ Detect all removable drives. If we find more than one, ask the user
+ which they would like to use.
+ """
+ drives = []
+ for drive in [l.upper() + ':' for l in 'abcdefghijklmnopqrstuvwxyz']:
+ if win32file.GetDriveType(drive) == win32file.DRIVE_REMOVABLE:
+ drives.append(drive)
+ if not len(drives):
+ raise Exception("Sorry, I couldn't find any devices")
+ elif len(drives) > 1:
+ drives[0] = raw_input("Which drive do you want to put Fedora
on: "
+ "%s ? " % drives)
+ drives[0] = drives[0].upper()
+ if not drives[0].endswith(":"):
+ drives[0] += ":"
+ self.drive = drives[0] + os.sep
+
+ def verifyFilesystem(self):
+ """
+ Verify our filesystem type, and set the volume label if necessary
+ """
+ try:
+ vol = win32api.GetVolumeInformation(self.drive[:-1])
+ except:
+ raise Exception("Make sure your USB key is plugged in and
formatted"
+ " using the FAT filesystem" + self.drive)
+ if vol[-1] not in ('FAT32', 'FAT'):
+ raise Exception("Unsupported filesystem: %s\nPlease backup and "
+ "format your USB key with the FAT filesystem." %
+ vol[-1])
+ if vol[0] == '':
+ win32file.SetVolumeLabel(self.drive[:-1], self.label)
+ else:
+ self.label = vol[0]
+
+ def findISO(self):
+ """
+ Look in the current directory for our ISO image.
+ """
+ isos = [item for item in os.listdir(".") if item.endswith(".iso")]
+ if not len(isos):
+ raise Exception("Cannot find ISO file. Please drag it into
this "
+ "directory. If you haven't downloaded Fedora
yet, "
+ "please visit:
http://fedoraproject.org/get-fedora")
+ if len(isos) > 1:
+ print "I found the following ISOs:"
+ for i, iso in enumerate(isos):
+ print " [ %d ] %s" % (i + 1, iso)
+ choice = raw_input("Which image do you want use: %s ? " %
+ range(1, i + 2))
+ isos[0] = isos[int(choice) - 1]
+ self.iso = isos[0]
+
+ def extractISO(self):
+ """ Extract our ISO with 7-zip directly to the USB key """
+ if os.path.isdir(os.path.join(self.drive, "LiveOS")):
+ print "Your device already contains a LiveOS!"
+ os.system("7-Zip%s7z.exe x %s -x![BOOT] -o%s" % (os.sep, self.iso,
+ self.drive))
+ if not os.path.isdir(os.path.join(self.drive, "LiveOS")):
+ raise Exception("ISO extraction failed? Cannot find LiveOS"
+self.iso)
+
+ def updateConfigs(self):
+ """ Generate our syslinux.cfg """
+ isolinux =
file(os.path.join(self.drive,"isolinux","isolinux.cfg"),'r')
+ syslinux =
file(os.path.join(self.drive,"isolinux","syslinux.cfg"),'w')
+ for line in isolinux.readlines():
+ if "CDLABEL" in line:
+ line = re.sub("CDLABEL=[^ ]*", "LABEL=" + self.label, line)
+ line = re.sub("rootfstype=[^ ]*", "rootfstype=vfat", line)
+ syslinux.write(line)
+ isolinux.close()
+ syslinux.close()
+
+ def installBootloader(self):
+ print "Installing bootloader"
+ shutil.move(os.path.join(self.drive, "isolinux"),
+ os.path.join(self.drive, "syslinux"))
+ os.unlink(os.path.join(self.drive, "syslinux", "isolinux.cfg"))
+ os.system("syslinux -d %s %s" %
(os.path.join(self.drive, "syslinux"),
+ self.drive[:-1]))
+
+
+
+
+class luApp(QtGui.QApplication):
+ """Main application class"""
+ def __init__(self,args=None):
+ QtGui.QApplication.__init__(self,args)
+ self.mywindow = lsUI()
+ self.mywindow.show()
+ self.exec_()
+
+
+class lsUI(Ui_luDialog, QtGui.QDialog):
+ """My class for the UI"""
+ def __init__(self):
+ QtGui.QDialog.__init__(self)
+ self.setupUi(self)
+ for drive in [l.upper() + ':' for l in 'abcdefghijklmnopqrstuvwxyz']:
+ if win32file.GetDriveType(drive) == win32file.DRIVE_REMOVABLE:
+ self.driveBox.addItem(drive + os.sep)
+ if self.driveBox.count < 0:
+ raise Exception("Sorry, I couldn't find any devices")
+ try:
+ self.live = LiveUSBCreator()
+ except Exception , e:
+ self.textEdit.setPlainText(str(e))
+ self.connectslots()
+
+ def connectslots(self):
+ self.connect(self.isoBttn,QtCore.SIGNAL("clicked()"),self.selectfile)
+ self.connect(self.burnBttn,QtCore.SIGNAL("clicked()"),self.burn)
+
+ def burn(self):
+ self.live.drive = str(self.driveBox.currentText())
+ if self.live.iso == None:
+ self.textEdit.setPlainText("Please select an ISO first")
+ return
+ try:
+ self.live.verifyFilesystem()
+ self.live.extractISO()
+ self.live.updateConfigs()
+ self.live.installBootloader()
+ self.textEdit.setPlainText("Done :)")
+ except Exception, e:
+ self.textEdit.setPlainText(str(e))
+
+ def selectfile(self):
+ isofile = QtGui.QFileDialog.getOpenFileName(self, "Select Live
ISO", ".", "ISO (*.iso)" )
+ self.live.iso = str(isofile)
+
+
+
+if __name__ == '__main__':
+ luApp = luApp(sys.argv)
diff --git a/luDialog.py b/luDialog.py
new file mode 100755
index 0000000..96a2e8a
--- /dev/null
+++ b/luDialog.py
@@ -0,0 +1,68 @@
+# -*- coding: utf-8 -*-
+
+# Form implementation generated from reading ui file 'luDialog.ui'
+#
+# Created: Mon Feb 04 15:41:02 2008
+# by: PyQt4 UI code generator 4.3.3
+#
+# WARNING! All changes made in this file will be lost!
+
+from PyQt4 import QtCore, QtGui
+
+class Ui_luDialog(object):
+ def setupUi(self, luDialog):
+ luDialog.setObjectName("luDialog")
+
luDialog.resize(QtCore.QSize(QtCore.QRect(0,0,384,359).size()).expandedTo(luDialog.minimumSizeHint()))
+
+ self.gridlayout = QtGui.QGridLayout(luDialog)
+ self.gridlayout.setObjectName("gridlayout")
+
+ self.hboxlayout = QtGui.QHBoxLayout()
+ self.hboxlayout.setObjectName("hboxlayout")
+
+ self.isoBttn = QtGui.QPushButton(luDialog)
+ self.isoBttn.setObjectName("isoBttn")
+ self.hboxlayout.addWidget(self.isoBttn)
+
+ self.label = QtGui.QLabel(luDialog)
+ self.label.setObjectName("label")
+ self.hboxlayout.addWidget(self.label)
+
+ self.driveBox = QtGui.QComboBox(luDialog)
+ self.driveBox.setObjectName("driveBox")
+ self.hboxlayout.addWidget(self.driveBox)
+ self.gridlayout.addLayout(self.hboxlayout,0,0,1,1)
+
+ spacerItem =
QtGui.QSpacerItem(20,40,QtGui.QSizePolicy.Minimum,QtGui.QSizePolicy.Expanding)
+ self.gridlayout.addItem(spacerItem,1,0,1,1)
+
+ self.hboxlayout1 = QtGui.QHBoxLayout()
+ self.hboxlayout1.setObjectName("hboxlayout1")
+
+ spacerItem1 =
QtGui.QSpacerItem(40,20,QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Minimum)
+ self.hboxlayout1.addItem(spacerItem1)
+
+ self.burnBttn = QtGui.QPushButton(luDialog)
+ self.burnBttn.setObjectName("burnBttn")
+ self.hboxlayout1.addWidget(self.burnBttn)
+
+ spacerItem2 =
QtGui.QSpacerItem(40,20,QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Minimum)
+ self.hboxlayout1.addItem(spacerItem2)
+ self.gridlayout.addLayout(self.hboxlayout1,2,0,1,1)
+
+ spacerItem3 =
QtGui.QSpacerItem(20,16,QtGui.QSizePolicy.Minimum,QtGui.QSizePolicy.Expanding)
+ self.gridlayout.addItem(spacerItem3,3,0,1,1)
+
+ self.textEdit = QtGui.QTextEdit(luDialog)
+ self.textEdit.setObjectName("textEdit")
+ self.gridlayout.addWidget(self.textEdit,4,0,1,1)
+
+ self.retranslateUi(luDialog)
+ QtCore.QMetaObject.connectSlotsByName(luDialog)
+
+ def retranslateUi(self, luDialog):
+
luDialog.setWindowTitle(QtGui.QApplication.translate("luDialog", "Fedora Live
ISO to USB ", None, QtGui.QApplication.UnicodeUTF8))
+ self.isoBttn.setText(QtGui.QApplication.translate("luDialog", "Select
The ISO", None, QtGui.QApplication.UnicodeUTF8))
+ self.label.setText(QtGui.QApplication.translate("luDialog", "Select
Drive to Install", None, QtGui.QApplication.UnicodeUTF8))
+
self.burnBttn.setText(QtGui.QApplication.translate("luDialog", "BURN", None,
QtGui.QApplication.UnicodeUTF8))
+
diff --git a/setup.py b/setup.py
index a4f0b36..d4a734f 100644
--- a/setup.py
+++ b/setup.py
@@ -1,16 +1,18 @@
-from distutils.core import setup
-import py2exe
-
-setup(
- console = [
- {
- "script" : "livecd-iso-to-usb.py",
- "icon_resources" : [(0, "fedora.ico")],
- }
- ],
- data_files = [
- "syslinux.exe",
- ("7-Zip", ["7-Zip/7z.exe", "7-Zip/7z.dll", "7-Zip/7zCon.sfx",
- "7-Zip/License.txt", "7-Zip/copying.txt"]),
- ],
-)
+from distutils.core import setup
+import py2exe
+
+setup(
+ windows = [
+ {
+ "script" : "livecd-iso-to-usb.py",
+ "icon_resources" : [(0, "fedora.ico")],
+
+ }
+ ],
+ options={"py2exe" : {"includes" : ["sip", "PyQt4._qt"]}},
+ data_files = [
+ "syslinux.exe",
+ ("7-Zip", ["7-Zip/7z.exe", "7-Zip/7z.dll", "7-Zip/7zCon.sfx",
+ "7-Zip/License.txt", "7-Zip/copying.txt"]),
+ ],
+)
Kushal
--
Fedora Ambassador, India
http://kushaldas.in
http://dgplug.org (Linux User Group of Durgapur)
More information about the devel
mailing list