SF.net SVN: morphix: [2366] trunk/morphixinstaller2/lib_install.py

[email protected] Fri, 21 Jul 2006 02:33:31 -0700
Newsgroups gmane.linux.morphix.cvs
Message-ID <[email protected]>
Revision: 2366
Author:   alextreme
Date:     2006-07-21 02:33:23 -0700 (Fri, 21 Jul 2006)
ViewCVS:  http://svn.sourceforge.net/morphix/?rev=2366&view=rev

Log Message:
-----------
  * getting there...

Modified Paths:
--------------
    trunk/morphixinstaller2/lib_install.py
Modified: trunk/morphixinstaller2/lib_install.py
===================================================================
--- trunk/morphixinstaller2/lib_install.py	2006-07-20 21:44:32 UTC (rev 2365)
+++ trunk/morphixinstaller2/lib_install.py	2006-07-21 09:33:23 UTC (rev 2366)
@@ -45,6 +45,14 @@
 		return self.executeCommand('uname -r')
 	
 	def getHarddiskList(self):
+		"""
+	Return a list of all available harddisks, with
+	each item in the list containing a list with the
+	first item being the name of the harddisk (hda, sda)
+	and the second name being a natural-language
+	description of the harddisk
+		"""
+
 		hdd_list = []
 
 		part_data = self.getContents(self.proc_partitions)
@@ -70,45 +78,134 @@
 				if media == None:
 					hdd_name = "RAID: " + str(name)
 				else:
-					hdd_name = str(name) + " with " + str(size) + " MiB, " + str(media)
+					hdd_name = str(name) + " with " + str(size) + " MB, " + str(media)
 	
 			if name[:2] == "sd":
-				hdd_name = str(name) + " with " + str(size) + " MiB, SCSI"
+				hdd_name = str(name) + " with " + str(size) + " MB, SCSI"
 
 			hdd_list += [[name, hdd_name]]
 
 		return hdd_list
 
-	def getPartitionList():
-		return
+	def getPartitionList(self, harddisk, do_swap = False):
+		""" 
+	Given a harddisk name, return a list of partitions
+	available on this harddisk. If do_swap is False,
+	only Linux-type partitions are returned. If do_swap
+	is True, only Linux-swap-type partitions are
+	returned.
+	The returned list contains a list for each partition,
+	containing the name as the first item and a
+	natural-language description as the second item
+		"""
 
-	def getExpertPartitionList():
+		ret_list = []
+
+		if harddisk == None:
+			return None
+
+		data = self.executeCommand("fdisk -l /dev/" + harddisk)
+		if data == "":
+			return None
+
+		partition_array = data.split("\n")
+		partition_array = partition_array[6:]
+		for partition in partition_array:
+			part_item = partition.split()
+			name = part_item[0]
+			id = part_item[4]
+			size = part_item[3]
+
+			if int(id) <= 0:
+				continue
+
+			if (id == 83 and do_swap == False) or (id == 82 and do_swap == True):
+				ret_list += [[name, str(name) + " - size: " + str(size / 1024) + " MB"]]
+
+		if do_swap == True:
+			ret_list += [["none", "No Swap"]]
+
+		return ret_list
+
+	def getExpertPartitionList(self):
 		return []
 
-	def unmountHarddiskPartitions(harddisk):
-		return
+	def unmountHarddiskPartitions(self, harddisk):
+		files = os.listdir(self.path_mnt_dir)
+		for file in files:
+			if file[0:3] == harddisk:
+				self.executeCommand("umount /mnt/" + file)
+		return True
 
-	def initInstallProcess():
-		return
+	def initInstallProcess(self):
+		return True
 
-	def startPartitioner(harddisk, partitioner, xfree86):
+	def startPartitioner(self, harddisk, command):
+		self.executeCommand(command + harddisk)
 		return
 
-	def getPartitionerCommands(harddisk, xfree86):
-		return
+	def getPartitioners(self, xfree86 = True):
+		
+		"""
+	Given xfree86 return either all X-enabled partitioners
+	or all commandline-based partitioners.
+	Returns a list, with each item being a list with the
+	first item being the natural language description
+	about the partitioner and the second item being
+	the command required to run the partitioner, minus
+	the name of the harddisk (which needs to be appended)
+		"""
 
-	def getPartitionerNames(xfree86):
-		return
+		partitioners = []
+		if xfree86:
+			if os.access(self.pm_path, os.F_OK):
+				partitioners += [["Partition Morpher - Graphical Partitioner", self.pm_path + " /dev/"]]
+			if os.access(self.qtparted_path, os.F_OK):
+				partitioners += [["CFDisk - commandline partitioner", self.qtparted_path + " /dev/"]]
+			if os.access(self.gparted_path, os.F_OK):
+				partitioners += [["QTParted - Graphical Partitioner", self.gparted_path + " /dev/"]]
+			if os.access(self.cfdisk_path, os.F_OK):
+				partitioners += [["CFDisk - commandline partitioner", "xterm -fn 10x20 -e " + str(self.cfdisk_path) + " /dev/"]]
+			if os.access(self.parted_path, os.F_OK):
+				partitioners += [["Parted - commandline partitioner", "xterm -fn 10x20 -e " + str(self.parted_path) + " /dev/"]]
 
-	def makeSwap():
-		return
+		# commandline-partitioners
+		else:
+			if os.access(self.cfdisk_path, os.F_OK):
+				partitioners += [["CFDisk - commandline partitioner", str(self.cfdisk_path) + " /dev/"]]
+			if os.access(self.parted_path, os.F_OK):
+				partitioners += [["Parted - commandline partitioner", str(self.parted_path) + " /dev/"]]			
+		
+		return partitioners
 
