Esempio n. 1
0
 def __init__(self, parent, storage):
     self.storage = storage
     self.intf = parent.intf
     self.parent = parent
     self.dialog = Dialog(_("Partitions to Shrink"), closeButton=False)
     self.dialog.addWidget(ShrinkWidget(self))
     self.dialog.resize(QSize(0,0))
Esempio n. 2
0
    def __init__(self, parent, request, isNew=False):
        self.parent = parent
        self.storage = parent.storage
        self.intf = parent.intf
        self.origrequest = request
        self.isNew = isNew

        availraidparts = self.parent.storage.unusedRaidMembers(
            array=self.origrequest)
        if availraidparts < 2:
            self.intf.messageWindow(_("Invalid Raid Members"),
                                    _("At least two unused software RAID "
                                      "partitions are needed to create "
                                      "a RAID device.\n\n"
                                      "First create at least two partitions "
                                      "of type \"software RAID\", and then "
                                      "select the \"RAID\" option again."),
                                    type="error")
            return

        if isNew:
            title = _("Make RAID Device")
        else:
            if request.minor is not None:
                title = _("Edit RAID Device: %s") % request.path
            else:
                title = _("Edit RAID Device")

        self.dialog = Dialog(title, closeButton=False)
        self.dialog.addWidget(RaidWidget(self, request, isNew))
        self.dialog.resize(QSize(450, 200))
Esempio n. 3
0
    def __init__(self,
                 parent,
                 origrequest,
                 isNew=False,
                 partedPartition=None,
                 restricts=None):
        self.storage = parent.storage
        self.intf = parent.intf
        self.origrequest = origrequest
        self.isNew = isNew
        self.parent = parent
        self.partedPartition = partedPartition

        if isNew:
            title = _("Create Partition on %(path)s (%(model)s)") % {
                "path": os.path.basename(partedPartition.disk.device.path),
                "model": partedPartition.disk.device.model
            }
        else:
            try:
                title = _("Edit Partition %s") % origrequest.path
            except:
                title = _("Edit Partition")

        self.dialog = Dialog(title, closeButton=False)
        self.dialog.addWidget(
            PartitionWidget(self, origrequest, isNew, restricts))
        self.dialog.resize(QSize(350, 175))
Esempio n. 4
0
 def toggleTetris(self):
     self.tetris = Dialog(_("Tetris"), None, True, QKeySequence(Qt.Key_F6))
     _tetris = Tetris(self.tetris)
     self.tetris.addWidget(_tetris)
     self.tetris.resize(240, 500)
     _tetris.start()
     self.tetris.exec_()
Esempio n. 5
0
 def toggleConsole(self):
     if not self.terminal:
         terminal = QTermWidget()
         terminal.setScrollBarPosition(QTermWidget.ScrollBarRight)
         terminal.setColorScheme(1)
         terminal.sendText("export TERM='xterm'\nclear\n")
         self.terminal = Dialog(_("Terminal"), terminal, True, QKeySequence(Qt.Key_F11))
         self.terminal.resize(700, 500)
     self.terminal.exec_()
Esempio n. 6
0
def showException(ex_type, tb):
    title = "Unhandled Exception!"
    
    if ex_type == yali.exception_fatal:
        w = ErrorWidget(tb)
    else:
        w = ExceptionWidget(tb)
    d = Dialog(title, w, None)
    d.resize(500,400)
    d.exec_loop()
Esempio n. 7
0
def showException(ex_type, tb):
    title = _("Error!")
    
    if ex_type in (yali.exception_fatal, yali.exception_pisi):
        w = ErrorWidget(tb)
    else:
        w = ExceptionWidget(tb)
    d = Dialog(title, w, None)
    d.resize(500,400)
    d.exec_loop()
Esempio n. 8
0
def showException(error_type, error_traceback):
    title = _("An error occured")
    closeButton = True

    if error_type in (yali.exception_yali, yali.exception_pisi):
        closeButton = False

    ctx.logger.debug(error_traceback)
    d = Dialog(title, ExceptionWidget(error_traceback, not closeButton), None, closeButton, icon="error")
    d.resize(300,160)
    d.exec_()
Esempio n. 9
0
def showException(ex_type, tb):
    title = _("An error occured")
    closeButton = True

    if ex_type in (yali.exception_fatal, yali.exception_pisi):
        closeButton = False

    ctx.debugger.log(tb)
    d = Dialog(title, ExceptionWidget(tb, not closeButton), None, closeButton, icon="error")
    d.resize(300,160)
    d.exec_()
Esempio n. 10
0
    def __init__(self, parent, request, isNew=False):
        self.parent = parent
        self.storage = parent.storage
        self.origrequest = request
        self.peSize = request.peSize
        self.pvs = request.pvs[:]
        self.isNew = isNew
        self.intf = parent.intf
        self.operations = []
        self.dialog = None
        self.lvs = {}

        for lv in self.origrequest.lvs:
            self.lvs[lv.lvname] = {
                "name": lv.lvname,
                "size": lv.size,
                "format": copy.copy(lv.format),
                "originalFormat": lv.originalFormat,
                "stripes": lv.stripes,
                "logSize": lv.logSize,
                "snapshotSpace": lv.snapshotSpace,
                "exists": lv.exists
            }

        self.availlvmparts = self.storage.unusedPVS(vg=request)
        # if no PV exist, raise an error message and return
        if len(self.availlvmparts) < 1:
            self.intf.messageWindow(
                _("General", "Not enough physical volumes"),
                _(
                    "General", "At least one unused physical "
                    "volume partition is "
                    "needed to\ncreate an LVM Volume Group.\n"
                    "Create a partition or RAID array "
                    "of type \"physical volume\n(LVM)\" and then "
                    "select the \"LVM\" option again."),
                type="warning")
            self.dialog = None
            return

        if isNew:
            title = _("General", "Make LVM Volume Group")
        else:
            try:
                title = _("General",
                          "Edit LVM Volume Group: %s") % (request.name, )
            except AttributeError:
                title = _("General", "Edit LVM Volume Group")

        self.dialog = Dialog(title, closeButton=False)
        self.dialog.addWidget(
            VolumeGroupWidget(self, self.origrequest, isNew=isNew))
        self.dialog.resize(QSize(450, 200))
Esempio n. 11
0
    def __init__(self, parent, request, isNew=False):
        self.parent = parent
        self.storage = parent.parent.storage
        self.intf = parent.parent.intf
        self.origrequest = request
        self.isNew = isNew

        if isNew:
            title = _("Make Logical Volume")
        else:
            title = _("Edit Logical Volume: %s") % request.lvname

        self.dialog = Dialog(title, closeButton=False)
        self.dialog.addWidget(LogicalVolumeWidget(self, request, isNew))
        self.dialog.resize(QSize(0, 0))
Esempio n. 12
0
 def toggleTetris(self):
     self.tetris = Dialog(_("Tetris"), None, self, True, QtGui.QKeySequence(Qt.Key_F6))
     _tetris = Tetris(self.tetris)
     self.tetris.addWidget(_tetris)
     self.tetris.resize(240,500)
     _tetris.start()
     self.tetris.exec_()
Esempio n. 13
0
    def __init__(self, parent, request, isNew=False):
        self.parent = parent
        self.storage = parent.storage
        self.intf = parent.intf
        self.origrequest = request
        self.isNew = isNew

        availraidparts = self.parent.storage.unusedRaidMembers(array=self.origrequest)
        if availraidparts < 2:
            self.intf.messageWindow(_("Invalid Raid Members"),
                                    _("At least two unused software RAID "
                                     "partitions are needed to create "
                                     "a RAID device.\n\n"
                                     "First create at least two partitions "
                                     "of type \"software RAID\", and then "
                                     "select the \"RAID\" option again."),
                                    customIcon="error")
            return

        if isNew:
            title = _("Make RAID Device")
        else:
            if request.minor is not None:
                title = _("Edit RAID Device: %s") % request.path
            else:
                title = _("Edit RAID Device")

        self.dialog = Dialog(title, closeButton=False)
        self.dialog.addWidget(RaidWidget(self, request, isNew))
        if self.origrequest.exists:
            self.dialog.resize(QSize(450, 200))
        else:
            self.dialog.resize(QSize(450, 400))
Esempio n. 14
0
 def __init__(self, parent, storage):
     self.storage = storage
     self.intf = parent.intf
     self.parent = parent
     self.dialog = Dialog(_("Partitions to Shrink"), closeButton=False)
     self.dialog.addWidget(ShrinkWidget(self))
     self.dialog.resize(QSize(0,0))
Esempio n. 15
0
 def toggleConsole(self):
     if not self.terminal:
         terminal = QTermWidget()
         terminal.setScrollBarPosition(QTermWidget.ScrollBarRight)
         terminal.setColorScheme(1)
         terminal.sendText("export TERM='xterm'\nclear\n")
         self.terminal = Dialog(_("Terminal"), terminal, True, QKeySequence(Qt.Key_F11))
         self.terminal.resize(700, 500)
     self.terminal.exec_()
Esempio n. 16
0
class Debugger:
    def __init__(self,showLineNumbers=True):
        title = _("Debug")
        self.debugWidget = QWidget()
        self.traceback = DebugContainer(self.debugWidget,showLineNumbers)
        
        l = QVBoxLayout(self.debugWidget)
        l.addWidget(self.traceback)
        
        self.window = Dialog(title,self.debugWidget,None,extraButtons=True)
        self.window.resize(500,400)
        self.aspect = DebuggerAspect(self)
        
    def showWindow(self):
        self.window.show()
        
    def log(self,log,type=1):
        self.traceback.add(QString(log),type)
Esempio n. 17
0
    def __init__(self,showLineNumbers=True):
        title = _("Debug")
        self.debugWidget = QWidget()
        self.traceback = DebugContainer(self.debugWidget,showLineNumbers)

        l = QVBoxLayout(self.debugWidget)
        l.addWidget(self.traceback)

        self.window = Dialog(title,self.debugWidget,None,extraButtons=True)
        self.window.resize(500,400)
        self.aspect = DebuggerAspect(self)
Esempio n. 18
0
class ShrinkEditor:
    def __init__(self, parent, storage):
        self.storage = storage
        self.intf = parent.intf
        self.parent = parent
        self.dialog = Dialog(_("Partitions to Shrink"), closeButton=False)
        self.dialog.addWidget(ShrinkWidget(self))
        self.dialog.resize(QSize(0,0))

    def run(self):
        if self.dialog is None:
            return []

        while 1:
            rc = self.dialog.exec_()
            operations = []

            if not rc:
                self.destroy()
                return (rc, operations)

            widget = self.dialog.content

            request = widget.partitions.itemData(widget.partitions.currentIndex())#.toPyObject() burada hata olabilir
            newsize = widget.sizeSpin.value()

            try:
                operations.append(OperationResizeFormat(request, newsize))
            except ValueError as e:
                self.intf.messageWindow(_("Resize FileSystem Error"),
                                        _("%(device)s: %(msg)s") %
                                        {'device': request.format.device, 'msg': e.message},
                                        type="error")
                continue

            try:
                operations.append(OperationResizeDevice(request, newsize))
            except ValueError as e:
                self.intf.messageWindow(_("Resize Device Error"),
                                              _("%(name)s: %(msg)s") %
                                               {'name': request.name, 'msg': e.message},
                                               type="warning")
                continue

            # everything ok, fall out of loop
            break

        self.dialog.destroy()

        return (rc, operations)

    def destroy(self):
        if self.dialog:
            self.dialog = None
