コード例 #1
0
    def __init__(self, parent = None):
        self.partutils = PartitionUtils()
        self.partutils.detect_removable_drives()
        self.drives = self.partutils.return_drives()

        #print(self.drives)

        super(SelectDisk, self).__init__(parent)
        self.setupUi(self)

        for drive in self.drives:
            label = QtGui.QListWidgetItem(QtCore.QString(self.drives[drive]["label"]))
            label.setIcon(QtGui.QIcon(":/icons/images/usb.png"))
            self.listWidget.addItem(label)
コード例 #2
0
ファイル: puding_cmd.py プロジェクト: pars-linux/uludag
    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)
コード例 #3
0
ファイル: main_window.py プロジェクト: gkmngrgn/puding
class SelectDisk(QtGui.QDialog, select_disk_ui.Ui_Dialog):
    def __init__(self, parent = None):
        self.partutils = PartitionUtils()
        self.partutils.detect_removable_drives()
        self.drives = self.partutils.return_drives()

        #print(self.drives)

        super(SelectDisk, self).__init__(parent)
        self.setupUi(self)

        for drive in self.drives:
            label = QtGui.QListWidgetItem(QtCore.QString(self.drives[drive]["label"]))
            label.setIcon(QtGui.QIcon(":/icons/images/usb.png"))
            self.listWidget.addItem(label)

    @QtCore.pyqtSignature("bool")
    def on_button_browse_clicked(self):
        dirname = QtGui.QFileDialog.getExistingDirectory(self, self.tr("Choose Mount Disk Path"))

        if not dirname:
            self.line_directory.setText(dirname)

    def on_listWidget_itemClicked(self):
        item = self.listWidget.currentItem()
        label = item.text()

        for drive in self.drives:
            if self.drives[drive]["label"] == label:
                device = self.drives[drive]["mount"]
                if not device:
                    device = drive
                break

        self.line_directory.setText(device)

    def get_selected_directory(self):
        if self.line_directory.displayText() == "":
            return False

        return self.line_directory.displayText()
コード例 #4
0
class SelectDisk(QtGui.QDialog, select_disk_ui.Ui_Dialog):
    def __init__(self, parent = None):
        self.partutils = PartitionUtils()
        self.partutils.detect_removable_drives()
        self.drives = self.partutils.return_drives()

        #print(self.drives)

        super(SelectDisk, self).__init__(parent)
        self.setupUi(self)

        for drive in self.drives:
            label = QtGui.QListWidgetItem(QtCore.QString(self.drives[drive]["label"]))
            label.setIcon(QtGui.QIcon(":/icons/images/usb.png"))
            self.listWidget.addItem(label)

    @QtCore.pyqtSignature("bool")
    def on_button_browse_clicked(self):
        dirname = QtGui.QFileDialog.getExistingDirectory(self, self.tr("Choose Mount Disk Path"))

        if not dirname:
            self.line_directory.setText(dirname)

    def on_listWidget_itemClicked(self):
        item = self.listWidget.currentItem()
        label = item.text()

        for drive in self.drives:
            if self.drives[drive]["label"] == label:
                device = self.drives[drive]["mount"]
                if not device:
                    device = drive
                break

        self.line_directory.setText(device)

    def get_selected_directory(self):
        if self.line_directory.displayText() == "":
            return False

        return self.line_directory.displayText()
コード例 #5
0
ファイル: main_window.py プロジェクト: gkmngrgn/puding
    def __init__(self, parent = None):
        self.partutils = PartitionUtils()
        self.partutils.detect_removable_drives()
        self.drives = self.partutils.return_drives()

        #print(self.drives)

        super(SelectDisk, self).__init__(parent)
        self.setupUi(self)

        for drive in self.drives:
            label = QtGui.QListWidgetItem(QtCore.QString(self.drives[drive]["label"]))
            label.setIcon(QtGui.QIcon(":/icons/images/usb.png"))
            self.listWidget.addItem(label)
コード例 #6
0
ファイル: puding_cmd.py プロジェクト: dhirajkhatiwada1/uludag
    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)
