def is_summable(self, otra, actual):
     '''Indica si se puede sumar el tamaño de las particiones si se trata \
     del mismo tipo (primaria o lógica)'''
     # Si la particion es libre
     if otra[TblCol.FORMATO] == msj.particion.libre:
         # Si ambas son primarias
         # o ambas son logicas
         if (is_primary(actual) and is_primary(otra)) \
         or (is_logic(actual) and is_logic(otra)):
             return True
     return False
Example #2
0
 def is_summable(self, otra, actual):
     '''Indica si se puede sumar el tamaño de las particiones si se trata \
     del mismo tipo (primaria o lógica)'''
     # Si la particion es libre
     if otra[TblCol.FORMATO] == msj.particion.libre:
         # Si ambas son primarias
         # o ambas son logicas
         if (is_primary(actual) and is_primary(otra)) \
         or (is_logic(actual) and is_logic(otra)):
             return True
     return False
    def delete_partition(self, part):
        'Ejecuta el proceso de eliminar la particion de la lista'
        i = get_row_index(self.lista, part)
        particion = self.lista[i]
        inicio = particion[TblCol.INICIO]
        fin = particion[TblCol.FIN]
        del_sig = del_ant = False

        # Si tiene una fila anterior
        if i > 0:
            p_anterior = self.lista[i - 1]
            if self.is_summable(p_anterior, particion):
                del_ant = True
                inicio = p_anterior[TblCol.INICIO]
        # si tiene una fila siguiente
        if has_next_row(self.lista, i):
            p_siguiente = self.lista[i + 1]
            if self.is_summable(p_siguiente, particion):
                del_sig = True
                fin = p_siguiente[TblCol.FIN]

        tamano = fin - inicio

        temp = copy(particion)
        temp[TblCol.DISPOSITIVO] = ''
        # Validar de que tipo quedará la particion libre
        if is_primary(temp):
            temp[TblCol.TIPO] = msj.particion.primaria
        elif is_logic(temp):
            temp[TblCol.TIPO] = msj.particion.logica
        temp[TblCol.FORMATO] = msj.particion.libre
        temp[TblCol.MONTAJE] = ''
        temp[TblCol.TAMANO] = humanize(tamano)
        temp[TblCol.USADO] = humanize(0)
        temp[TblCol.LIBRE] = humanize(tamano)
        temp[TblCol.INICIO] = inicio
        temp[TblCol.FIN] = fin
        temp[TblCol.FORMATEAR] = False
        temp[TblCol.ESTADO] = PStatus.FREED

        # Sustituimos con los nuevos valores
        self.lista[i] = temp
        # Borramos los esṕacios vacios contiguos si existieren
        if del_sig:
            del self.lista[i + 1]
        if del_ant:
            del self.lista[i - 1]

        # Si lo que se estaeliminando no es un espacio libre
        if not is_free(particion):
            # Agregamos la accion correspondiente
            self.acciones.append(['borrar',
                                  self.disco,
                                  None,
                                  particion[TblCol.INICIO],
                                  particion[TblCol.FIN],
                                  particion[TblCol.FORMATO],
                                  msj.particion.get_tipo_orig(
                                                       particion[TblCol.TIPO]),
                                  0])
 def count_primary(self):
     '''Cuenta la cantidad de particiones primarias. Las particiones
     extendidas cuentan como primarias'''
     total = 0
     for fila in self.lista:
         if is_primary(fila) and not is_free(fila):
             total = total + 1
     return total
Example #5
0
 def count_primary(self):
     '''Cuenta la cantidad de particiones primarias. Las particiones
     extendidas cuentan como primarias'''
     total = 0
     for fila in self.lista:
         if is_primary(fila) and not is_free(fila):
             total = total + 1
     return total