Esempio n. 19
0
class ShrinkEditor:
    def __init__(self, parent, storage):
        self.storage = storage
        self.intf = parent.intf
        self.parent = parent
        self.dialog = Dialog(_("Partitions to Shrink"), closeButton=False)
        self.dialog.addWidget(ShrinkWidget(self))
        self.dialog.resize(QSize(0,0))

    def run(self):
        if self.dialog is None:
            return []

        while 1:
            rc = self.dialog.exec_()
            operations = []

            if not rc:
                self.destroy()
                return (rc, operations)

            widget = self.dialog.content

            request = widget.partitions.itemData(widget.partitions.currentIndex()).toPyObject()
            newsize = widget.sizeSpin.value()

            try:
                operations.append(OperationResizeFormat(request, newsize))
            except ValueError as e:
                self.intf.messageWindow(_("Resize FileSystem Error"),
                                        _("%(device)s: %(msg)s") %
                                        {'device': request.format.device, 'msg': e.message},
                                        type="error")
                continue

            try:
                operations.append(OperationResizeDevice(request, newsize))
            except ValueError as e:
                self.intf.messageWindow(_("Resize Device Error"),
                                              _("%(name)s: %(msg)s") %
                                               {'name': request.name, 'msg': e.message},
                                               type="warning")
                continue

            # everything ok, fall out of loop
            break

        self.dialog.destroy()

        return (rc, operations)

    def destroy(self):
        if self.dialog:
            self.dialog = None
Esempio n. 20
0
    def __init__(self, parent, request, isNew=False):
        self.parent = parent
        self.storage = parent.parent.storage
        self.intf = parent.parent.intf
        self.origrequest = request
        self.isNew = isNew

        if isNew:
            title = _("Make Logical Volume")
        else:
            title = _("Edit Logical Volume: %s") % request.lvname

        self.dialog = Dialog(title, closeButton=False)
        self.dialog.addWidget(LogicalVolumeWidget(self, request, isNew))
        self.dialog.resize(QSize(0, 0))
    def execute(self):

        # show confirmation dialog
        w = WarningWidget(self)
        self.dialog = WarningDialog(w, self)
        if not self.dialog.exec_loop():
            # disabled by weaver.
            ctx.screens.enablePrev()
            
            self.partlist.update()
            return False


        # show information window...
        info_window = InformationWindow(self, _("Please wait while formatting!"))

        # commit events
        self.partlist.devices_commit()

        # inform user...
        self.partlist.showPartitionRequests(formatting=True)
        # process events and show partitioning information!
        ctx.screens.processEvents()
        
        
        ##
        # check swap partition, if not present use swap file
        rt = request.mountRequestType
        pt = parttype.swap
        swap_part_req = ctx.partrequests.searchPartTypeAndReqType(pt, rt)

        if not swap_part_req:
            # No swap partition defined using swap as file in root
            # partition
            rt = request.mountRequestType
            pt = parttype.root
            root_part_req = ctx.partrequests.searchPartTypeAndReqType(pt, rt)
            ctx.partrequests.append(
                request.SwapFileRequest(root_part_req.partition(),
                                        root_part_req.partitionType()))

        # apply all partition requests
        ctx.partrequests.applyAll()

        # close window
        info_window.close(True)
        return True
Esempio n. 22
0
    def __init__(self, parent, request, isNew=False):
        self.parent = parent
        self.storage = parent.storage
        self.origrequest = request
        self.peSize = request.peSize
        self.pvs = request.pvs[:]
        self.isNew = isNew
        self.intf = parent.intf
        self.operations = []
        self.dialog = None
        self.lvs = {}

        for lv in self.origrequest.lvs:
            self.lvs[lv.lvname] = {"name": lv.lvname,
                                   "size": lv.size,
                                   "format": copy.copy(lv.format),
                                   "originalFormat": lv.originalFormat,
                                   "stripes": lv.stripes,
                                   "logSize": lv.logSize,
                                   "snapshotSpace": lv.snapshotSpace,
                                   "exists": lv.exists}

        self.availlvmparts = self.storage.unusedPVS(vg=request)
        # if no PV exist, raise an error message and return
        if len(self.availlvmparts) < 1:
            self.intf.messageWindow(_("Not enough physical volumes"),
                                    _("At least one unused physical "
                                      "volume partition is "
                                      "needed to\ncreate an LVM Volume Group.\n"
                                      "Create a partition or RAID array "
                                      "of type \"physical volume\n(LVM)\" and then "
                                      "select the \"LVM\" option again."),
                                    type="warning")
            self.dialog = None
            return

        if isNew:
            title = _("Make LVM Volume Group")
        else:
            try:
                title = _("Edit LVM Volume Group: %s") % (request.name,)
            except AttributeError:
                title = _("Edit LVM Volume Group")

        self.dialog = Dialog(title, closeButton=False)
        self.dialog.addWidget(VolumeGroupWidget(self, self.origrequest, isNew=isNew))
        self.dialog.resize(QSize(450, 200))
Esempio n. 23
0
    def __init__(self,showTimeStamp=True):
        title = _("Debugging Console")
        self.debugWidget = QtGui.QWidget()
        self.debugShortCut = QtGui.QShortcut(QtGui.QKeySequence(Qt.Key_F2),self.debugWidget)
        QObject.connect(self.debugShortCut, SIGNAL("activated()"), self.toggleDebug)

        self.traceback = DebugContainer(self.debugWidget,showTimeStamp)
        self.loglevel = QtGui.QComboBox(self.debugWidget)
        self.loglevel.addItem("0: Developer Messages")
        self.loglevel.addItem("1: All Messages")
        QObject.connect(self.loglevel, SIGNAL("currentIndexChanged(int)"),self.loglevelChanged)

        l = QtGui.QVBoxLayout(self.debugWidget)
        l.addWidget(self.loglevel)
        l.addWidget(self.traceback)

        self.window = Dialog(title,self.debugWidget)
        self.window.resize(500,400)
        self.aspect = DebuggerAspect(self)
Esempio n. 24
0
    def execute(self):

        # show confirmation dialog
        w = WarningWidget(self)
        self.dialog = WarningDialog(w, self)
        if not self.dialog.exec_loop():
            return False


        # commit events
        self.partlist.devices_commit()

        # inform user...
        self.partlist.showPartitionRequests(formatting=True)
        # process events and show partitioning information!
        ctx.screens.processEvents()
        ctx.screens.processEvents()
        
        
        ##
        # check swap partition, if not present use swap file
        rt = request.mountRequestType
        pt = parttype.swap
        found_swap_part = [x for x in ctx.partrequests.searchPartTypeAndReqType(pt, rt)]
        # this should give (at most) one result
        # cause we are storing one request for a partitionType()
        assert(len(found_swap_part) <= 1)


        if not found_swap_part:
            print "no swap partition defined using swap as file..."
            # find root partition
            rt = request.mountRequestType
            pt = parttype.root
            for r in ctx.partrequests.searchPartTypeAndReqType(pt, rt):
                ctx.partrequests.append(
                    request.SwapFileRequest(r.partition(), r.partitionType()))

        # apply all partition requests
        ctx.partrequests.applyAll()

        return True
Esempio n. 25
0
    def __init__(self, parent, origrequest, isNew=False, partedPartition=None, restricts=None):
        self.storage = parent.storage
        self.intf = parent.intf
        self.origrequest = origrequest
        self.isNew = isNew
        self.parent = parent
        self.partedPartition = partedPartition

        if isNew:
            title = _("Create Partition on %(path)s (%(model)s)") %  {"path":os.path.basename(partedPartition.disk.device.path),
                                                                      "model":partedPartition.disk.device.model}
        else:
            try:
                title = _("Edit Partition %s") % origrequest.path
            except:
                title = _("Edit Partition")

        self.dialog = Dialog(title, closeButton=False)
        self.dialog.addWidget(PartitionWidget(self, origrequest, isNew, restricts))
        self.dialog.resize(QSize(350, 175))
Esempio n. 26
0
class Debugger:
    def __init__(self,showTimeStamp=True):
        title = _("Debugging Console")
        self.debugWidget = QtGui.QWidget()
        self.debugShortCut = QtGui.QShortcut(QtGui.QKeySequence(Qt.Key_F2),self.debugWidget)
        QObject.connect(self.debugShortCut, SIGNAL("activated()"), self.toggleDebug)

        self.traceback = DebugContainer(self.debugWidget,showTimeStamp)
        self.loglevel = QtGui.QComboBox(self.debugWidget)
        self.loglevel.addItem("0: Developer Messages")
        self.loglevel.addItem("1: All Messages")
        QObject.connect(self.loglevel, SIGNAL("currentIndexChanged(int)"),self.loglevelChanged)

        l = QtGui.QVBoxLayout(self.debugWidget)
        l.addWidget(self.loglevel)
        l.addWidget(self.traceback)

        self.window = Dialog(title,self.debugWidget)
        self.window.resize(500,400)
        self.aspect = DebuggerAspect(self)

    def loglevelChanged(self,newLevel):
        self.traceback.level = newLevel

    def showWindow(self):
        self.window.show()

    def hideWindow(self):
        self.window.hide()

    def isVisible(self):
        return self.window.isVisible()

    def toggleDebug(self):
        if self.isVisible():
            self.hideWindow()
        else:
            self.showWindow()

    def log(self,log,type=0,indent=0):
        if ctx.debugEnabled and not log == '':
            self.traceback.add(unicode(log),type,indent)
Esempio n. 27
0
 def showError(self, title, message, parent=None):
     r = ErrorWidget(parent)
     r.label.setText(message)
     d = Dialog(title, r, self, closeButton=False)
     d.resize(300,200)
     d.exec_()
