def getPath(self): ''' A method which gets the path of the device on which to build the system.''' # Create the disk variable disk = None # Get the disk which we are going to use while disk is None: # Prompt the user to give some input Output.text('Enter the disk on which to build Wander (/dev/sdX):', False) # See if we can use the disk try: # And store the input disk, device = self.getDevice(self.getDisk(input())) except (DeviceException, IOException): # If we catch an exception, the disk is not available disk = None # And return what we have return disk, device
def printPartitions(self, disk, device): ''' The method which prints all of the partitions on a device, and creates a list of the partitions to reference later.''' # Create a variable to store the list of partitions partitions = list() # Print a list of partitions on the disk Output.text(f'The device {device.path} contains the following ' + 'partitions:') for partition in disk.partitions: # Store the partition in a list partitions.append(partition.number) # Get the partition filesystem information filesystem = partition.fileSystem filesystem = filesystem.type if filesystem else 'unknown' Output.text( f'Partition {partition.number} ({partition.path})\n' + f' size: {round(partition.getSize() / 1024, 2)} GiB\n' + f' type: {filesystem}') # And return what we have return partitions
def verify(self): ''' The verify method, which ensures that the partition is correctly selected and properly formatted.''' # First, check if we are in a docker container if docker(): return True # Otherwise, tell the user what's happening Output.header('Checking partition system...') # Create the disk variable disk, device = self.getPath() # Store the partition to use partition = self.getPartition(self.printPartitions(disk, device), device) # Store the partition that we're using self.path = device.path + str(partition) # Let the user know exactly what the path is Output.text('Wander will be built on ' + self.path + '.') # Log the filesystem Output.log( Output.TESTING, 'Checking that the filesystem of ' + self.path + ' is ext4.') # Store the unknown filesystem filesystem = None # Check the file system for partition in disk.partitions: # Check that the paths match if partition.path == self.path: # Store the file system information filesystem = partition.fileSystem filesystem = filesystem.type if filesystem else None # And close break # Get our result result = filesystem == 'ext4' # Log the filesystem Output.log( Output.PASSED if result else Output.FAILED, 'Checking that' + ' the filesystem of ' + self.path + ' is ext4.') print() # Inform the user of the status Output.footer(result, "Checking partition system") # And return the result return result
def getPartition(self, partitions, device): ''' A method which returns the partition of the device on which to build the system.''' # Create the partition variable partition = None # Get the partition which we are going to use while partition is None: # Prompt the user to give some input Output.text( f'Enter the partition of {device.path} on which to' + ' build Wander:', False) # Get the partition input partition = int(input()) # And check if the partition is valid if partition not in partitions: partition = None # And return what we have return partition