コード例 #7
0
ファイル: puding_cmd.py プロジェクト: dhirajkhatiwada1/uludag
class Create:
    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 __ask_destination(self):
        self.drives = self.partutils.return_drives()
        if len(self.drives) == 1:
            # FIX ME: If disk is unmounted, you should mount it before return process!
            # It returns mount point directory.
            device = self.drives.keys()[0]

        else:
            drive_no = 0

            self.utils.cprint(_("Devices:"), "brightwhite")

            for drive in self.drives:
                drive_no += 1

                # FIX ME: Bad coding..
                self.utils.cprint("%d) %s:" % (drive_no, drive), "brightgreen")
                self.utils.cprint("    %s:" % _("Label"), "green", True)
                print(self.drives[drive]["label"])

                self.utils.cprint("    %s:" % _("Parent"), "green", True)
                print(str(self.drives[drive]["parent"]))

                self.utils.cprint("    %s:" % _("Mount Point"), "green", True)
                mount_dir = self.drives[drive]["mount"]
                if not mount_dir:
                    print("%s (%s)" % (self.iso_dir,  _("not mounted")))
                else:
                    print(mount_dir)

                self.utils.cprint("    %s:" % _("Unmount"), "green", True)
                print(str(self.drives[drive]["unmount"]))

                self.utils.cprint("    UUID:", "green", True)
                print(self.drives[drive]["uuid"])

                self.utils.cprint("    %s:" % _("File System Version"), "green", True)
                print(self.drives[drive]["fsversion"])

                self.utils.cprint("    %s:" % _("File System Type"), "green", True)
                print("%s\n" % self.drives[drive]["fstype"])

            try:
                part_number = int(raw_input(_("USB devices or partitions have found more than one. Please choose one:") + " "))

            except ValueError:
                self.utils.cprint(_("Please enter a number between 0 - %d." % (drive_no + 1)), "red")

                sys.exit(1)

            try:
                device = self.drives.keys()[part_number - 1]

            except IndexError:
                self.utils.cprint(_("You must enter a number between 0 - %d." % (drive_no + 1)), "red")

                sys.exit(1)

        destination = self.drives[device]["mount"]

        return device, destination

    def __check_destination(self, dst):
        if os.path.isdir(dst) and os.path.ismount(dst):
            return True

        return False

    def __check_disk_info(self, dst, total_size):
        (capacity, available, used) = get_disk_info(str(dst))
        if available < total_size:
            self.utils.cprint(_("There is not enough space left on your USB stick for the image."), "red")

            self.utils.cprint(_("Unmounting directories..."), "red")
            unmount_dirs()

            return False

        self.utils.cprint(_("USB disk informations:"), "brightgreen")
        self.utils.cprint("    %s:" % _("Capacity"), "green", True)
        print("%dMB" % capacity)

        self.utils.cprint("    %s:" % _("Available"), "green", True)
        print("%dMB" % available)

        self.utils.cprint("    %s:" % _("Used"), "green", True)
        print("%dMB" % used)

        print(_("\nPlease double check your path information. If you don't type the path to the USB stick correctly, you may damage your computer. Would you like to continue?"))

        answer = raw_input("%s " % _("Please type CONFIRM to continue:"))
        if answer in (_('CONFIRM'), _('confirm')):
            self.utils.cprint(_("Writing image data to USB stick!"), "green")

            return True

        self.utils.cprint(_("You did not type CONFIRM. Exiting.."), "red")
        unmount_dirs()

        return False

    def __check_source(self, src):
        if not os.path.isfile(src):
            self.utils.cprint(_("The path is invalid, please specify an image path."), "red")

            return False

        self.utils.cprint(_("Calculating checksum..."), "green")

        try:
            (name, md5, url) = self.progressbar.verify_iso_checksum(src)

            self.utils.cprint(_("Source Informations:"), "brightgreen")
            self.utils.cprint("    %s:" % _("Image Path"), "green", True)
            print(src)
            self.utils.cprint("    %s:" % _("Name"), "green", True)
            print(name)
            self.utils.cprint("    Md5sum:", "green", True)
            print(md5)
            self.utils.cprint("    %s:" % _("Download URL"), "green", True)
            print(url)

            return True

        # FIX ME: Bad Code..
        except TypeError:
            self.utils.cprint(_("The checksum of the source cannot be validated. Please specify a correct source or be sure that you have downloaded the source correctly."), "red")

            return False

    def __create_image(self, src, dst):
        create_USB_dirs(dst)

        self.utils.cprint(_("Creating boot manager..."), "yellow")
        if create_syslinux(self.iso_dir, dst):
            self.utils.cprint(_("Could not create boot manager."), "red")

            return False

        self.__copy_image(self.iso_dir, dst)

        self.utils.cprint(_("Unmounting image and USB disk..."), "green")
        unmount_dirs()

        self.utils.cprint(_("USB disk is ready. Now you can install or run Pardus from your USB disk."), "brightgreen")

        return True

    def __copy_image(self, src, dst):
        # FIX ME: Now, Puding supports only Pardus..
        from pardusTools import Main

        tools = Main(src, dst)
        file_list = tools.file_list

        for path in file_list:
            file_name = os.path.split(path)[-1]
            self.utils.cprint("%s:" % _("Copying"), "green", True)
            self.utils.cprint(file_name, "brightyellow")
            tools.copy_file(path)