Esempio n. 28
0
class PartitionEditor:
    def __init__(self,
                 parent,
                 origrequest,
                 isNew=False,
                 partedPartition=None,
                 restricts=None):
        self.storage = parent.storage
        self.intf = parent.intf
        self.origrequest = origrequest
        self.isNew = isNew
        self.parent = parent
        self.partedPartition = partedPartition

        if isNew:
            title = _("Create Partition on %(path)s (%(model)s)") % {
                "path": os.path.basename(partedPartition.disk.device.path),
                "model": partedPartition.disk.device.model
            }
        else:
            try:
                title = _("Edit Partition %s") % origrequest.path
            except:
                title = _("Edit Partition")

        self.dialog = Dialog(title, closeButton=False)
        self.dialog.addWidget(
            PartitionWidget(self, origrequest, isNew, restricts))
        self.dialog.resize(QSize(350, 175))

    def run(self):
        if self.dialog is None:
            return []

        while 1:
            rc = self.dialog.exec_()
            operations = []

            if not rc:
                self.destroy()
                return []

            widget = self.dialog.content

            mountpoint = unicode(widget.mountpointMenu.currentText())
            active = widget.mountpointMenu.isEnabled()
            if active and mountpoint:
                msg = sanityCheckMountPoint(mountpoint)
                if msg:
                    ctx.interface.messageWindow(_("Mount Point Error"),
                                                msg,
                                                type="warning")
                    continue

                used = False
                for (mp, dev) in self.storage.mountpoints.iteritems():
                    if mp == mountpoint and \
                       dev.id != self.origrequest.id and \
                       not (self.origrequest.format.type == "luks" and
                            self.origrequest in dev.parents):
                        used = True
                        break

                if used:
                    ctx.interface.messageWindow(
                        _("Mount point in use"),
                        _("The mount point \"%s\" is in "
                          "use. Please pick another.") % (mountpoint, ),
                        type="warning")
                    continue

            if not self.origrequest.exists:
                if widget.primaryCheck.isChecked():
                    primary = True
                else:
                    primary = None

                size = widget.sizeSpin.value()

                formatType = str(widget.filesystemMenu.currentText())
                format = formats.getFormat(formatType, mountpoint=mountpoint)
                if self.isNew:
                    disk = self.storage.devicetree.getDeviceByPath(
                        self.partedPartition.disk.device.path)
                else:
                    disk = self.origrequest.disk

                err = doUIRAIDLVMChecks(format, [disk.name], self.storage)
                if err:
                    self.intf.messageWindow(_("Error With Request"),
                                            err,
                                            type="error")
                    continue

                weight = partitioning.weight(mountpoint=mountpoint,
                                             fstype=format.type)

                if self.isNew:
                    request = self.storage.newPartition(size=size,
                                                        grow=None,
                                                        maxsize=0,
                                                        primary=primary,
                                                        format=format,
                                                        parents=disk)
                else:
                    request = self.origrequest
                    request.weight = weight

                usedev = request

                if self.isNew:
                    operations.append(OperationCreateDevice(request))
                else:
                    request.req_size = size
                    request.req_base_size = size
                    request.req_grow = None
                    request.req_max_size = 0
                    request.req_primary = primary
                    request.req_disks = [disk]

                operations.append(OperationCreateFormat(usedev, format))

            else:
                # preexisting partition
                request = self.origrequest
                usedev = request

                origformat = usedev.format
                devicetree = self.storage.devicetree

                if widget.formatRadio.isChecked():
                    formatType = str(widget.formatCombo.currentText())
                    format = formats.getFormat(formatType,
                                               mountpoint=mountpoint,
                                               device=usedev.path)

                    operations.append(OperationCreateFormat(usedev, format))
                else:
                    cancel = []
                    cancel.extend(
                        devicetree.findOperations(type="destroy",
                                                  object="format",
                                                  devid=request.id))
                    cancel.extend(
                        devicetree.findOperations(type="create",
                                                  object="format",
                                                  devid=request.id))
                    cancel.reverse()
                    for operation in cancel:
                        devicetree.removeOperation(operation)

                    request.format = request.originalFormat
                    usedev = request

                    if usedev.format.mountable:
                        usedev.format.mountpoint = mountpoint

                if self.origrequest.protected and usedev.format.mountable:
                    # users can set a mountpoint for protected partitions
                    usedev.format.mountpoint = mountpoint

                request.weight = partitioning.weight(
                    mountpoint=mountpoint, fstype=request.format.type)

                if widget.migrateRadio.isChecked():
                    operations.append(OperationMigrateFormat(usedev))

                if widget.resizeRadio.isChecked():
                    size = widget.resizeSpin.value()
                    try:
                        operations.append(OperationResizeDevice(request, size))
                        if request.format.type and request.format.exists:
                            operations.append(
                                OperationResizeFormat(request, size))
                    except ValueError:
                        pass

                if request.format.exists and \
                   getattr(request, "mountpoint", None) and \
                   self.storage.formatByDefault(request):
                    if not queryNoFormatPreExisting(self.intf):
                        continue

            # everything ok, fall out of loop
            break

        return operations

    def destroy(self):
        if self.dialog:
            self.dialog = None
Esempio n. 29
0
 def showReleaseNotes(self):
     # make a release notes dialog
     dialog = Dialog(_('Release Notes'), ReleaseNotes(self), self)
     dialog.resize(500, 400)
     dialog.exec_()
Esempio n. 30
0
class Widget(QWidget):
    signalProcessEvents = pyqtSignal()

    def __init__(self):
        QWidget.__init__(self, None)
        # Set pixmaps resource before Main Window initialized
        self._resource = os.path.join(ctx.consts.theme_dir, ctx.flags.theme,
                                      ctx.consts.pixmaps_resource_file)
        if os.path.exists(self._resource):
            resource = QResource()
            resource.registerResource(self._resource)
        else:
            raise yali.Error, _("Pixmaps resources file doesn't exists")

        self.ui = Ui_YaliMain()
        self.ui.setupUi(self)

        self.font = 10
        self.animation_type = None

        self.screens = None
        self.screens_content = None

        self.pds_helper = HelpWidget(self.ui.scrollAreaWidgetContents)

        # shortcut to open help
        self.help_shortcut = QShortcut(QKeySequence(Qt.Key_F1), self)

        # shortcut to open debug window
        #self.debugShortCut = QtWidgets.QShortcut(QtWidgets.QKeySequence(Qt.Key_F2),self)

        # something funny
        self.tetris_shortcut = QShortcut(QKeySequence(Qt.Key_F6), self)
        self.cursor_shortcut = QShortcut(QKeySequence(Qt.Key_F7), self)
        self.theme_shortcut = QShortcut(QKeySequence(Qt.Key_F8), self)

        # shortcut to open a console
        self.console_shortcut = QShortcut(QKeySequence(Qt.Key_F11), self)

        # set style
        self._style = os.path.join(ctx.consts.theme_dir, ctx.flags.theme,
                                   ctx.consts.style_file)
        if os.path.exists(self._style):
            self.updateStyle()
        else:
            raise yali.Error, _("Style file doesn't exists")

        # set screens content
        release_file = os.path.join(ctx.consts.branding_dir,
                                    ctx.flags.branding,
                                    ctx.consts.release_file)
        if os.path.exists(release_file):
            self.screens_content = yali.util.parse_branding_screens(
                release_file)
        else:
            raise yali.Error, _("Release file doesn't exists")

        # move one step at a time
        self.step_increment = 1

        # ToolButton Popup Menu
        self.menu = QMenu()
        self.shutdown = self.menu.addAction(
            QIcon(QPixmap(":/images/system-shutdown.png")),
            _("Turn Off Computer"))
        self.reboot = self.menu.addAction(
            QIcon(QPixmap(":/images/system-reboot.png")),
            _("Restart Computer"))
        self.restart = self.menu.addAction(
            QIcon(QPixmap(":/images/system-yali-reboot.png")),
            _("Restart YALI"))
        #self.menu.setDefaultAction(self.shutdown)
        self.ui.system_menu.setMenu(self.menu)
        self.ui.system_menu.setDefaultAction(self.shutdown)

        # Main Slots
        self.help_shortcut.activated.connect(self.pds_helper.toggleHelp)
        #self.debugShortCut.activated.connect(self.toggleDebug)
        self.console_shortcut.activated.connect(self.toggleConsole)
        self.cursor_shortcut.activated.connect(self.toggleCursor)
        self.theme_shortcut.activated.connect(self.toggleTheme)
        self.tetris_shortcut.activated.connect(self.toggleTetris)
        self.ui.buttonNext.clicked.connect(self.slotNext)
        self.ui.buttonBack.clicked.connect(self.slotBack)
        self.ui.toggleHelp.clicked.connect(self.pds_helper.toggleHelp)
        if not ctx.flags.install_type == ctx.STEP_FIRST_BOOT:
            self.ui.releaseNotes.clicked.connect(self.showReleaseNotes)
        else:
            self.ui.releaseNotes.hide()
        self.menu.triggered[QAction].connect(self.slotMenu)

        self.cmb = _("right")
        self.dont_ask_again = False
        self.terminal = None
        self.tetris = None

        self.ui.helpContentFrame.hide()

        self.effect = QGraphicsOpacityEffect(self)
        self.ui.mainStack.setGraphicsEffect(self.effect)
        self.effect.setOpacity(1.0)

        self.anime = QTimer(self)
        self.anime.timeout.connect(self.animate)

    def mousePressEvent(self, event):
        if event.button() == Qt.RightButton and not self.dont_ask_again:
            if self.cmb == _("left"):
                ocmb = _("right")
            else:
                ocmb = _("left")
            reply = QuestionDialog(
                _("Mouse Settings"),
                _("You just clicked the <b>%s</b> mouse button.") % self.cmb,
                _("Do you want to switch to the <b>%s</b> handed configuration?"
                  ) % ocmb,
                dontAsk=True)
            if reply == "yes":
                yali.sysutils.setMouse(self.cmb)
                self.cmb = ocmb
            elif reply == "dontask":
                self.dont_ask_again = True

    def updateStyle(self):
        self.setStyleSheet(file(self._style).read())
        self.font = 10

    def setFontPlus(self):
        self.increaseFontSize(1)

    def setFontMinus(self):
        self.increaseFontSize(-1)

    def increaseFontSize(self, num):
        # We have to edit style sheet to set new fonts
        # Because if you use a style sheet in your application
        # ::setFont gets useless :( http://doc.trolltech.com/4.5/qapplication.html#setFont
        old = "QWidget{font:%dpt;}" % self.font
        self.font = self.font + num
        new = "QWidget{font:%dpt;}" % self.font
        self.setStyleSheet(self.styleSheet().replace(old, new))

    def slotMenu(self, action):
        if action == self.shutdown:
            reply = QuestionDialog(
                _("Warning"),
                _("Are you sure you want to shut down your computer now?"))
            if reply == "yes":
                yali.util.shutdown()
        elif action == self.reboot:
            reply = QuestionDialog(
                _("Warning"),
                _("Are you sure you want to restart your computer now?"))
            if reply == "yes":
                yali.util.reboot()
        else:
            reply = QuestionDialog(
                _("Warning"),
                _("Are you sure you want to restart the YALI installer now?"))
            if reply == "yes":
                os.execv("/usr/bin/yali-bin", sys.argv)

    def toggleTheme(self):
        "This easter egg will be implemented later"
        """
        if self._style == os.path.join(ctx.consts.theme_dir, "%s/style.qss" % ctx.flags.theme):
            if os.path.join(ctx.consts.theme_dir, "%s/style.glass.qss" % ctx.flags.theme):
                self._style = os.path.join(ctx.consts.theme_dir, "%s/style.glass.qss" % ctx.flags.theme)
        else:
            self._style = os.path.join(ctx.consts.theme_dir, "%s/style.qss" % ctx.flags.theme)
        self.updateStyle()
        """

    def toggleConsole(self):
        if not self.terminal:
            terminal = QTermWidget()
            terminal.setScrollBarPosition(QTermWidget.ScrollBarRight)
            terminal.setColorScheme(1)
            terminal.sendText("export TERM='xterm'\nclear\n")
            self.terminal = Dialog(_("Terminal"), terminal, True,
                                   QKeySequence(Qt.Key_F11))
            self.terminal.resize(700, 500)
        self.terminal.exec_()

    def toggleTetris(self):
        self.tetris = Dialog(_("Tetris"), None, True, QKeySequence(Qt.Key_F6))
        _tetris = Tetris(self.tetris)
        self.tetris.addWidget(_tetris)
        self.tetris.resize(240, 500)
        _tetris.start()
        self.tetris.exec_()

    def toggleCursor(self):
        if self.cursor().shape() == QCursor(Qt.ArrowCursor).shape():
            raw = QPixmap(":/gui/pics/pardusman-icon.png")
            raw.setMask(raw.mask())
            self.setCursor(QCursor(raw, 2, 2))
        else:
            self.unsetCursor()

    # show/hide help text
    def slotToggleHelp(self):
        self.ui.helpContentFrame.setFixedHeight(self.ui.helpContent.height())
        if self.ui.helpContentFrame.isVisible():
            self.ui.helpContentFrame.hide()
        else:
            self.ui.helpContentFrame.show()
        widget = self.ui.mainStack.currentWidget()
        widget.update()

    # show/hide debug window
    def toggleDebug(self):
        if ctx.debugger.isVisible():
            ctx.debugger.hideWindow()
        else:
            ctx.debugger.showWindow()

    # returns the id of current stack
    def getCurrent(self, index):
        new_index = self.ui.mainStack.currentIndex() + index
        total_index = self.ui.mainStack.count()
        if new_index < 0: new_index = 0
        if new_index > total_index: new_index = total_index
        return new_index

    # move to id numbered step
    def setCurrent(self, index=None):
        if index:
            self.stackMove(index)

    # execute next step
    def slotNext(self, dry_run=False):
        widget = self.ui.mainStack.currentWidget()
        ret = True
        if not dry_run:
            ret = widget.execute()
        if ret:
            self.pds_helper.hideHelp()
            self.ui.toggleHelp.setChecked(False)
            self.stackMove(self.getCurrent(self.step_increment))
            self.step_increment = 1

    # execute previous step
    def slotBack(self):
        widget = self.ui.mainStack.currentWidget()
        if widget.backCheck():
            self.stackMove(self.getCurrent(self.step_increment * -1))
        self.pds_helper.hideHelp()
        self.ui.toggleHelp.setChecked(False)
        self.step_increment = 1

    # move to id numbered stack
    def stackMove(self, index):
        if not index == self.ui.mainStack.currentIndex() or index == 0:
            self.effect.setOpacity(0.0)
            self.animation_type = "fade-in"
            self.anime.start(50)
            self.ui.mainStack.setCurrentIndex(index)
            widget = self.ui.mainStack.currentWidget()
            # Hack to fix goodbye screen help content
            # BUG:#15860, #15444
            if widget.name == "goodbye":
                widget_id = "%s%s" % (widget.name, ctx.flags.install_type)
            else:
                widget_id = widget.name

            widget_icon = self.screens_content[widget_id][0]

            if self.screens_content[widget_id][1].has_key(ctx.consts.lang):
                widget_title = self.screens_content[widget_id][1][
                    ctx.consts.lang]
            else:
                widget_title = self.screens_content[widget_id][1]["en"]

            if self.screens_content[widget_id][2].has_key(ctx.consts.lang):
                widget_help = self.screens_content[widget_id][2][
                    ctx.consts.lang]
            else:
                widget_help = self.screens_content[widget_id][2]["en"]

            self.ui.screenName.setText(widget_title)
            self.pds_helper.ui.helpContent.setText(widget_help)
            self.pds_helper.setHelp(widget_help)
            self.ui.screenIcon.setPixmap(
                QPixmap(":/gui/pics/%s.png" % (widget_icon)))

            ctx.mainScreen.processEvents()
            widget.update()
            ctx.mainScreen.processEvents()
            widget.shown()

    def animate(self):
        if self.animation_type == "fade-in":
            if self.effect.opacity() < 1.0:
                self.effect.setOpacity(self.effect.opacity() + 0.2)
            else:
                self.anime.stop()
        if self.animation_type == "fade-out":
            if self.effect.opacity() > 0.0:
                self.effect.setOpacity(self.effect.opacity() - 0.2)
            else:
                self.anime.stop()

    def createWidgets(self, screens=[]):
        if not self.screens:
            self.screens = screens
        self.ui.mainStack.removeWidget(self.ui.page)

        for screen in screens:
            #if ctx.flags.debug:
            # debug all screens.
            #    weave_all_object_methods(ctx.aspect, screen)

            # enable navigation buttons before shown
            weave_object_method(enableNavButtonsAspect, screen, "shown")
            # disable navigation buttons before the execute.
            weave_object_method(disableNavButtonsAspect, screen, "execute")
            try:
                self.ui.mainStack.addWidget(screen())
            except Exception, msg:
                rc = ctx.interface.messageWindow(
                    _("Error"),
                    _("An error occurred when attempting "
                      "to load screens:%s") % msg,
                    type="custom",
                    customIcon="error",
                    customButtons=[_("Exit")])
                if not rc:
                    sys.exit(0)

        #weave_all_object_methods(ctx.aspect, self)
        self.stackMove(ctx.flags.startup)