-	def makeFilesystem(partition, filesystem):
-		return
+	def makeSwap(self, swap_partition):
+		self.executeCommand("mkswap " + swap_partition)
+		return True
 
-	def makeRoot():
-		return
+	def makeFilesystem(self, partition, filesystem):
+		if filesystem == "ext2":
+			self.executeCommand("mkfs.ext2 " + partition)
+			return True
+		if filesystem == "ext3":
+			self.executeCommand("mkfs.ext3 " + partition)
+			return True
+		if filesystem == "reiserfs":
+			self.executeCommand("mkfs.reiserfs -q " + partition)
+			return True
 
+		return False
+
+	def makeRoot(self, root_partition, root_mountpoint, filesystem_type = "ext3"):
+		if root_partition == None:
+			return False
+
+		self.executeCommand("umount " + root_partition)
+		self.executeCommand("umount " + root_mountpoint)
+		# TODO: umount expert partitions
+		self.makeFilesystem(root_partition, filesystem_type)
+		# TODO: makeFS expert partitions
+		return True
+
 	def getTotalPartitionSize():
 		return
 	
@@ -121,18 +218,94 @@
 	def getCurrentPercentage():
 		return
 
-	def executeMinimoduleInstallscripts():
-		return
+	def executeMinimoduleInstallscripts(self, root_mountpoint):
+		minimods = os.listdir("/mnt/mini")
+		for minimod in minimods:
+			install_sh = "/mnt/mini/" + minimod + "/morphix/install.sh"
+			if os.access(install_sh, os.F_OK):
+				# install script gets root mountpoint as first argument
+				self.executeCommand(install_sh + " " + root_mountpoint)
+			else:
+				self.executeCommand("mkdir -p " + root_mountpoint + "/mnt/mini")
+				self.executeCommand("cp -a /mnt/mini/" + minimod + " " + root_mountpoint + "/mnt/mini/")
 
-	def mountPartition(partition, destination):
-		return
+		return True
 
+	def mountPartition(self, partition, destination):
+		if not os.access(destination, os.F_OK):
+			if not os.mkdir(destination, 0755):
+				return False
+		
+		self.executeCommand("mount " + partition + " " + destination)
+
+		return True
+
 	def umountTarget():
 		return
 
-	def buildRoot():
-		return
+	def buildRoot(self, root_mountpoint, root_partition, filesystem_type, swap_partition):
+		self.executeCommand("mkdir -p " + root_mountpoint)
+		self.mountPartition(root_partition, root_mountpoint)
+		# TODO: mount extra partitions
 
+		dirs = ["/bin", "/etc", "/home", "/lib", "/morphix", "/sbin", "/usr", "/opt", "/var", "/root", "/mnt/mini"]
+		for dir in dirs:
+			self.executeCommand("sh -c \"find " + dir + " -depth | cpio -pdmv --quiet " + root_mountpoint + "\"")
+
+		self.executeCommand("sh -c \"cd /MorphixCD && find ./dev -depth | cpio -pdmv --quiet " + root_mountpoint + "\"")
+		self.executeCommand("sh -c \"cd /MorphixCD && find ./boot -depth | cpio -pdmv --quiet " + root_mountpoint + "\"")
+
+
+		os.unlink(root_mountpoint + "/etc/hosts")
+		
+		dirs = ["/cdrom", "/cdrom1", "/floppy", "/mnt", "/proc", "/sys"]
+
+		for dir in dirs:
+			os.mkdir(root_mountpoint + "/" + dir)
+
+		self.executeMinimoduleInstallscripts(root_mountpoint)
+
+		skip_list ["translucency", "cowloop", "mini_fo", "ide_scsi", "cloop"]
+		fd = open(root_mountpoint + "/etc/modules", "w")
+		module_data = self.getContents(self.proc_modules)
+		modules = module_data.split("\n")
+		for module in modules:
+			data = module.split()
+			module_name = data[0]
+			if module_name in skip_list:
+				continue
+			fd.write(module_name + "\n")
+		fd.close()
+
+		fd = open(root_mountpoint + "/etc/fstab", "w")
+		fd.write(root_partition + " \t / " + filesystem_type + " \t defaults \t 0 \t 1\n")
+		if swap_partition != None:
+			fd.write(swap_partition + " \t none \t swap \t sw \t 0 \t 0\n")
+
+		# TODO: add expert partitions
+
+		# TODO/note from old partitioner: use portions from live-CD fstab?
+
+		fd.write("proc /proc proc defaults 0 0\n/dev/fd0 /floppy auto user,noauto 0 0\n/dev/cdrom /cdrom auto ro,user,noauto 0 0\nnone /sys sysfs defaults 0 0\n")
+		
+		old_fstab = self.getContents("/etc/fstab")
+		fstab_list = old_fstab.split("\n")
+		for i in range(0, len(fstab_list)):
+			if "Added by morphix-base" in fstab_list[i]:
+				i += 1
+				fd.write("# Added by morphix installer during install\n")
+				sub_item = fstab_list[i].split()
+				name = sub_item[1]
+				if name != "none":
+					os.mkdir(root_mountpoint + "/" + name)
+				fd.write(fstab_list[i])
+
+		fd.close()
+
+		# TODO: umount extra partitions
+
+		return True
+
 	def copyKernel():
 		return
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV