Esempio n. 1
0
def format_partition_for_real(obj, fs):
	""" Uses mkfs.* to format partition. """	

	# Get an appropriate frontend
	frontend = get_supported_filesystems()[fs]
	
	_app = frontend[0] # Application (e.g /sbin/mkfs.ext4)
	_opt = frontend[1] # Options of the application.
	
	# Umount...
	if is_mounted(obj.path):
		umount(parted_part=obj)
	
	_opt = "%s %s" % (obj.path, _opt)
	
	# In some cases, a freshly committed Disk object will temporairly
	# make the partitions unavailable.
	# Running partprobe resolves this, but will slow down the process
	# a bit.
	try:
		m.sexec("partprobe")
	except:
		pass
	
	# BEGIN FORMATTING!!!!111111!!!!!!!!!!!!!1111111111111111
	mkfs = m.execute("%s %s" % (_app, _opt))
	mkfs.start() # START!!!111111111!!!!!!!!!!!!!!!111111111111111
	
	# Return object to frontend, it should handle all.
	return mkfs
Esempio n. 2
0
def is_mounted(obj):
	""" Checks if obj is mounted.
	obj can be either a partition object in /dev, or a mount point.
	
	Returns a dictionary with informations on the object if True, otherwise returns False.
	"""
		
	clss = m.execute("LANG=C mount | grep -w %s" % obj, custom_log=m.subprocess.PIPE)
	# Start
	clss.start()
	
	# Wait
	status = clss.wait()
	
	# output...
	output = clss.process.communicate()
	
	if not output or status != 0:
		return False
	else:
		# Split opts.
		for line in output:
			# It should be one.
			items = line.split(" ")
			return {"path":items[0], "mountpoint":items[2], "type":items[4], "options":items[-1].replace("(","").replace(")","").replace("\n","")}
Esempio n. 3
0
def check_distributions(obj=False):
	""" Checks all partitions in Device/Partition object to discover other distributions.
	If obj is not specified, returns a list of *all* distributions on *all* disks. """
	
	# Start os-prober
	clss = m.execute("LANG=C os-prober", custom_log=m.subprocess.PIPE)
	# Start
	clss.start()
	
	# Wait
	status = clss.wait()
	
	# output...
	output = clss.process.communicate()[0].split("\n")
	
	distribs = {}
		
	for line in output:
		if not line:
			continue
			
		line = line.split(":")
		if obj:
			# We should limit results to the ones that are relevant in obj.device.path.
			if not obj.path in line[0]:
				continue # Not a partition on obj.device; skip.

		distribs[line[0]] = line[1] # Add.
	
	#distribs = {"/dev/sdb1": "Inter Linux"}
	
	return distribs
Esempio n. 4
0
def check_distributions(obj=False):
	""" Checks all partitions in Device/Partition object to discover other distributions.
	If obj is not specified, returns a list of *all* distributions on *all* disks. """
	
	# Mount every unmounted partition otherwise os-prober won't detect anything
	mounted = []
	for disk in (disks.values() if not obj else [obj]):
		if disk == "notable":
			continue
		
		partitions = disk_partitions(disk)
		for partition in partitions:
			if "-" in partition.path or is_mounted(partition.path):
				# Already mounted or freespace
				continue
			
			try:
				mount_partition(parted_part=partition)
				mounted.append(partition)
			except:
				pass
	
	# Start os-prober
	clss = m.execute("LANG=C os-prober", custom_log=m.subprocess.PIPE)
	# Start
	clss.start()
	
	# Wait
	status = clss.wait()
	
	# output...
	output = clss.process.communicate()[0].split("\n")
	
	# Unmount previously mounted partitions
	for partition in mounted:
		umount(parted_part=partition)
	
	distribs = {}
		
	for line in output:
		if not line:
			continue
			
		line = line.split(":")
		if obj:
			# We should limit results to the ones that are relevant in obj.device.path.
			if not obj.path in line[0]:
				continue # Not a partition on obj.device; skip.
		
		# Handle EFI paths
		location = line[0]
		if "@" in location:
			location = location.split("@")[0]

		distribs[location] = line[1] # Add.
	
	#distribs = {"/dev/sdb1": "Inter Linux"}
	
	return distribs