Esempio n. 31
0
 def showGPL(self):
     # make a GPL dialog
     d = Dialog("GPL", Gpl(self), self)
     d.resize(500,400)
     d.exec_()
Esempio n. 32
0
class PartitionEditor:
    def __init__(self, parent, origrequest, isNew=False, partedPartition=None, restricts=None):
        self.storage = parent.storage
        self.intf = parent.intf
        self.origrequest = origrequest
        self.isNew = isNew
        self.parent = parent
        self.partedPartition = partedPartition

        if isNew:
            title = _("Create Partition on %(path)s (%(model)s)") %  {"path":os.path.basename(partedPartition.disk.device.path),
                                                                      "model":partedPartition.disk.device.model}
        else:
            try:
                title = _("Edit Partition %s") % origrequest.path
            except:
                title = _("Edit Partition")

        self.dialog = Dialog(title, closeButton=False)
        self.dialog.addWidget(PartitionWidget(self, origrequest, isNew, restricts))
        self.dialog.resize(QSize(350, 175))

    def run(self):
        if self.dialog is None:
            return []

        while 1:
            rc = self.dialog.exec_()
            operations = []

            if not rc:
                self.destroy()
                return []

            widget = self.dialog.content

            mountpoint = unicode(widget.mountpointMenu.currentText())
            active = widget.mountpointMenu.isEnabled()
            if active and mountpoint:
                msg = sanityCheckMountPoint(mountpoint)
                if msg:
                    ctx.interface.messageWindow(_("Mount Point Error"), msg,
                                                type="warning")
                    continue

                used = False
                for (mp, dev) in self.storage.mountpoints.iteritems():
                    if mp == mountpoint and \
                       dev.id != self.origrequest.id and \
                       not (self.origrequest.format.type == "luks" and
                            self.origrequest in dev.parents):
                        used = True
                        break

                if used:
                    ctx.interface.messageWindow(_("Mount point in use"),
                                                _("The mount point \"%s\" is in "
                                                  "use. Please pick another.") %
                                                (mountpoint,),
                                                type="warning")
                    continue

            if not self.origrequest.exists:
                if widget.primaryCheck.isChecked():
                    primary = True
                else:
                    primary = None

                size = widget.sizeSpin.value()

                formatType = str(widget.filesystemMenu.currentText())
                format = formats.getFormat(formatType, mountpoint=mountpoint)
                if self.isNew:
                    disk = self.storage.devicetree.getDeviceByPath(self.partedPartition.disk.device.path)
                else:
                    disk = self.origrequest.disk

                err = doUIRAIDLVMChecks(format, [disk.name], self.storage)
                if err:
                    self.intf.messageWindow(_("Error With Request"),
                                            err, type="error")
                    continue

                weight = partitioning.weight(mountpoint=mountpoint, fstype=format.type)

                if self.isNew:
                    request = self.storage.newPartition(size=size,
                                                        grow=None,
                                                        maxsize=0,
                                                        primary=primary,
                                                        format=format,
                                                        parents=disk)
                else:
                    request = self.origrequest
                    request.weight = weight

                usedev = request

                if self.isNew:
                    operations.append(OperationCreateDevice(request))
                else:
                    request.req_size = size
                    request.req_base_size = size
                    request.req_grow = None
                    request.req_max_size = 0
                    request.req_primary = primary
                    request.req_disks = [disk]

                operations.append(OperationCreateFormat(usedev, format))

            else:
                # preexisting partition
                request = self.origrequest
                usedev = request

                origformat = usedev.format
                devicetree = self.storage.devicetree

                if widget.formatRadio.isChecked():
                    formatType = str(widget.formatCombo.currentText())
                    format = formats.getFormat(formatType, mountpoint=mountpoint, device=usedev.path)

                    operations.append(OperationCreateFormat(usedev, format))
                else:
                    cancel = []
                    cancel.extend(devicetree.findOperations(type="destroy",
                                                            object="format",
                                                            devid=request.id))
                    cancel.extend(devicetree.findOperations(type="create",
                                                            object="format",
                                                            devid=request.id))
                    cancel.reverse()
                    for operation in cancel:
                        devicetree.removeOperation(operation)

                    request.format = request.originalFormat
                    usedev = request

                    if usedev.format.mountable:
                        usedev.format.mountpoint = mountpoint

                if self.origrequest.protected and usedev.format.mountable:
                    # users can set a mountpoint for protected partitions
                    usedev.format.mountpoint = mountpoint

                request.weight = partitioning.weight(mountpoint=mountpoint, fstype=request.format.type)

                if widget.migrateRadio.isChecked():
                    operations.append(OperationMigrateFormat(usedev))

                if widget.resizeRadio.isChecked():
                    size = widget.resizeSpin.value()
                    try:
                        operations.append(OperationResizeDevice(request, size))
                        if request.format.type and request.format.exists:
                            operations.append(OperationResizeFormat(request, size))
                    except ValueError:
                        pass

                if request.format.exists and \
                   getattr(request, "mountpoint", None) and \
                   self.storage.formatByDefault(request):
                    if not queryNoFormatPreExisting(self.intf):
                        continue

            # everything ok, fall out of loop
            break

        return operations

    def destroy(self):
        if self.dialog:
            self.dialog = None