Example #6
0
    def delete_partition(self, part):
        'Ejecuta el proceso de eliminar la particion de la lista'
        i = get_row_index(self.lista, part)
        particion = self.lista[i]
        inicio = particion[TblCol.INICIO]
        fin = particion[TblCol.FIN]
        del_sig = del_ant = False

        # Si tiene una fila anterior
        if i > 0:
            p_anterior = self.lista[i - 1]
            if self.is_summable(p_anterior, particion):
                del_ant = True
                inicio = p_anterior[TblCol.INICIO]
        # si tiene una fila siguiente
        if has_next_row(self.lista, i):
            p_siguiente = self.lista[i + 1]
            if self.is_summable(p_siguiente, particion):
                del_sig = True
                fin = p_siguiente[TblCol.FIN]

        tamano = fin - inicio

        temp = copy(particion)
        temp[TblCol.DISPOSITIVO] = ''
        # Validar de que tipo quedará la particion libre
        if is_primary(temp):
            temp[TblCol.TIPO] = msj.particion.primaria
        elif is_logic(temp):
            temp[TblCol.TIPO] = msj.particion.logica
        temp[TblCol.FORMATO] = msj.particion.libre
        temp[TblCol.MONTAJE] = ''
        temp[TblCol.TAMANO] = humanize(tamano)
        temp[TblCol.USADO] = humanize(0)
        temp[TblCol.LIBRE] = humanize(tamano)
        temp[TblCol.INICIO] = inicio
        temp[TblCol.FIN] = fin
        temp[TblCol.FORMATEAR] = False
        temp[TblCol.ESTADO] = PStatus.FREED

        # Sustituimos con los nuevos valores
        self.lista[i] = temp
        # Borramos los esṕacios vacios contiguos si existieren
        if del_sig:
            del self.lista[i + 1]
        if del_ant:
            del self.lista[i - 1]

        # Si lo que se estaeliminando no es un espacio libre
        if not is_free(particion):
            # Agregamos la accion correspondiente
            self.acciones.append([
                'borrar', self.disco, None, particion[TblCol.INICIO],
                particion[TblCol.FIN], particion[TblCol.FORMATO],
                msj.particion.get_tipo_orig(particion[TblCol.TIPO]), 0
            ])
    def table_row_selected(self, fila):
        """Acciones a tomar cuando una fila de la tabla es seleccionada"""

        # Si no se selecciona una fila valida
        if fila == None:
            print "Nada seleccionado."
            return
        else:
            self.fila_selec = fila

        # BTN_NUEVA
        if is_free(fila):
            # Activar solo si hay menos de 4 particiones primarias
            if is_primary(fila) and self.count_primary() < 4:
                self.btn_nueva.set_sensitive(True)
            # o si la part. libre es logica
            elif is_logic(fila) and self.count_logical() < 11:
                self.btn_nueva.set_sensitive(True)
            else:
                self.btn_nueva.set_sensitive(False)
        else:
            self.btn_nueva.set_sensitive(False)

        # BTN_USAR
        if is_usable(self.fila_selec):
            self.btn_editar.set_sensitive(True)
        else:
            self.btn_editar.set_sensitive(False)

        # BTN_REDIMENSION
        # Si la particion NO es libre
        # si el filesystem tiene redimensionador
        # y no se ha marcado la aprticion para usarla
        # y si hay espacio para redimensionar dentro de la particion
        if (
            fila[TblCol.FORMATO] != msj.particion.libre
            and is_resizable(fila[TblCol.FORMATO])
            and fila[TblCol.ESTADO] != PStatus.USED
            and floatify(fila[TblCol.TAMANO]) > floatify(fila[TblCol.USADO])
        ):
            self.btn_redimension.set_sensitive(True)
        else:
            self.btn_redimension.set_sensitive(False)

        # BTN_ELIMINAR
        # Solo se pueden eliminar particiones, no los espacios libres
        # TODO: Eliminar part. extendidas (necesita verificar part. logicas)
        if not is_free(fila):
            self.btn_eliminar.set_sensitive(True)
        else:
            self.btn_eliminar.set_sensitive(False)
Example #8
0
    def table_row_selected(self, fila):
        '''Acciones a tomar cuando una fila de la tabla es seleccionada'''

        # Si no se selecciona una fila valida
        if fila == None:
            print "Nada seleccionado."
            return
        else:
            self.fila_selec = fila

        # BTN_NUEVA
        if is_free(fila):
            # Activar solo si hay menos de 4 particiones primarias
            if is_primary(fila) and self.count_primary() < 4:
                self.btn_nueva.set_sensitive(True)
            # o si la part. libre es logica
            elif is_logic(fila) and self.count_logical() < 11:
                self.btn_nueva.set_sensitive(True)
            else:
                self.btn_nueva.set_sensitive(False)
        else:
            self.btn_nueva.set_sensitive(False)

        # BTN_USAR
        if is_usable(self.fila_selec):
            self.btn_editar.set_sensitive(True)
        else:
            self.btn_editar.set_sensitive(False)

        #BTN_REDIMENSION
        # Si la particion NO es libre
        # si el filesystem tiene redimensionador
        # y no se ha marcado la aprticion para usarla
        # y si hay espacio para redimensionar dentro de la particion
        if fila[TblCol.FORMATO] != msj.particion.libre \
        and is_resizable(fila[TblCol.FORMATO]) \
        and fila[TblCol.ESTADO] != PStatus.USED \
        and floatify(fila[TblCol.TAMANO]) > floatify(fila[TblCol.USADO]):
            self.btn_redimension.set_sensitive(True)
        else:
            self.btn_redimension.set_sensitive(False)

        # BTN_ELIMINAR
        # Solo se pueden eliminar particiones, no los espacios libres
        #TODO: Eliminar part. extendidas (necesita verificar part. logicas)
        if not is_free(fila):
            self.btn_eliminar.set_sensitive(True)
        else:
            self.btn_eliminar.set_sensitive(False)
    def __init__(self, lista, fila_selec, acciones):
        self.lista = lista
        self.fila_selec = fila_selec
        self.acciones = acciones
        self.disco = fila_selec[TblCol.DISPOSITIVO]

        if is_primary(self.fila_selec, False) or is_logic(self.fila_selec):
            self.delete_partition(self.fila_selec)
        else:
            is_clean = True
            for partition in self.lista:
                if is_logic(partition) and not is_free(partition):
                    message = "Debe borrar primero las particiones lógicas."
                    UserMessage(message, 'ERROR', gtk.MESSAGE_ERROR, gtk.BUTTONS_OK)
                    is_clean = False
                    break;
            if is_clean:
                i = get_row_index(self.lista, self.fila_selec)
                free = self.lista[i + 1]
                self.delete_partition(self.fila_selec)
                free[TblCol.TIPO] = msj.particion.primaria
                self.delete_partition(free)
Example #10
0
    def __init__(self, lista, fila_selec, acciones):
        self.lista = lista
        self.fila_selec = fila_selec
        self.acciones = acciones
        self.disco = fila_selec[TblCol.DISPOSITIVO]

        if is_primary(self.fila_selec, False) or is_logic(self.fila_selec):
            self.delete_partition(self.fila_selec)
        else:
            is_clean = True
            for partition in self.lista:
                if is_logic(partition) and not is_free(partition):
                    message = _("You must first delete the logical \
partitions.")
                    UserMessage(message, 'ERROR', gtk.MESSAGE_ERROR,
                                gtk.BUTTONS_OK)
                    is_clean = False
                    break
            if is_clean:
                i = get_row_index(self.lista, self.fila_selec)
                free = self.lista[i + 1]
                self.delete_partition(self.fila_selec)
                free[TblCol.TIPO] = msj.particion.primaria
                self.delete_partition(free)