/[gli]/trunk/src/GLIStorageDevice.py
Gentoo

Diff of /trunk/src/GLIStorageDevice.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 513 Revision 514
459 _resizeable = None 459 _resizeable = None
460 _min_sectors_for_resize = 0 460 _min_sectors_for_resize = 0
461 _mb = 0 461 _mb = 0
462 462
463 ## 463 ##
464 # Brief description of function 464 # Initialization function for the Partition class
465 # @param self Parameter description
466 # @param device Parameter description
467 # @param minor Parameter description
468 # @param mb Parameter description
469 # @param start Parameter description
470 # @param end Parameter description 465 # @param self Parameter description
471 # @param type Parameter description 466 # @param device Parent GLIStorageDevice object
472 # @param mountpoint='' Parameter description 467 # @param minor Minor of partition
473 # @param mountopts='' Parameter description 468 # @param mb Parameter Size of partition in MB
474 # @param format=True Parameter description 469 # @param start Parameter Start sector of partition
475 # @param existing=False Parameter description 470 # @param end Parameter Start sector of partition
471 # @param type Parameter Type of partition (ext2, ext3, fat32, linux-swap, free, extended, etc.)
472 # @param mountpoint='' Mountpoint of partition
473 # @param mountopts='' Mount options of partition
474 # @param format=True Format partition
475 # @param existing=False This partition exists on disk
476 def __init__(self, device, minor, mb, start, end, type, mountpoint='', mountopts='', format=True, existing=False): 476 def __init__(self, device, minor, mb, start, end, type, mountpoint='', mountopts='', format=True, existing=False):
477 self._device = device 477 self._device = device
478 self._minor = float(minor) 478 self._minor = float(minor)
479 if existing: self._orig_minor = int(minor) 479 if existing: self._orig_minor = int(minor)
480 self._start = int(start) 480 self._start = int(start)
515 if int(min_size) != min_size: min_size = int(min_size) + 1 515 if int(min_size) != min_size: min_size = int(min_size) + 1
516 self._min_sectors_for_resize = min_size 516 self._min_sectors_for_resize = min_size
517 self._resizeable = True 517 self._resizeable = True
518 518
519 ## 519 ##
520 # Brief description of function 520 # Returns whether or not the partition is extended
521 # @param self Parameter description 521 # @param self Parameter description
522 def is_extended(self): 522 def is_extended(self):
523 if self._type == "extended": 523 if self._type == "extended":
524 return True 524 return True
525 else: 525 else:
526 return False 526 return False
527 527
528 ## 528 ##
529 # Brief description of function 529 # Returns whether or not the partition is logical
530 # @param self Parameter description 530 # @param self Parameter description
531 def is_logical(self): 531 def is_logical(self):
532 if self._type == "free": 532 if self._type == "free":
533 if int(self._minor) + Decimal("0.9") == Decimal(str(self._minor)): 533 if int(self._minor) + Decimal("0.9") == Decimal(str(self._minor)):
534 return True 534 return True
538 return True 538 return True
539 else: 539 else:
540 return False 540 return False
541 541
542 ## 542 ##
543 # Brief description of function 543 # Returns a list of logical partitions if this is an extended partition
544 # @param self Parameter description 544 # @param self Parameter description
545 def get_logicals(self): 545 def get_logicals(self):
546 if not self.is_extended(): 546 if not self.is_extended():
547 return None 547 return None
548 logicals = [] 548 logicals = []
554 logicals.append(part) 554 logicals.append(part)
555 logicals.sort() 555 logicals.sort()
556 return logicals 556 return logicals
557 557
558 ## 558 ##
559 # Brief description of function 559 # Returns the extened parent partition if this is a logical partition (no longer used)
560 # @param self Parameter description 560 # @param self Parameter description
561 def get_extended_parent(self): 561 def get_extended_parent(self):
562 if not self.is_logical(): 562 if not self.is_logical():
563 return None 563 return None
564 else: 564 else:
565 return self._device.get_partition_at(self._start, ignore_extended=0) 565 return self._device.get_partition_at(self._start, ignore_extended=0)
566 566
567 ## 567 ##
568 # Brief description of function 568 # Sets the start sector for the partition
569 # @param self Parameter description
570 # @param start Parameter description 569 # @param self Parameter description
570 # @param start Start sector
571 def set_start(self, start): 571 def set_start(self, start):
572 self._start = int(start) 572 self._start = int(start)
573 self._blocks = ((self._end - self._start) * self._device.get_cylinder_size()) / 512 573 self._blocks = ((self._end - self._start) * self._device.get_cylinder_size()) / 512
574 574
575 ## 575 ##
576 # Brief description of function 576 # Returns the start sector for the partition
577 # @param self Parameter description 577 # @param self Parameter description
578 def get_start(self): 578 def get_start(self):
579 return int(self._start) 579 return int(self._start)
580 580
581 ## 581 ##
582 # Brief description of function 582 # Sets the end sector of the partition
583 # @param self Parameter description
584 # @param end Parameter description 583 # @param self Parameter description
584 # @param end End sector
585 def set_end(self, end): 585 def set_end(self, end):
586 self._end = int(end) 586 self._end = int(end)
587 self._blocks = ((self._end - self._start) * self._device.get_cylinder_size()) / 512 587 self._blocks = ((self._end - self._start) * self._device.get_cylinder_size()) / 512
588 588
589 ## 589 ##
590 # Brief description of function 590 # Returns end sector for the partition
591 # @param self Parameter description 591 # @param self Parameter description
592 def get_end(self): 592 def get_end(self):
593 return int(self._end) 593 return int(self._end)
594 594
595 ## 595 ##
596 # Brief description of function 596 # Returns size of partition in MB
597 # @param self Parameter description 597 # @param self Parameter description
598 def get_mb(self): 598 def get_mb(self):
599 return int(self._mb) 599 return int(self._mb)
600 600
601 ## 601 ##
602 # Brief description of function 602 # Sets size of partition in MB
603 # @param self Parameter description 603 # @param self Parameter description
604 # @param mb Parameter description 604 # @param mb Parameter description
605 def set_mb(self, mb): 605 def set_mb(self, mb):
606 self._mb = int(mb) 606 self._mb = int(mb)
607 607
608 ## 608 ##
609 # Brief description of function 609 # Sets type of partition
610 # @param self Parameter description 610 # @param self Parameter description
611 # @param type Parameter description 611 # @param type Parameter description
612 def set_type(self, type): 612 def set_type(self, type):
613 self._type = type 613 self._type = type
614 614
615 ## 615 ##
616 # Brief description of function 616 # Returns type of partition
617 # @param self Parameter description 617 # @param self Parameter description
618 def get_type(self): 618 def get_type(self):
619 return self._type 619 return self._type
620 620
621 ## 621 ##
622 # Brief description of function 622 # Returns parent GLIStorageDevice object
623 # @param self Parameter description 623 # @param self Parameter description
624 def get_device(self): 624 def get_device(self):
625 return self._device 625 return self._device
626 626
627 ## 627 ##
628 # Brief description of function 628 # Sets minor of partition
629 # @param self Parameter description
630 # @param minor Parameter description 629 # @param self Parameter description
630 # @param minor New minor
631 def set_minor(self, minor): 631 def set_minor(self, minor):
632 self._minor = float(minor) 632 self._minor = float(minor)
633 633
634 ## 634 ##
635 # Brief description of function 635 # Returns minor of partition
636 # @param self Parameter description 636 # @param self Parameter description
637 def get_minor(self): 637 def get_minor(self):
638 return float(self._minor) 638 return float(self._minor)
639 639
640 ## 640 ##
641 # Brief description of function 641 # Sets the original minor of the partition
642 # @param self Parameter description 642 # @param self Parameter description
643 # @param orig_minor Parameter description 643 # @param orig_minor Parameter description
644 def set_orig_minor(self, orig_minor): 644 def set_orig_minor(self, orig_minor):
645 self._orig_minor = int(orig_minor) 645 self._orig_minor = int(orig_minor)
646 646
647 ## 647 ##
648 # Brief description of function 648 # Returns the original minor of the partition
649 # @param self Parameter description 649 # @param self Parameter description
650 def get_orig_minor(self): 650 def get_orig_minor(self):
651 return self._orig_minor 651 return self._orig_minor
652 652
653 ## 653 ##
654 # Brief description of function 654 # Sets the mountpoint for the partition
655 # @param self Parameter description
656 # @param mountpoint Parameter description 655 # @param self Parameter description
656 # @param mountpoint Mountpoint
657 def set_mountpoint(self, mountpoint): 657 def set_mountpoint(self, mountpoint):
658 self._mountpoint = mountpoint 658 self._mountpoint = mountpoint
659 659
660 ## 660 ##
661 # Brief description of function 661 # Returns the mountpoint for the partition
662 # @param self Parameter description 662 # @param self Parameter description
663 def get_mountpoint(self): 663 def get_mountpoint(self):
664 return self._mountpoint 664 return self._mountpoint
665 665
666 ## 666 ##
667 # Brief description of function 667 # Sets the mount options for the partition
668 # @param self Parameter description
669 # @param mountopts Parameter description 668 # @param self Parameter description
669 # @param mountopts Mount options
670 def set_mountopts(self, mountopts): 670 def set_mountopts(self, mountopts):
671 self._mountopts = mountopts 671 self._mountopts = mountopts
672 672
673 ## 673 ##
674 # Brief description of function 674 # Returns the mount options for the partition
675 # @param self Parameter description 675 # @param self Parameter description
676 def get_mountopts(self): 676 def get_mountopts(self):
677 return self._mountopts 677 return self._mountopts
678 678
679 ## 679 ##
680 # Brief description of function 680 # Set whether to format the partition
681 # @param self Parameter description 681 # @param self Parameter description
682 # @param format Parameter description 682 # @param format Parameter description
683 def set_format(self, format): 683 def set_format(self, format):
684 self._format = format 684 self._format = format
685 685
686 ## 686 ##
687 # Brief description of function 687 # Returns whether to format the partition
688 # @param self Parameter description 688 # @param self Parameter description
689 def get_format(self): 689 def get_format(self):
690 return self._format 690 return self._format
691 691
692 ## 692 ##
693 # Brief description of function 693 # Returns minimum sectors for resize
694 # @param self Parameter description
695 def get_blocks(self):
696 return int(self._blocks)
697
698 ##
699 # Brief description of function
700 # @param self Parameter description 694 # @param self Parameter description
701 def get_min_sectors_for_resize(self): 695 def get_min_sectors_for_resize(self):
702 if self.is_extended(): 696 if self.is_extended():
703 min_size = self._start 697 min_size = self._start
704 for part in self._device._partitions: 698 for part in self._device._partitions:
707 return min_size 701 return min_size
708 else: 702 else:
709 return self._min_sectors_for_resize 703 return self._min_sectors_for_resize
710 704
711 ## 705 ##
712 # Brief description of function 706 # Returns maximum sectors for resize
713 # @param self Parameter description 707 # @param self Parameter description
714 def get_max_sectors_for_resize(self): 708 def get_max_sectors_for_resize(self):
715 free_start, free_end = self._device.get_free_space(self._end) 709 free_start, free_end = self._device.get_free_space(self._end)
716 if free_end == -1: return self._end 710 if free_end == -1: return self._end
717 if free_start - 1 == self._end: 711 if free_start - 1 == self._end:
722 return self._end - self._start 716 return self._end - self._start
723 else: 717 else:
724 return free_end - self._start 718 return free_end - self._start
725 719
726 ## 720 ##
727 # Brief description of function 721 # Resizes the partition
728 # @param self Parameter description
729 # @param start Parameter description
730 # @param end Parameter description 722 # @param self Parameter description
723 # @param start New start sector
724 # @param end New end sector
731 def resize(self, start, end): 725 def resize(self, start, end):
732 part_at_start = self._device.get_partition_at(int(start)) 726 part_at_start = self._device.get_partition_at(int(start))
733 part_at_end = self._device.get_partition_at(int(end)) 727 part_at_end = self._device.get_partition_at(int(end))
734 logicals = None 728 logicals = None
735 if self.is_logical(): 729 if self.is_logical():
750 self.set_start(start) 744 self.set_start(start)
751 self.set_end(end) 745 self.set_end(end)
752 return 1 746 return 1
753 747
754 ## 748 ##
755 # Brief description of function 749 # Utility function to raise an exception
756 # @param self Parameter description
757 # @param message Parameter description 750 # @param self Parameter description
751 # @param message Error message
758 def _error(self, message): 752 def _error(self, message):
759 "Raises an exception" 753 "Raises an exception"
760 raise "PartitionObjectError", message 754 raise "PartitionObjectError", message
761
762 755
756##
757# Returns a list of detected partitionable devices
763def detect_devices(): 758def detect_devices():
764 "Returns a list of partitionable devices on the system" 759 "Returns a list of partitionable devices on the system"
765 760
766 devices = [] 761 devices = []
767 762

Legend:
Removed from v.513  
changed lines
  Added in v.514

  ViewVC Help
Powered by ViewVC 1.1.20