Esempio n. 33
0
class Widget(QWidget, ScreenWidget):

    help = _('''
<font size="+2">Partitioning your hard disk</font>

<font size="+1">
<p>
Pardus can be installed on a variety of hardware. You can install Pardus
on an empty disk or hard disk partition. <b>An installation will automatically
destroy the previously saved information on selected partitions. </b>
</p>
<p>
In order to use Pardus, you must create one Linux filesystem (for the 
system files), which is mandatory and a swap space 
(for improved performance), which is optional. This swap space 
is used whenever system needs more memory, but the system lacks it.
We advise you to allocate at least 4 GBs of hard disk area and 
swap space (between 500 MB - 2 GB, according to your needs) for 
convenience. A Linux partition size less than 3.5 GB is not allowed.
You may also optionally use another disk partition for storing 
user files.
</p>
<p>
You need to format a Linux partition, if it's used for the first time.
You can enable \'Use available free space\' option, if the hard disk's 
remaining space is to be used automatically.
</p>
<p>
The partition table shows the device, size, partition type and
filesystem information. If the partition will be formatted during
Pardus installation stage, then the corresponding \'Format\' 
column will be enabled.
</p>
<p>
Please refer to Pardus Installing and Using Guide for more information
about disk partitioning.
</p>
</font>
''')


    def __init__(self, *args):
        apply(QWidget.__init__, (self,) + args)

        self.partlist = PartList(self)
        self.partedit = PartEdit(self)
        self.partedit.hide()
        self.dialog = None

        vbox = QVBoxLayout(self)
        vbox.addWidget(self.partlist)

        self.connect(self.partlist, PYSIGNAL("signalCreate"),
                     self.slotCreatePart)

        self.connect(self.partlist, PYSIGNAL("signalDelete"),
                     self.slotDeletePart)

        self.connect(self.partlist, PYSIGNAL("signalEdit"),
                     self.slotEditPart)

        self.connect(self.partlist, PYSIGNAL("signalResize"),
                     self.slotResizePart)

        self.connect(self.partedit, PYSIGNAL("signalApplied"),
                     self.slotApplied)

        self.connect(self.partedit, PYSIGNAL("signalCanceled"),
                     self.slotCanceled)


    def shown(self):
        from os.path import basename
        ctx.debugger.log("%s loaded" % basename(__file__))
        ctx.screens.disableNext()
        self.partlist.update()

    ##
    # do the work and run requested actions on partitions.
    def execute(self):
        ctx.debugger.log("Manual Partitioning selected...")
        ctx.screens.processEvents()
        return True

    def slotCreatePart(self, parent, d):
        self.partedit.setState(createState, d)
        self.dialog = Dialog(_("Create Partition"), self.partedit, self)
        self.dialog.exec_loop()

    def slotDeletePart(self, parent, d):
        self.partedit.setState(deleteState, d)
        self.dialog = Dialog(_("Delete Partition"), self.partedit, self)
        self.dialog.exec_loop()

    def slotEditPart(self, parent, d):
        self.partedit.setState(editState, d)
        self.dialog = Dialog(_("Edit Partition"), self.partedit, self)
        self.dialog.exec_loop()

    def slotResizePart(self, parent, d):
        self.partedit.setState(resizeState, d)
        self.dialog = Dialog(_("Resize Partition"), self.partedit, self)
        self.dialog.exec_loop()

    def slotApplied(self):
        self.dialog.done(0)
        self.partlist.update()

    def slotCanceled(self):
        self.dialog.reject()
Esempio n. 34
0
class Widget(QWidget, ScreenWidget):

    help = _(
        """
<font size="+2">Partitioning your hard disk</font>

<font size="+1">
<p>
Pardus can be installed on a variety of hardware. You can install Pardus
on an empty disk or hard disk partition. <b>An installation will automatically
destroy the previously saved information on selected partitions. </b>
</p>
<p>
In order to use Pardus, you must create one Linux filesystem (for the 
system files), which is mandatory and a swap space 
(for improved performance), which is optional. This swap space 
is used whenever system needs more memory, but the system lacks it.
We advise you to allocate at least 4 GBs of hard disk area and 
swap space (between 500 MB - 2 GB, according to your needs) for 
convenience. A Linux partition size less than 3.5 GB is not allowed.
You may also optionally use another disk partition for storing 
user files.
</p>
<p>
You need to format a Linux partition, if it's used for the first time.
You can enable \'Use available free space\' option, if the hard disk's 
remaining space is to be used automatically.
</p>
<p>
The partition table shows the device, size, partition type and
filesystem information. If the partition will be formatted during
Pardus installation stage, then the corresponding \'Format\' 
column will be enabled.
</p>
<p>
Please refer to Pardus Installing and Using Guide for more information
about disk partitioning.
</p>
</font>
"""
    )

    def __init__(self, *args):
        apply(QWidget.__init__, (self,) + args)

        self.partlist = PartList(self)
        self.partedit = PartEdit(self)
        self.partedit.hide()
        self.dialog = None

        vbox = QVBoxLayout(self)
        vbox.addWidget(self.partlist)

        self.connect(self.partlist, PYSIGNAL("signalCreate"), self.slotCreatePart)

        self.connect(self.partlist, PYSIGNAL("signalDelete"), self.slotDeletePart)

        self.connect(self.partlist, PYSIGNAL("signalEdit"), self.slotEditPart)

        self.connect(self.partlist, PYSIGNAL("signalResize"), self.slotResizePart)

        self.connect(self.partedit, PYSIGNAL("signalApplied"), self.slotApplied)

        self.connect(self.partedit, PYSIGNAL("signalCanceled"), self.slotCanceled)

    def shown(self):
        from os.path import basename

        ctx.debugger.log("%s loaded" % basename(__file__))
        ctx.screens.disableNext()

        self.partlist.update()

    ##
    # do the work and run requested actions on partitions.
    def execute(self):

        # show confirmation dialog
        w = WarningWidget(self)
        self.dialog = WarningDialog(w, self)
        if not self.dialog.exec_loop():
            # disabled by weaver.
            ctx.screens.enablePrev()

            self.partlist.update()
            return False

        # show information window...
        info_window = InformationWindow(self, _("Please wait while formatting!"))

        # commit events
        self.partlist.devices_commit()

        # inform user...
        self.partlist.showPartitionRequests(formatting=True)
        # process events and show partitioning information!
        ctx.screens.processEvents()

        ##
        # check swap partition, if not present use swap file
        rt = request.mountRequestType
        pt = parttype.swap
        swap_part_req = ctx.partrequests.searchPartTypeAndReqType(pt, rt)

        if not swap_part_req:
            # No swap partition defined using swap as file in root
            # partition
            rt = request.mountRequestType
            pt = parttype.root
            root_part_req = ctx.partrequests.searchPartTypeAndReqType(pt, rt)
            ctx.partrequests.append(request.SwapFileRequest(root_part_req.partition(), root_part_req.partitionType()))

        # apply all partition requests
        ctx.partrequests.applyAll()

        # close window
        info_window.close(True)
        return True

    def slotCreatePart(self, parent, d):
        self.partedit.setState(createState, d)
        self.dialog = Dialog(_("Create Partition"), self.partedit, self)
        self.dialog.exec_loop()

    def slotDeletePart(self, parent, d):
        self.partedit.setState(deleteState, d)
        self.dialog = Dialog(_("Delete Partition"), self.partedit, self)
        self.dialog.exec_loop()

    def slotEditPart(self, parent, d):
        self.partedit.setState(editState, d)
        self.dialog = Dialog(_("Edit Partition"), self.partedit, self)
        self.dialog.exec_loop()

    def slotResizePart(self, parent, d):
        self.partedit.setState(resizeState, d)
        self.dialog = Dialog(_("Resize Partition"), self.partedit, self)
        self.dialog.exec_loop()

    def slotApplied(self):
        self.dialog.done(0)
        self.partlist.update()

    def slotCanceled(self):
        self.dialog.reject()
Esempio n. 35
0
 def slotDeletePart(self, parent, d):
     self.partedit.setState(deleteState, d)
     self.dialog = Dialog(_("Delete Partition"), self.partedit, self)
     self.dialog.exec_loop()
Esempio n. 36
0
class LogicalVolumeEditor:
    def __init__(self, parent, request, isNew=False):
        self.parent = parent
        self.storage = parent.parent.storage
        self.intf = parent.parent.intf
        self.origrequest = request
        self.isNew = isNew

        if isNew:
            title = _("Make Logical Volume")
        else:
            title = _("Edit Logical Volume: %s") % request.lvname

        self.dialog = Dialog(title, closeButton=False)
        self.dialog.addWidget(LogicalVolumeWidget(self, request, isNew))
        self.dialog.resize(QSize(0, 0))

    def run(self):
        if self.dialog is None:
            return None

        while 1:
            rc = self.dialog.exec_()

            if not rc:
                if self.isNew:
                    if self.parent.parent.lvs.has_key(self.origrequest.lvname):
                        del self.parent.parent.lvs[self.origrequest.lvname]
                self.destroy()
                return None

            format = None
            widget = self.dialog.content

            format = self.origrequest.format

            mountpoint = unicode(widget.mountpointMenu.currentText())
            if mountpoint and widget.mountpointMenu.isEditable():
                msg = sanityCheckMountPoint(mountpoint)
                if msg:
                    self.intf.messageWindow(_("Mount Point Error"), msg,
                                            type="error")
                    continue

            if not self.origrequest.exists:
                format_type = str(widget.filesystemMenu.currentText())
            else:
                format_type = str(widget.formatCombo.currentText())

            format_class = formats.getFormat(format_type)
            if mountpoint and format_class.mountable:
                used = False

                current_mountpoint = getattr(format, "mountpoint", None)

                for lv in self.parent.parent.lvs.values():
                    format = lv["format"]
                    if not format.mountable or current_mountpoint and \
                        format.mountpoint == current_mountpoint:
                        continue

                    if format.mountpoint == mountpoint:
                        used = True
                        break

                for (mp, dev) in self.parent.parent.storage.mountpoints.iteritems():
                    if (dev.type != "lvmlv" or dev.vg.id != self.origrequest.vg.id) and mp == mountpoint:
                        used = True
                        break

                if used:
                    self.intf.messageWindow(_("Mount point in use"),
                                            _("The mount point \"%s\" is in "
                                              "use. Please pick another.") %
                                            (mountpoint,),
                                            type="warning")
                    continue


            name = str(widget.name.text())
            if not self.origrequest.exists:
                msg = sanityCheckLogicalVolumeName(name)
                if msg:
                    self.intf.messageWindow(_("Illegal Logical Volume Name"),
                                            msg, type="warning")
                    continue

            # check that the name is not already in use
            used = 0
            for lv in self.parent.parent.lvs.values():
                if self.origrequest.lvname != name and lv['name'] == name:
                    used = 1
                    break

            if used:
                self.intf.messageWindow(_("Illegal logical volume name"),
                                        _("The logical volume name \"%s\" is "
                                          "already in use. Please pick another.")
                                        % (name,), type="warning")
                continue


            if not self.origrequest.exists:
                badsize = 0
                try:
                    size = long(widget.sizeSpin.value())
                except:
                    size = 1

                if badsize or size <= 0:
                    self.intf.messageWindow(_("Illegal size"),
                                            _("The requested size as entered is "
                                              "not a valid number greater than 0."),
                                            type="warning")
                    continue
            else:
                size = self.origrequest.size

            # check that size specification is within limits
            peSize = int(self.parent.physicalExtends.itemData(self.parent.physicalExtends.currentIndex())) / 1024
            size = lvm.clampSize(size, peSize, roundup=True)
            maximumVolumeSize = lvm.getMaxLVSize()
            if size > maximumVolumeSize:
                self.intf.messageWindow(_("Not enough space"),
                                        _("The current requested size "
                                          "(%(size)10.2f MB) is larger than "
                                          "the maximum logical volume size "
                                          "(%(maxlv)10.2f MB). "
                                          "To increase this limit you can "
                                          "create more Physical Volumes from "
                                          "unpartitioned disk space and "
                                          "add them to this Volume Group.")
                                          % {'size': size, 'maxlv': maximumVolumeSize},
                                        type="warning")
                continue

            # Get format
            origname = self.origrequest.lvname
            if not self.origrequest.exists:
                formatType = str(widget.filesystemMenu.currentText())
                format = formats.getFormat(formatType, mountpoint=mountpoint)
                self.origrequest._name = name
                try:
                    self.origrequest.size = size
                except ValueError, msg:
                    self.intf.messageWindow(_("Not enough space"),
                                            _("The size entered for this "
                                              "logical volume (%(size)d MB) "
                                              "combined with the size of the "
                                              "other logical volume(s) "
                                              "exceeds the size of the "
                                              "volume group (%(tmpvgsize)d "
                                              "MB). Please make the volume "
                                              "group larger or make the "
                                              "logical volume smaller.")
                                              % {'size': size, 'tmpvgsize': self.origrequest.vg.size},
                                            type="warning")
                    continue
                else:
                    self.origrequest.format = format
            else:
                if widget.formatRadio.isChecked():
                    formatType = str(widget.formatCombo.currentText())
                    format = formats.getFormat(formatType, mountpoint=mountpoint, device=self.origrequest.path)
                    self.origrequest.format = format
                else:
                    self.origrequest.format = self.origrequest.originalFormat

                if widget.migrateRadio.isChecked():
                    self.origrequest.format.migrate = True

                if widget.resizeRadio.isChecked():
                    self.origrequest.targetSize = widget.resizeSpin.value()

                if self.origrequest.format.mountable:
                    self.origrequest.format.mountpoint = mountpoint

                if self.origrequest.format.exists and \
                    self.origrequest.format.mountable and \
                    self.origrequest.format.mountpoint:
                    if self.storage.formatByDefault(self.origrequest) and \
                       not queryNoFormatPreExisting(self.intf):
                        continue

            # everything ok
            break

        if self.parent.parent.lvs.has_key(origname) and origname != self.origrequest.lvname:
            del self.parent.parent.lvs[origname]

        return {'name': self.origrequest.lvname,
                'size': self.origrequest.size,
                'format': self.origrequest.format,
                'originalFormat': self.origrequest.originalFormat,
                'stripes': self.origrequest.stripes,
                'logSize': self.origrequest.logSize,
                'snapshotSpace': self.origrequest.snapshotSpace,
                'exists': self.origrequest.exists}