コード例 #8
0
ファイル: puding_cmd.py プロジェクト: pars-linux/uludag
class Create:
    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 __ask_destination(self):
        self.drives = self.partutils.return_drives()
        if len(self.drives) == 1:
            # FIX ME: If disk is unmounted, you should mount it before return process!
            # It returns mount point directory.
            device = self.drives.keys()[0]

        else:
            drive_no = 0

            self.utils.cprint(_("Devices:"), "brightwhite")

            for drive in self.drives:
                drive_no += 1

                # FIX ME: Bad coding..
                self.utils.cprint("%d) %s:" % (drive_no, drive), "brightgreen")
                self.utils.cprint("    %s:" % _("Label"), "green", True)
                print(self.drives[drive]["label"])

                self.utils.cprint("    %s:" % _("Parent"), "green", True)
                print(str(self.drives[drive]["parent"]))

                self.utils.cprint("    %s:" % _("Mount Point"), "green", True)
                mount_dir = self.drives[drive]["mount"]
                if not mount_dir:
                    print("%s (%s)" % (self.iso_dir, _("not mounted")))
                else:
                    print(mount_dir)

                self.utils.cprint("    %s:" % _("Unmount"), "green", True)
                print(str(self.drives[drive]["unmount"]))

                self.utils.cprint("    UUID:", "green", True)
                print(self.drives[drive]["uuid"])

                self.utils.cprint("    %s:" % _("File System Version"),
                                  "green", True)
                print(self.drives[drive]["fsversion"])

                self.utils.cprint("    %s:" % _("File System Type"), "green",
                                  True)
                print("%s\n" % self.drives[drive]["fstype"])

            try:
                part_number = int(
                    raw_input(
                        _("USB devices or partitions have found more than one. Please choose one:"
                          ) + " "))

            except ValueError:
                self.utils.cprint(
                    _("Please enter a number between 0 - %d." %
                      (drive_no + 1)), "red")

                sys.exit(1)

            try:
                device = self.drives.keys()[part_number - 1]

            except IndexError:
                self.utils.cprint(
                    _("You must enter a number between 0 - %d." %
                      (drive_no + 1)), "red")

                sys.exit(1)

        destination = self.drives[device]["mount"]

        return device, destination

    def __check_destination(self, dst):
        if os.path.isdir(dst) and os.path.ismount(dst):
            return True

        return False

    def __check_disk_info(self, dst, total_size):
        (capacity, available, used) = get_disk_info(str(dst))
        if available < total_size:
            self.utils.cprint(
                _("There is not enough space left on your USB stick for the image."
                  ), "red")

            self.utils.cprint(_("Unmounting directories..."), "red")
            unmount_dirs()

            return False

        self.utils.cprint(_("USB disk informations:"), "brightgreen")
        self.utils.cprint("    %s:" % _("Capacity"), "green", True)
        print("%dMB" % capacity)

        self.utils.cprint("    %s:" % _("Available"), "green", True)
        print("%dMB" % available)

        self.utils.cprint("    %s:" % _("Used"), "green", True)
        print("%dMB" % used)

        print(
            _("\nPlease double check your path information. If you don't type the path to the USB stick correctly, you may damage your computer. Would you like to continue?"
              ))

        answer = raw_input("%s " % _("Please type CONFIRM to continue:"))
        if answer in (_('CONFIRM'), _('confirm')):
            self.utils.cprint(_("Writing image data to USB stick!"), "green")

            return True

        self.utils.cprint(_("You did not type CONFIRM. Exiting.."), "red")
        unmount_dirs()

        return False

    def __check_source(self, src):
        if not os.path.isfile(src):
            self.utils.cprint(
                _("The path is invalid, please specify an image path."), "red")

            return False

        self.utils.cprint(_("Calculating checksum..."), "green")

        try:
            (name, md5, url) = self.progressbar.verify_iso_checksum(src)

            self.utils.cprint(_("Source Informations:"), "brightgreen")
            self.utils.cprint("    %s:" % _("Image Path"), "green", True)
            print(src)
            self.utils.cprint("    %s:" % _("Name"), "green", True)
            print(name)
            self.utils.cprint("    Md5sum:", "green", True)
            print(md5)
            self.utils.cprint("    %s:" % _("Download URL"), "green", True)
            print(url)

            return True

        # FIX ME: Bad Code..
        except TypeError:
            self.utils.cprint(
                _("The checksum of the source cannot be validated. Please specify a correct source or be sure that you have downloaded the source correctly."
                  ), "red")

            return False

    def __create_image(self, src, dst):
        create_USB_dirs(dst)

        self.utils.cprint(_("Creating boot manager..."), "yellow")
        if create_syslinux(self.iso_dir, dst):
            self.utils.cprint(_("Could not create boot manager."), "red")

            return False

        self.__copy_image(self.iso_dir, dst)

        self.utils.cprint(_("Unmounting image and USB disk..."), "green")
        unmount_dirs()

        self.utils.cprint(
            _("USB disk is ready. Now you can install or run Pardus from your USB disk."
              ), "brightgreen")

        return True

    def __copy_image(self, src, dst):
        # FIX ME: Now, Puding supports only Pardus..
        from pardusTools import Main

        tools = Main(src, dst)
        file_list = tools.file_list

        for path in file_list:
            file_name = os.path.split(path)[-1]
            self.utils.cprint("%s:" % _("Copying"), "green", True)
            self.utils.cprint(file_name, "brightyellow")
            tools.copy_file(path)