Question: I need help making this print out using PrettyTable in Python. I can't quite figure out the pieces I'm missing. It has to be in
I need help making this print out using PrettyTable in Python. I can't quite figure out the pieces I'm missing. It has to be in PrettyTable as well. I can't just have the values print out. Any help is greatly appreciated!
''' Import Standard Libraries ''' import os from binascii import hexlify from time import ctime
''' Import 3rd Party Libraries''' from hashing import HashFile # Note HashFile.py need to be in the same folder as your script
from prettytable import PrettyTable tbl = PrettyTable(['Path', 'FileSize', 'Hash', 'LastModified', 'FileHeader', 'Status', 'Error'])
class FileProcessor: ''' Class to Create User Dictionary'''
def __init__(self, fileName): if os.path.isfile(fileName): self.filePath = fileName # You will add code here to extract the following information self.lastModifiedTime = 'modTime' self.fileSize = 'FileSize' self.md5Hash = 'md5' self.fileHeader = 'FileHeader' self.status = 'Status' self.errorInfo = 'Error' tbl.add_row([fileName, 'modTime', ' md5',' modTime', 'FileHeader', 'Status', 'Error']) def GetFileMetaData(self): # You will add code here to retrun the required values # think about the container type you might return with the required values stats = os.stat(fileName) self.filePath = os.path.abspath() self.lastModifiedTime = stats.st_mtime(stats) self.fileSize = os.path.getsize(fileName) self.md5Hash = HashFile(fileName) self.fileHeader = hexlify(fileName) self.status = os.stat_result self.errorInfo = os.error return def GetFileHeader(self):
with open(fileName, 'rb') as binFile:
header = binFile.read(20)
self.fileHeader = hexlify(header)
def main(): print(" Assignment-4 ") dirPath = input("Enter a valid directory path: ") ''' Process all the files in the path ''' for root, dirs, files in os.walk(dirPath): for fileName in files: path = os.path.join(root, fileName) fullPath = os.path.abspath(path) file_processor = FileProcessor(fullPath) if __name__ == '__main__': main() resultString = tbl.get_string() print(resultString)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