Esempio n. 37
0
class RaidEditor(object):
    def __init__(self, parent, request, isNew=False):
        self.parent = parent
        self.storage = parent.storage
        self.intf = parent.intf
        self.origrequest = request
        self.isNew = isNew

        availraidparts = self.parent.storage.unusedRaidMembers(
            array=self.origrequest)
        if availraidparts < 2:
            self.intf.messageWindow(_("Invalid Raid Members"),
                                    _("At least two unused software RAID "
                                      "partitions are needed to create "
                                      "a RAID device.\n\n"
                                      "First create at least two partitions "
                                      "of type \"software RAID\", and then "
                                      "select the \"RAID\" option again."),
                                    type="error")
            return

        if isNew:
            title = _("Make RAID Device")
        else:
            if request.minor is not None:
                title = _("Edit RAID Device: %s") % request.path
            else:
                title = _("Edit RAID Device")

        self.dialog = Dialog(title, closeButton=False)
        self.dialog.addWidget(RaidWidget(self, request, isNew))
        self.dialog.resize(QSize(450, 200))

    def run(self):
        if self.dialog is None:
            return []

        while 1:
            rc = self.dialog.exec_()
            operations = []
            raidmembers = []

            if not rc:
                self.destroy()
                return []

            widget = self.dialog.content

            mountpoint = unicode(widget.mountpointMenu.currentText())
            active = widget.mountpointMenu.isEnabled()
            if active and mountpoint:
                msg = sanityCheckMountPoint(mountpoint)
                if msg:
                    self.intf.messageWindow(_("Mount Point Error"),
                                            msg,
                                            type="error")
                    continue

                used = False
                for (mp, dev) in self.storage.mountpoints.iteritems():
                    if mp == mountpoint and \
                       dev.id != self.origrequest.id and \
                       not (self.origrequest.format.type == "luks" and
                            self.origrequest in dev.parents):
                        used = True
                        break

                if used:
                    self.intf.messageWindow(_("Mount point in use"),
                                            _("The mount point \"%s\" is in "
                                              "use. Please pick another.") %
                                            (mountpoint, ),
                                            type="warning")
                    continue

            for index in range(widget.raidMembers.count()):
                if widget.raidMembers.item(index).checkState() == Qt.Checked:
                    raidmembers.append(
                        widget.raidMembers.item(index).partition)

            # The user has to select some devices to be part of the array.
            if not raidmembers:
                raidlevel = int(
                    widget.raidLevels.itemData(
                        widget.raidLevels.currentIndex()))
                self.intf.messageWindow(
                    _("Invalid Raid Members"),
                    _("A RAID%(level)d set requires at least %(min_member)d member"
                      ) % {
                          "level": raidlevel,
                          "min_member": raid.get_raid_min_members(raidlevel)
                      },
                    type="warning")
                continue

            if not self.origrequest.exists:
                formatType = str(widget.filesystemMenu.currentText())
                raidminor = int(
                    widget.raidMinors.itemData(
                        widget.raidMinors.currentIndex()))
                raidlevel = int(
                    widget.raidLevels.itemData(
                        widget.raidLevels.currentIndex()))

                if not raid.isRaid(raid.RAID0, raidlevel):
                    spares = widget.spareSpin.value()
                else:
                    spares = 0

                format = formats.getFormat(formatType, mountpoint=mountpoint)
                members = len(raidmembers) - spares

                try:
                    request = self.storage.newRaidArray(
                        minor=raidminor,
                        level=raidlevel,
                        format=format,
                        parents=raidmembers,
                        totalDevices=len(raidmembers),
                        memberDevices=members)
                except ValueError, msg:
                    self.intf.messageWindow(_("Invalid Raid Members"),
                                            unicode(msg),
                                            type="warning")
                    continue

                if not self.isNew:
                    # This may be handled in devicetree.registerAction,
                    # but not in case when we change minor and thus
                    # device name/path (at least with current md)
                    operations.append(OperationDestroyDevice(self.origrequest))

                operations.append(OperationCreateDevice(request))
                operations.append(OperationCreateFormat(request))

            else:
                format = None
                if widget.formatRadio.isChecked():
                    formatType = str(widget.formatCombo.currentText())
                    format = formats.getFormat(formatType,
                                               mountpoint=mountpoint,
                                               device=self.origrequest.path)
                    operations.append(
                        OperationCreateFormat(self.origrequest, format))
                else:
                    cancel = []
                    cancel.extend(
                        self.storage.devicetree.findOperations(
                            type="destroy",
                            object="format",
                            devid=self.origrequest.id))
                    cancel.extend(
                        self.storage.devicetree.findOperations(
                            type="create",
                            object="format",
                            devid=self.origrequest.id))
                    for operation in cancel:
                        self.storage.devicetree.removeOperation(operation)

                    self.origrequest.format = self.origrequest.originalFormat

                if self.origrequest.format.mountable:
                    self.origrequest.format.mountpoint = mountpoint

                if widget.migrateRadio.isChecked():
                    operations.append(OperationMigrateFormat(self.origrequest))

                if self.origrequest.format.exists and not format and \
                   self.storage.formatByDefault(self.origrequest):
                    if not queryNoFormatPreExisting(self.intf):
                        continue

            # everything ok, fall out of loop
            break

        return operations
Esempio n. 38
0
 def showGPL(self):
     dialog = Dialog("GPL", LicenseBrowser(self), self)
     dialog.resize(500, 400)
     dialog.exec_()
Esempio n. 39
0
class LVMEditor(object):
    def __init__(self, parent, request, isNew=False):
        self.parent = parent
        self.storage = parent.storage
        self.origrequest = request
        self.peSize = request.peSize
        self.pvs = request.pvs[:]
        self.isNew = isNew
        self.intf = parent.intf
        self.operations = []
        self.dialog = None
        self.lvs = {}

        for lv in self.origrequest.lvs:
            self.lvs[lv.lvname] = {"name": lv.lvname,
                                   "size": lv.size,
                                   "format": copy.copy(lv.format),
                                   "originalFormat": lv.originalFormat,
                                   "stripes": lv.stripes,
                                   "logSize": lv.logSize,
                                   "snapshotSpace": lv.snapshotSpace,
                                   "exists": lv.exists}

        self.availlvmparts = self.storage.unusedPVS(vg=request)
        # if no PV exist, raise an error message and return
        if len(self.availlvmparts) < 1:
            self.intf.messageWindow(_("Not enough physical volumes"),
                                    _("At least one unused physical "
                                      "volume partition is "
                                      "needed to\ncreate an LVM Volume Group.\n"
                                      "Create a partition or RAID array "
                                      "of type \"physical volume\n(LVM)\" and then "
                                      "select the \"LVM\" option again."),
                                    type="warning")
            self.dialog = None
            return

        if isNew:
            title = _("Make LVM Volume Group")
        else:
            try:
                title = _("Edit LVM Volume Group: %s") % (request.name,)
            except AttributeError:
                title = _("Edit LVM Volume Group")

        self.dialog = Dialog(title, closeButton=False)
        self.dialog.addWidget(VolumeGroupWidget(self, self.origrequest, isNew=isNew))
        self.dialog.resize(QSize(450, 200))

    def run(self):
        if self.dialog is None:
            return []

        while 1:
            rc = self.dialog.exec_()
            operations = []
            if not rc:
                if self.isNew:
                    if self.lvs.has_key(self.origrequest.name):
                        del self.lvs[self.origrequest.name]
                self.destroy()
                return []

            widget = self.dialog.content

            name =  str(widget.name.text())
            pvs = widget.selectedPhysicalVolumes
            msg = sanityCheckVolumeGroupName(name)
            if msg:
                self.intf.messageWindow(_("Invalid Volume Group Name"),
                                        msg, type="warning")
                continue

            origname = self.origrequest.name
            if origname != name:
                if name in [vg.name for vg in self.storage.vgs]:
                    self.intf.messageWindow(_("Name in use"),
                                            _("The volume group name \"%s\" is "
                                              "already in use. Please pick another.")
                                              % (name,), type="warning")
                    continue

            peSize = widget.physicalExtends.itemData(widget.physicalExtends.currentIndex()).toInt()[0] / 1024.0

            origlvs = self.origrequest.lvs
            if not self.origrequest.exists:
                ctx.logger.debug("non-existing vg -- setting up lvs, pvs, name, peSize")
                for lv in self.origrequest.lvs:
                    self.origrequest._removeLogicalVolume(lv)

                for pv in self.origrequest.pvs:
                    if pv not in self.pvs:
                        self.origrequest._removePhysicalVolume(pv)

                for pv in self.pvs:
                    if pv not in self.origrequest.pvs:
                        self.origrequest._addPhysicalVolume(pv)

                self.origrequest.name = name
                self.origrequest.peSize = peSize

                if self.isNew:
                    operations = [OperationCreateDevice(self.origrequest)]

            for lv in origlvs:
                ctx.logger.debug("old lv %s..." % lv.lvname)
                if not lv.exists or lv.lvname not in self.lvs or \
                   (not self.lvs[lv.lvname]['exists'] and lv.exists):
                    ctx.logger.debug("removing lv %s" % lv.lvname)
                    if lv.format.type:
                        operations.append(OperationDestroyFormat(lv))

                    if lv in self.origrequest.lvs:
                        self.origrequest._removeLogicalVolume(lv)

                    operations.append(OperationDestroyDevice(lv))

            # schedule creation of all new lvs, their formats, luks devices, &c
            tempvg = widget.tmpVolumeGroup
            for lv in tempvg.lvs:
                ctx.logger.debug("new lv %s" % lv)
                if not lv.exists:
                    ctx.logger.debug("creating lv %s" % lv.lvname)
                    logicalvolume = LogicalVolume(lv.lvname, self.origrequest, size=lv.size)
                    operations.append(OperationCreateDevice(logicalvolume))

                    # create the format
                    mountpoint = getattr(lv.format, "mountpoint", None)
                    format = formats.getFormat(lv.format.type,
                                               mountpoint=mountpoint,
                                               device=logicalvolume.path)
                    operations.append(OperationCreateFormat(logicalvolume, format))
                else:
                    ctx.logger.debug("lv %s already exists" % lv.lvname)
                    origlv = widget.getLogicalVolumeByName(lv.lvname)
                    if lv.resizable and lv.targetSize != origlv.size:
                        operations.append(OperationResizeDevice(origlv, lv.targetSize))

                    if lv.format.exists:
                        ctx.logger.debug("format already exists")
                        usedev = origlv
                        format = lv.format
                        if format == usedev.originalFormat:
                            cancel = []
                            cancel.extend(self.parent.storage.devicetree.findOperations(type="create",
                                                                                        object="format",
                                                                                        devid=origlv.id))
                            cancel.extend(self.parent.storage.devicetree.findOperations(type="destroy",
                                                                                        object="format",
                                                                                        devid=origlv.id))
                            for operation in cancel:
                                self.storage.devicetree.cancelOperation(operation)

                        if hasattr(format, "mountpoint"):
                            usedev.format.mountpoint = format.mountpoint

                        if format.migratable and format.migrate and \
                           not usedev.format.migrate:
                            usedev.format.migrate = format.migrate
                            operations.append(OperationMigrateFormat(usedev))

                        if format.resizable and lv.format.resizable and \
                                lv.targetSize != format.targetSize and \
                                lv.targetSize != lv.currentSize and \
                                usedev.format.exists:
                            ctx.logger.debug("resizing format on %s to %d" % (usedev.lvname, lv.targetSize))
                            operations.append(OperationResizeFormat(usedev, lv.targetSize))
                    elif lv.format.type:
                        ctx.logger.debug("new format: %s" % lv.format.type)
                        if origlv.format.type:
                            operations.append(OperationDestroyFormat(origlv))

                        mountpoint = getattr(lv.format, "mountpoint", None)
                        format = formats.getFormat(lv.format.type,
                                                   mountpoint=mountpoint,
                                                   device=origlv.path)
                        operations.append(OperationCreateFormat(origlv, format))
                    else:
                        ctx.logger.debug("no format!")
            break

        return operations

    def destroy(self):
        if self.dialog:
            self.dialog = None
Esempio n. 40
0
class LVMEditor(object):
    def __init__(self, parent, request, isNew=False):
        self.parent = parent
        self.storage = parent.storage
        self.origrequest = request
        self.peSize = request.peSize
        self.pvs = request.pvs[:]
        self.isNew = isNew
        self.intf = parent.intf
        self.operations = []
        self.dialog = None
        self.lvs = {}

        for lv in self.origrequest.lvs:
            self.lvs[lv.lvname] = {"name": lv.lvname,
                                   "size": lv.size,
                                   "format": copy.copy(lv.format),
                                   "originalFormat": lv.originalFormat,
                                   "stripes": lv.stripes,
                                   "logSize": lv.logSize,
                                   "snapshotSpace": lv.snapshotSpace,
                                   "exists": lv.exists}

        self.availlvmparts = self.storage.unusedPVS(vg=request)
        # if no PV exist, raise an error message and return
        if len(self.availlvmparts) < 1:
            self.intf.messageWindow(_("Not enough physical volumes"),
                                    _("At least one unused physical "
                                      "volume partition is "
                                      "needed to\ncreate an LVM Volume Group.\n"
                                      "Create a partition or RAID array "
                                      "of type \"physical volume\n(LVM)\" and then "
                                      "select the \"LVM\" option again."),
                                    type="warning")
            self.dialog = None
            return

        if isNew:
            title = _("Make LVM Volume Group")
        else:
            try:
                title = _("Edit LVM Volume Group: %s") % (request.name,)
            except AttributeError:
                title = _("Edit LVM Volume Group")

        self.dialog = Dialog(title, closeButton=False)
        self.dialog.addWidget(VolumeGroupWidget(self, self.origrequest, isNew=isNew))
        self.dialog.resize(QSize(450, 200))

    def run(self):
        if self.dialog is None:
            return []

        while 1:
            rc = self.dialog.exec_()
            operations = []
            if not rc:
                if self.isNew:
                    if self.lvs.has_key(self.origrequest.name):
                        del self.lvs[self.origrequest.name]
                self.destroy()
                return []

            widget = self.dialog.content

            name =  str(widget.name.text())
            pvs = widget.selectedPhysicalVolumes
            msg = sanityCheckVolumeGroupName(name)
            if msg:
                self.intf.messageWindow(_("Invalid Volume Group Name"),
                                        msg, type="warning")
                continue

            origname = self.origrequest.name
            if origname != name:
                if name in [vg.name for vg in self.storage.vgs]:
                    self.intf.messageWindow(_("Name in use"),
                                            _("The volume group name \"%s\" is "
                                              "already in use. Please pick another.")
                                              % (name,), type="warning")
                    continue

            peSize = int(widget.physicalExtends.itemData(widget.physicalExtends.currentIndex())) / 1024.0
            
            origlvs = self.origrequest.lvs
            if not self.origrequest.exists:
                ctx.logger.debug("non-existing vg -- setting up lvs, pvs, name, peSize")
                for lv in self.origrequest.lvs:
                    self.origrequest._removeLogicalVolume(lv)

                for pv in self.origrequest.pvs:
                    if pv not in self.pvs:
                        self.origrequest._removePhysicalVolume(pv)

                for pv in self.pvs:
                    if pv not in self.origrequest.pvs:
                        self.origrequest._addPhysicalVolume(pv)

                self.origrequest.name = name
                self.origrequest.peSize = peSize

                if self.isNew:
                    operations = [OperationCreateDevice(self.origrequest)]

            for lv in origlvs:
                ctx.logger.debug("old lv %s..." % lv.lvname)
                if not lv.exists or lv.lvname not in self.lvs or \
                   (not self.lvs[lv.lvname]['exists'] and lv.exists):
                    ctx.logger.debug("removing lv %s" % lv.lvname)
                    if lv.format.type:
                        operations.append(OperationDestroyFormat(lv))

                    if lv in self.origrequest.lvs:
                        self.origrequest._removeLogicalVolume(lv)

                    operations.append(OperationDestroyDevice(lv))

            # schedule creation of all new lvs, their formats, luks devices, &c
            tempvg = widget.tmpVolumeGroup
            for lv in tempvg.lvs:
                ctx.logger.debug("new lv %s" % lv)
                if not lv.exists:
                    ctx.logger.debug("creating lv %s" % lv.lvname)
                    logicalvolume = LogicalVolume(lv.lvname, self.origrequest, size=lv.size)
                    operations.append(OperationCreateDevice(logicalvolume))

                    # create the format
                    mountpoint = getattr(lv.format, "mountpoint", None)
                    format = formats.getFormat(lv.format.type,
                                               mountpoint=mountpoint,
                                               device=logicalvolume.path)
                    operations.append(OperationCreateFormat(logicalvolume, format))
                else:
                    ctx.logger.debug("lv %s already exists" % lv.lvname)
                    origlv = widget.getLogicalVolumeByName(lv.lvname)
                    if lv.resizable and lv.targetSize != origlv.size:
                        operations.append(OperationResizeDevice(origlv, lv.targetSize))

                    if lv.format.exists:
                        ctx.logger.debug("format already exists")
                        usedev = origlv
                        format = lv.format
                        if format == usedev.originalFormat:
                            cancel = []
                            cancel.extend(self.parent.storage.devicetree.findOperations(type="create",
                                                                                        object="format",
                                                                                        devid=origlv.id))
                            cancel.extend(self.parent.storage.devicetree.findOperations(type="destroy",
                                                                                        object="format",
                                                                                        devid=origlv.id))
                            for operation in cancel:
                                self.storage.devicetree.cancelOperation(operation)

                        if hasattr(format, "mountpoint"):
                            usedev.format.mountpoint = format.mountpoint

                        if format.migratable and format.migrate and \
                           not usedev.format.migrate:
                            usedev.format.migrate = format.migrate
                            operations.append(OperationMigrateFormat(usedev))

                        if format.resizable and lv.format.resizable and \
                                lv.targetSize != format.targetSize and \
                                lv.targetSize != lv.currentSize and \
                                usedev.format.exists:
                            ctx.logger.debug("resizing format on %s to %d" % (usedev.lvname, lv.targetSize))
                            operations.append(OperationResizeFormat(usedev, lv.targetSize))
                    elif lv.format.type:
                        ctx.logger.debug("new format: %s" % lv.format.type)
                        if origlv.format.type:
                            operations.append(OperationDestroyFormat(origlv))

                        mountpoint = getattr(lv.format, "mountpoint", None)
                        format = formats.getFormat(lv.format.type,
                                                   mountpoint=mountpoint,
                                                   device=origlv.path)
                        operations.append(OperationCreateFormat(origlv, format))
                    else:
                        ctx.logger.debug("no format!")
            break

        return operations

    def destroy(self):
        if self.dialog:
            self.dialog = None
Esempio n. 41
0
 def showGPL(self):
     # make a release notes dialog
     r = GUIGPL.Widget(self)
     d = Dialog("GPL", r, self)
     d.resize(500,400)
     d.exec_loop()
Esempio n. 42
0
 def slotEditPart(self, parent, d):
     self.partedit.setState(editState, d)
     self.dialog = Dialog(_("Edit Partition"), self.partedit, self)
     self.dialog.exec_loop()