Esempio n. 5
0
	def begin(self):
		""" Unsquashes squashimage to TARGET """
		
		proc = m.execute("unsquashfs -d %(destination)s -f -i -fr 10 -da 10 -n %(image)s" % {"destination":self.TARGET, "image":self.squashimage}, custom_log=m.subprocess.PIPE)
		# Start
		proc.start()
		
		# Return object to frontend. It should parse it and launch progressbar.
		return proc
Esempio n. 6
0
def new_table(obj, tabletype):
	""" Uses parted's mktable command to create a new partition table. """
	
	table = supported_tables[tabletype]
	device = obj
	
	prted = m.execute("parted -s %s mktable %s" % (obj.path, table))
	prted.start()
	
	# Return object to frontend
	return prted
Esempio n. 7
0
	def get_files(self):
		""" Get the number of files to be copied. """
		
		proc = m.execute("unsquashfs -d FROMHERE -l %s" % self.squashimage, custom_log=m.subprocess.PIPE, shell=False)
		# Start
		proc.start()
		
		# output...
		output = proc.process.communicate()[0].split("\n")
		
		if not proc.process.returncode == 0:
			# failed
			raise m.CmdError("Unable to get file list. Most likely the image doesn't exist.")
		
		return len(output)
Esempio n. 8
0
def resize_partition_for_real(obj, newLength, action, path=None, fs=None):
	""" Given a partition object and the new start and end, this
	will resize the partition's filesystem. """

	# newLength from MB to KB, rounded minus one
	newLengthKiB = int((newLength*1000)/1.024)-1 # KiB, needed by resize2fs
	newLength = int(newLength*1000)-1 # KB, used by conforming applications

	# Get filesystem
	if not fs:
		fs = obj.fileSystem.type
	if fs.startswith("ext"):
		# ext* filesystems uses resize2fs, which uses kibibytes even if
		# they call them kilobytes
		newLength = newLengthKiB
	
	# Get an appropriate resizer
	if fs in supported_resize:
		resizer = supported_resize[fs]
	else:
		m.verbose("Resizer unavailable for %s. This may be an issue ;)" % fs)
		return
	
	if not resizer:
		# Handled internally by parted
		obj.fileSystem.resize(obj.geometry)
		return
	
	if not path:
		path = obj.path
	
	_app = resizer[0]
	_opt = resizer[1] % {"device":path, "size":newLength, "mountpoint":"FIXME"}

	# Umount...
	if fs not in ("btrfs") and is_mounted(obj.path):
		umount(parted_part=obj)
	
	# BEGIN RESIZING!!!!111111!!!!!!!!!!!!!1111111111111111
	process = m.execute("%s %s" % (_app, _opt))
	process.start() # START!!!111111111!!!!!!!!!!!!!!!111111111111111
	
	# Return object to frontend.
	return process
Esempio n. 9
0
def format_partition_for_real(obj, fs):
	""" Uses mkfs.* to format partition. """	

	# Get an appropriate frontend
	frontend = get_supported_filesystems()[fs]
	
	_app = frontend[0] # Application (e.g /sbin/mkfs.ext4)
	_opt = frontend[1] # Options of the application.
	
	# Umount...
	if is_mounted(obj.path):
		umount(parted_part=obj)
	
	_opt = "%s %s" % (obj.path, _opt)
	
	# BEGIN FORMATTING!!!!111111!!!!!!!!!!!!!1111111111111111
	mkfs = m.execute("%s %s" % (_app, _opt))
	mkfs.start() # START!!!111111111!!!!!!!!!!!!!!!111111111111111
	
	# Return object to frontend, it should handle all.
	return mkfs