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

Diff of /trunk/src/GLIArchitectureTemplate.py

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

Revision 219 Revision 220
1""" 1"""
2Gentoo Linux Installer 2Gentoo Linux Installer
3 3
4$Id: GLIArchitectureTemplate.py,v 1.28 2005/01/07 05:23:19 codeman Exp $ 4$Id: GLIArchitectureTemplate.py,v 1.29 2005/01/07 07:00:13 agaffney Exp $
5Copyright 2004 Gentoo Technologies Inc. 5Copyright 2004 Gentoo Technologies Inc.
6 6
7 7
8The ArchitectureTemplate is largely meant to be an abstract class and an 8The ArchitectureTemplate is largely meant to be an abstract class and an
9interface (yes, it is both at the same time!). The purpose of this is to create 9interface (yes, it is both at the same time!). The purpose of this is to create
690 raise GLIException("AddUserError", 'warning', 'set_users', "Failure to add user " + username) 690 raise GLIException("AddUserError", 'warning', 'set_users', "Failure to add user " + username)
691 691
692 def install_bootloader(self): 692 def install_bootloader(self):
693 "THIS FUNCTION MUST BE DONE BY THE INDIVIDUAL ARCH" 693 "THIS FUNCTION MUST BE DONE BY THE INDIVIDUAL ARCH"
694 pass 694 pass
695
696 def _cylinders_to_sectors(self, minor, start, end, sectors_in_cylinder):
697 cylinders = int(end) - int(start) + 1
698 total_sectors = cylinders * int(sectors_in_cylinder)
699 start_sector = int(start) * sectors_in_cylinder
700 end_sector = start_sector + total_sectors - 1
701 if int(minor) == 1 and start_sector == 0: start_sector = 63
702 return (start_sector, end_sector)
703
704 def _sectors_to_megabytes(self, sectors, sector_bytes=512):
705 return float((float(sectors) * sector_bytes)/ float(1024*1024))
706
707 def _sectors_to_bytes(self, sectors, sector_bytes=512):
708 return (int(sectors) * sector_bytes)
709
710 def _run_parted_command(self, device, cmd):
711 parted_output = commands.getoutput("parted -s " + device + " " + cmd)
712 print "parted -s " + device + " " + cmd
713
714 def _add_partition(self, device, start, end, type, fs):
715 start = self._sectors_to_megabytes(start)
716 end = self._sectors_to_megabytes(end)
717 self._run_parted_command(device, "mkpart " + type + " " + fs + " " + str(start) + " " + str(end))
718 if type == "ntfs":
719 pass
720 elif type == "ext2" or type == "ext3":
721 pass
722 else:
723 pass
724
725 def do_partitioning(self):
726 import GLIStorageDevice, parted, pprint
727
728 devices_old = {}
729 parts_old = {}
730 parts_new = self._install_profile.get_partition_tables()
731 drives = GLIStorageDevice.detect_devices()
732 drives.sort()
733 for drive in drives:
734 devices_old[drive] = GLIStorageDevice.Device(drive)
735 devices_old[drive].set_partitions_from_disk()
736 for part in devices_old.keys(): parts_old[part] = devices_old[part].get_install_profile_structure()
737
738 pp = pprint.PrettyPrinter(indent=4)
739 pp.pprint(parts_old)
740 pp.pprint(parts_new)
741
742 for dev in parts_old.keys():
743 parts_active = []
744 parts_lba = []
745 print "\nProcessing " + dev + "..."
746 parted_dev = parted.PedDevice.get(dev)
747 parted_disk = parted.PedDisk.new(parted_dev)
748 last_partition_touched = 0
749 sectors_in_cylinder = devices_old[dev]._sectors_in_cylinder
750 # First pass to delete old partitions that aren't resized
751 for part in parts_old[dev]:
752 oldpart = parts_old[dev][part]
753 old_start, old_end = self._cylinders_to_sectors(part, oldpart['start'], oldpart['end'], sectors_in_cylinder)
754 matchingminor = 0
755 for new_part in parts_new[dev]:
756 tmppart = parts_new[dev][new_part]
757 new_start, new_end = self._cylinders_to_sectors(new_part, tmppart['start'], tmppart['end'], sectors_in_cylinder)
758 if int(tmppart['start']) == int(oldpart['start']) and tmppart['format'] == False and tmppart['type'] == oldpart['type'] and int(tmppart['end']) == int(oldpart['end']):
759 matchingminor = new_part
760 print " Deleting old minor " + str(part) + " to be recreated later"
761 self._run_parted_command(dev, "rm " + str(part))
762 break
763 if int(tmppart['start']) == int(oldpart['start']) and tmppart['format'] == False and tmppart['type'] == oldpart['type'] and int(tmppart['end']) != int(oldpart['end']):
764 matchingminor = new_part
765 print " Ignoring old minor " + str(part) + " to resize later"
766 break
767 if not matchingminor:
768 print " No match found...deleting partition " + str(part)
769 self._run_parted_command(dev, "rm " + str(part))
770 else:
771 if parted_disk.get_partition(part).get_flag(1): # Active/boot
772 print " Partition " + str(part) + " was active...noted"
773 parts_active.append(int(matchingminor))
774 if parted_disk.get_partition(part).get_flag(7): # LBA
775 print " Partition " + str(part) + " was LBA...noted"
776 parts_lba.append(int(matchingminor))
777 # Second pass to resize old partitions that need to be resized
778 print " Second pass..."
779 for part in parts_old[dev]:
780 oldpart = parts_old[dev][part]
781 old_start, old_end = self._cylinders_to_sectors(part, oldpart['start'], oldpart['end'], sectors_in_cylinder)
782 for new_part in parts_new[dev]:
783 tmppart = parts_new[dev][new_part]
784 new_start, new_end = self._cylinders_to_sectors(new_part, tmppart['start'], tmppart['end'], sectors_in_cylinder)
785 if int(tmppart['start']) == int(oldpart['start']) and tmppart['format'] == False and tmppart['type'] == oldpart['type'] and int(tmppart['end']) != int(oldpart['end']):
786 print " Resizing old minor " + str(part) + " from " + str(oldpart['start']) + "-" + str(oldpart['end'])+ " to " + str(tmppart['start']) + "-" + str(tmppart['end'])
787 type = tmppart['type']
788 device = dev
789 minor = part
790 start = int(new_start)
791 end = int(new_end)
792 if type == "ext2" or type == "ext3":
793 total_sectors = end - start + 1
794 commands.getstatus("resize2fs " + device + str(minor) + " " + str(total_sectors) + "s")
795 print "resize2fs " + device + str(minor) + " " + str(total_sectors) + "s"
796 elif type == "ntfs":
797 total_sectors = end - start + 1
798 total_bytes = int(self._sectors_to_bytes(total_sectors))
799 commands.getstatus("ntfsresize --size " + str(total_bytes) + " " + device + str(minor))
800 print "ntfsresize --size " + str(total_bytes) + " " + device + str(minor)
801 else:
802 start = float(self._sectors_to_megabytes(start))
803 end = float(self._sectors_to_megabytes(end))
804 self._run_parted_command(device, "resize " + str(minor) + " " + str(start) + " " + str(end))
805 print " Deleting old minor " + str(part) + " to be recreated in 3rd pass"
806 self._run_parted_command(dev, "rm " + str(part))
807 break
808 # Third pass to create new partition table
809 print " Third pass..."
810 for part in parts_new[dev]:
811 newpart = parts_new[dev][part]
812 new_start, new_end = self._cylinders_to_sectors(part, newpart['start'], newpart['end'], sectors_in_cylinder)
813 if newpart['type'] == "extended":
814 print " Adding extended partition from " + str(newpart['start']) + " to " + str(newpart['end'])
815 self._add_partition(dev, new_start, new_end, "extended", "")
816 elif int(part) < 5:
817 print " Adding primary partition from " + str(newpart['start']) + " to " + str(newpart['end'])
818 self._add_partition(dev, new_start, new_end, "primary", newpart['type'])
819 elif int(part) > 4:
820 print " Adding logical partition from " + str(newpart['start']) + " to " + str(newpart['end'])
821 self._add_partition(dev, new_start, new_end, "logical", newpart['type'])
822 if int(part) in parts_active and not newpart['format']:
823 print " Partition was previously active...setting"
824 self._run_parted_command(dev, "set " + str(part) + " boot on")
825 if int(part) in parts_lba and not newpart['format']:
826 print " Partition was previously LBA...setting"
827 self._run_parted_command(dev, "set " + str(part) + " lba on")

Legend:
Removed from v.219  
changed lines
  Added in v.220

  ViewVC Help
Powered by ViewVC 1.1.20