def __init__(self, src, dst): self.utils = Utils() self.progressbar = ProgressBar(src) self.iso_dir = tempfile.mkdtemp(suffix="_isoPuding") if not dst: self.partutils = PartitionUtils() if not self.partutils.detect_removable_drives(): self.utils.cprint(_("USB device not found."), "red") sys.exit() else: device, dst = self.__ask_destination() # FIX ME: You should not use it. if not dst: dst = tempfile.mkdtemp(suffix="_usbPuding") cmd = "mount -t vfat %s %s" % (device, dst) self.utils.cprint(_("Mounting USB device..."), "green") run_command(cmd) self.utils.cprint(_("Mounting image..."), "green") cmd = "fuseiso %s %s" % (src, self.iso_dir) if run_command(cmd): self.utils.cprint(_("Could not mounted image."), "red") sys.exit(1) if self.__check_source(src) and self.__check_destination(dst): from pardusTools import Main tools = Main(self.iso_dir, dst) if self.__check_disk_info(dst, tools.get_total_size()): self.__create_image(src, dst) else: self.utils.cprint( _("The path you have typed as second argument is invalid. Please check the USB directory." ), "red") unmount_dirs() sys.exit(1)
def __init__(self, src, dst): self.utils = Utils() self.progressbar = ProgressBar(src) self.iso_dir = tempfile.mkdtemp(suffix="_isoPuding") if not dst: self.partutils = PartitionUtils() if not self.partutils.detect_removable_drives(): self.utils.cprint(_("USB device not found."), "red") sys.exit() else: device, dst = self.__ask_destination() # FIX ME: You should not use it. if not dst: dst = tempfile.mkdtemp(suffix="_usbPuding") cmd = "mount -t vfat %s %s" % (device, dst) self.utils.cprint(_("Mounting USB device..."), "green") run_command(cmd) self.utils.cprint(_("Mounting image..."), "green") cmd = "fuseiso %s %s" % (src, self.iso_dir) if run_command(cmd): self.utils.cprint(_("Could not mounted image."), "red") sys.exit(1) if self.__check_source(src) and self.__check_destination(dst): from pardusTools import Main tools = Main(self.iso_dir, dst) if self.__check_disk_info(dst, tools.get_total_size()): self.__create_image(src, dst) else: self.utils.cprint(_("The path you have typed as second argument is invalid. Please check the USB directory."), "red") unmount_dirs() sys.exit(1)
class MainWindow(QtGui.QMainWindow, main_window_ui.Ui_MainWindow): def __init__(self, parent = None): self.iso_dir = tempfile.mkdtemp(suffix="_isoPuding") super(MainWindow, self).__init__(parent) self.setupUi(self) self.connect(self.button_quit, QtCore.SIGNAL("clicked()"), QtCore.SLOT("close()")) self.connect(self.actionQuit, QtCore.SIGNAL("triggered()"), QtCore.SLOT("close()")) @QtCore.pyqtSignature("bool") def on_button_browse_image_clicked(self): filename = QtGui.QFileDialog.getOpenFileName(self, self.tr("Select CD Image"), os.environ["HOME"], "%s (*.iso *.img)" % self.tr("Images")) self.line_image.setText(filename) @QtCore.pyqtSignature("bool") def on_button_browse_disk_clicked(self): self.browse_disk = SelectDisk() if self.browse_disk.exec_() == QtGui.QDialog.Accepted: dirname = self.browse_disk.get_selected_directory() if not dirname: self.warning_dialog(self.tr("Warning"), self.tr("You should select a valid directory.")) else: self.line_disk.setText(QtCore.QString(dirname)) @QtCore.pyqtSignature("bool") def on_actionAbout_triggered(self): about_puding = About() about_puding.exec_() @QtCore.pyqtSignature("bool") def on_button_create_clicked(self): # FIXED issue: #1 src = unicode(str(self.line_image.displayText())) dst = str(self.line_disk.displayText()) if dst.startswith("/dev/"): device = dst dst = tempfile.mkdtemp(suffix="_usbPuding") from puding.pardusTools import Authorization auth = Authorization() auth.mount(device, dst) if not self.__check_destination(dst): self.warning_dialog(self.tr("Directory is Invalid"), self.tr("Please check the USB disk path.")) return False try: (name, md5, url) = self.__get_source_info(src) except TypeError: # 'bool' object is not iterable # It's not true way, you should warn to the users with WarningDialog. return False mount_point = get_mounted(dst) (capacity, available, used) = get_disk_info(dst) # Mount iso if not os.path.ismount(self.iso_dir): cmd = "fuseiso %s %s" % (src, self.iso_dir) if run_command(cmd): # FIX ME: Should use warning dialog. return False # FIX ME: Now Puding supports only Pardus. from pardusTools import Main self.tools = Main(self.iso_dir, dst) total_size = self.tools.get_total_size() if available < total_size: self.warning_dialog("Warning", "There is not enough space left on your USB stick for the image.") else: self.confirm_infos = ConfirmDialog(src, dst, mount_point, name, total_size, capacity, available, used) if self.confirm_infos.exec_() == QtGui.QDialog.Accepted: create_USB_dirs(dst) self.__create_image(src, dst) if dst.endswith("Puding"): auth.umount(dst) run_command("fusermount -u %s" % self.iso_dir) def warning_dialog(self, title, message,): QtGui.QMessageBox.warning(self, title, message, QtGui.QMessageBox.Ok) def question_dialog(self, title, message): return QtGui.QMessageBox.question(self, title, message, QtGui.QMessageBox.Cancel | QtGui.QMessageBox.Ok) def __get_source_info(self, src): if QtCore.QString(src).isEmpty(): self.warning_dialog(self.tr("CD Image is Invalid"), self.tr("Please set an CD image path.")) return False if not os.path.isfile(src): self.warning_dialog(self.tr("CD Image is Invalid"), self.tr("Please check the CD image path.")) return False iso_size = get_iso_size(src) iso_size_progress = iso_size / increment_value check_iso = ProgressBar(title = self.tr("Verify Checksum"), message = self.tr("The checksum of the source is checking now..."), max_value = iso_size_progress) pi = ProgressIncrementChecksum(check_iso, src) # FIX ME: Why is it in here? def close_dialog(): pi.quit() check_iso.close() QtCore.QObject.connect(pi, QtCore.SIGNAL("increment_progress()"), check_iso.increment_progress) QtCore.QObject.connect(pi, QtCore.SIGNAL("closeProgressDialog()"), close_dialog) pi.start() check_iso.exec_() if not pi.checksum(): message = """The checksum of the source cannot be validated. Please specify a correct source or be sure that you have downloaded the source correctly.""" self.warning_dialog(self.tr("Checksum invalid"), self.tr(message)) return False return pi.checksum() def __check_destination(self, dst): if QtCore.QString(dst).isEmpty(): return False return os.path.ismount(str(dst)) def __create_image(self, src, dst): file_list = self.tools.file_list max_value = self.tools.get_number_of_files() create_image = ProgressBar(title = self.tr("Creating Image"), message = self.tr("Creating image..."), max_value = max_value) pi = ProgressIncrementCopy(create_image, self.iso_dir, dst) def close_dialog(): pi.quit() create_image.close() QtCore.QObject.connect(pi, QtCore.SIGNAL("increment_progress()"), create_image.increment_progress) QtCore.QObject.connect(pi, QtCore.SIGNAL("update_label"), pi.update_label) QtCore.QObject.connect(pi, QtCore.SIGNAL("closeProgressDialog()"), close_dialog) pi.start() create_image.exec_() self.warning_dialog(self.tr("USB Image is Ready"), self.tr("Your USB image is ready. Now you can install or run Pardus from USB storage.")) return True