Esempio n. 43
0
class LogicalVolumeEditor:
    def __init__(self, parent, request, isNew=False):
        self.parent = parent
        self.storage = parent.parent.storage
        self.intf = parent.parent.intf
        self.origrequest = request
        self.isNew = isNew

        if isNew:
            title = _("Make Logical Volume")
        else:
            title = _("Edit Logical Volume: %s") % request.lvname

        self.dialog = Dialog(title, closeButton=False)
        self.dialog.addWidget(LogicalVolumeWidget(self, request, isNew))
        self.dialog.resize(QSize(0, 0))

    def run(self):
        if self.dialog is None:
            return None

        while 1:
            rc = self.dialog.exec_()

            if not rc:
                if self.isNew:
                    if self.parent.parent.lvs.has_key(self.origrequest.lvname):
                        del self.parent.parent.lvs[self.origrequest.lvname]
                self.destroy()
                return None

            format = None
            widget = self.dialog.content

            format = self.origrequest.format

            mountpoint = unicode(widget.mountpointMenu.currentText())
            if mountpoint and widget.mountpointMenu.isEditable():
                msg = sanityCheckMountPoint(mountpoint)
                if msg:
                    self.intf.messageWindow(_("Mount Point Error"), msg,
                                            type="error")
                    continue

            if not self.origrequest.exists:
                format_type = str(widget.filesystemMenu.currentText())
            else:
                format_type = str(widget.formatCombo.currentText())

            format_class = formats.getFormat(format_type)
            if mountpoint and format_class.mountable:
                used = False

                current_mountpoint = getattr(format, "mountpoint", None)

                for lv in self.parent.parent.lvs.values():
                    format = lv["format"]
                    if not format.mountable or current_mountpoint and \
                        format.mountpoint == current_mountpoint:
                        continue

                    if format.mountpoint == mountpoint:
                        used = True
                        break

                for (mp, dev) in self.parent.parent.storage.mountpoints.iteritems():
                    if (dev.type != "lvmlv" or dev.vg.id != self.origrequest.vg.id) and mp == mountpoint:
                        used = True
                        break

                if used:
                    self.intf.messageWindow(_("Mount point in use"),
                                            _("The mount point \"%s\" is in "
                                              "use. Please pick another.") %
                                            (mountpoint,),
                                            type="warning")
                    continue


            name = str(widget.name.text())
            if not self.origrequest.exists:
                msg = sanityCheckLogicalVolumeName(name)
                if msg:
                    self.intf.messageWindow(_("Illegal Logical Volume Name"),
                                            msg, type="warning")
                    continue

            # check that the name is not already in use
            used = 0
            for lv in self.parent.parent.lvs.values():
                if self.origrequest.lvname != name and lv['name'] == name:
                    used = 1
                    break

            if used:
                self.intf.messageWindow(_("Illegal logical volume name"),
                                        _("The logical volume name \"%s\" is "
                                          "already in use. Please pick another.")
                                        % (name,), type="warning")
                continue


            if not self.origrequest.exists:
                badsize = 0
                try:
                    size = long(widget.sizeSpin.value())
                except:
                    size = 1

                if badsize or size <= 0:
                    self.intf.messageWindow(_("Illegal size"),
                                            _("The requested size as entered is "
                                              "not a valid number greater than 0."),
                                            type="warning")
                    continue
            else:
                size = self.origrequest.size

            # check that size specification is within limits
            peSize = self.parent.physicalExtends.itemData(self.parent.physicalExtends.currentIndex()).toInt()[0] / 1024
            size = lvm.clampSize(size, peSize, roundup=True)
            maximumVolumeSize = lvm.getMaxLVSize()
            if size > maximumVolumeSize:
                self.intf.messageWindow(_("Not enough space"),
                                        _("The current requested size "
                                          "(%(size)10.2f MB) is larger than "
                                          "the maximum logical volume size "
                                          "(%(maxlv)10.2f MB). "
                                          "To increase this limit you can "
                                          "create more Physical Volumes from "
                                          "unpartitioned disk space and "
                                          "add them to this Volume Group.")
                                          % {'size': size, 'maxlv': maximumVolumeSize},
                                        type="warning")
                continue

            # Get format
            origname = self.origrequest.lvname
            if not self.origrequest.exists:
                formatType = str(widget.filesystemMenu.currentText())
                format = formats.getFormat(formatType, mountpoint=mountpoint)
                self.origrequest._name = name
                try:
                    self.origrequest.size = size
                except ValueError, msg:
                    self.intf.messageWindow(_("Not enough space"),
                                            _("The size entered for this "
                                              "logical volume (%(size)d MB) "
                                              "combined with the size of the "
                                              "other logical volume(s) "
                                              "exceeds the size of the "
                                              "volume group (%(tmpvgsize)d "
                                              "MB). Please make the volume "
                                              "group larger or make the "
                                              "logical volume smaller.")
                                              % {'size': size, 'tmpvgsize': self.origrequest.vg.size},
                                            type="warning")
                    continue
                else:
                    self.origrequest.format = format
            else:
                if widget.formatRadio.isChecked():
                    formatType = str(widget.formatCombo.currentText())
                    format = formats.getFormat(formatType, mountpoint=mountpoint, device=self.origrequest.path)
                    self.origrequest.format = format
                else:
                    self.origrequest.format = self.origrequest.originalFormat

                if widget.migrateRadio.isChecked():
                    self.origrequest.format.migrate = True

                if widget.resizeRadio.isChecked():
                    self.origrequest.targetSize = widget.resizeSpin.value()

                if self.origrequest.format.mountable:
                    self.origrequest.format.mountpoint = mountpoint

                if self.origrequest.format.exists and \
                    self.origrequest.format.mountable and \
                    self.origrequest.format.mountpoint:
                    if self.storage.formatByDefault(self.origrequest) and \
                       not queryNoFormatPreExisting(self.intf):
                        continue

            # everything ok
            break

        if self.parent.parent.lvs.has_key(origname) and origname != self.origrequest.lvname:
            del self.parent.parent.lvs[origname]

        return {'name': self.origrequest.lvname,
                'size': self.origrequest.size,
                'format': self.origrequest.format,
                'originalFormat': self.origrequest.originalFormat,
                'stripes': self.origrequest.stripes,
                'logSize': self.origrequest.logSize,
                'snapshotSpace': self.origrequest.snapshotSpace,
                'exists': self.origrequest.exists}
Esempio n. 44
0
class Widget(QWidget, ScreenWidget):

    help = _('''
<font size="+2">Partitioning your hard disk</font>

<font size="+1">
<p>
Pardus can be installed on a variety of hardware. You can install Pardus
on an empty disk or hard disk partition. <b>An installation will automatically
destroy the previously saved information on selected partitions. </b>
</p>
<p>
In order to use Pardus, you must create one Linux filesystem (for the 
system files), which is mandatory and a swap space 
(for improved performance), which is optional. 
We advise you to allocate at least 4 GBs of hard disk area and 
swap space (between 500 MB - 2 GB, according to your needs) for 
convenience. A Linux partition size less than 2.5 GB is not allowed.
You may also optionally use another disk partition for storing 
user files.
</p>
<p>
You need to format a Linux partition, if it's used for the first time.
You can enable \'Use available free space\' option, if the hard disk's 
remaining space is to be used automatically.
</p>
<p>
The partition table shows the device, size, partition type and
filesystem information. If the partition will be formatted during
Pardus installation stage, then the corresponding \'Format\' 
column will be enabled.
</p>
<p>
Please refer to Pardus Installing and Using Guide for more information
about disk partitioning.
</p>
</font>
''')


    def __init__(self, *args):
        apply(QWidget.__init__, (self,) + args)
        
        # initialize all storage devices
        if not yali.storage.init_devices():
            raise GUIException, _("Can't find a storage device!")

        self.partlist = PartList(self)
        self.partedit = PartEdit(self)
        self.partedit.hide()
        self.dialog = None

        vbox = QVBoxLayout(self)
        vbox.addWidget(self.partlist)
        
        self.connect(self.partlist, PYSIGNAL("signalCreate"),
                     self.slotCreatePart)

        self.connect(self.partlist, PYSIGNAL("signalDelete"),
                     self.slotDeletePart)

        self.connect(self.partlist, PYSIGNAL("signalEdit"),
                     self.slotEditPart)

        self.connect(self.partlist, PYSIGNAL("signalResize"),
                     self.slotResizePart)


        self.connect(self.partedit, PYSIGNAL("signalApplied"),
                     self.slotApplied)

        self.connect(self.partedit, PYSIGNAL("signalCanceled"),
                     self.slotCanceled)


    def shown(self):
        ctx.screens.enablePrev()

        self.partlist.update()

    ##
    # do the work and run requested actions on partitions.
    def execute(self):

        # show confirmation dialog
        w = WarningWidget(self)
        self.dialog = WarningDialog(w, self)
        if not self.dialog.exec_loop():
            return False


        # commit events
        self.partlist.devices_commit()

        # inform user...
        self.partlist.showPartitionRequests(formatting=True)
        # process events and show partitioning information!
        ctx.screens.processEvents()
        ctx.screens.processEvents()
        
        
        ##
        # check swap partition, if not present use swap file
        rt = request.mountRequestType
        pt = parttype.swap
        found_swap_part = [x for x in ctx.partrequests.searchPartTypeAndReqType(pt, rt)]
        # this should give (at most) one result
        # cause we are storing one request for a partitionType()
        assert(len(found_swap_part) <= 1)


        if not found_swap_part:
            print "no swap partition defined using swap as file..."
            # find root partition
            rt = request.mountRequestType
            pt = parttype.root
            for r in ctx.partrequests.searchPartTypeAndReqType(pt, rt):
                ctx.partrequests.append(
                    request.SwapFileRequest(r.partition(), r.partitionType()))

        # apply all partition requests
        ctx.partrequests.applyAll()

        return True


    def slotCreatePart(self, parent, d):
        self.partedit.setState(createState, d)
        self.dialog = Dialog(_("Create Partition"), self.partedit, self)
        self.dialog.exec_loop()

    def slotDeletePart(self, parent, d):
        self.partedit.setState(deleteState, d)
        self.dialog = Dialog(_("Delete Partition"), self.partedit, self)
        self.dialog.exec_loop()

    def slotEditPart(self, parent, d):
        self.partedit.setState(editState, d)
        self.dialog = Dialog(_("Edit Partition"), self.partedit, self)
        self.dialog.exec_loop()

    def slotResizePart(self, parent, d):
        self.partedit.setState(resizeState, d)
        self.dialog = Dialog(_("Resize Partition"), self.partedit, self)
        self.dialog.exec_loop()


    def slotApplied(self):
        self.dialog.done(0)
        self.partlist.update()

    def slotCanceled(self):
        self.dialog.reject()
Esempio n. 45
0
 def slotResizePart(self, parent, d):
     self.partedit.setState(resizeState, d)
     self.dialog = Dialog(_("Resize Partition"), self.partedit, self)
     self.dialog.exec_loop()