From fc7151cc8459d6ef9fd18a792ab07a89500bcaff Mon Sep 17 00:00:00 2001 From: BananaFeet Date: Wed, 4 Nov 2020 22:49:35 -0800 Subject: [PATCH 1/2] Updated 'Type' to return the extension and now should display the file type. Still working on adding filename and fixing the formatting for file_size --- browserApp/model/file.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/browserApp/model/file.py b/browserApp/model/file.py index 54c88b9..e47c0a2 100644 --- a/browserApp/model/file.py +++ b/browserApp/model/file.py @@ -45,12 +45,12 @@ def get_info(self): if os.path.isfile(self.full_path): stat = os.stat(self.full_path) - data['type'] = "File" - # data['file_ext'] = # Retrieve file ext - data['file_size'] = str(stat.st_size) + " bytes" + data['Type'] = os.path.splitext(self.full_path)[1] # Get extension from filename + #data['file_name: '] = # Get filename + data['file_size'] = os.path.getsize(self.full_path) # store the file size in "12.23MB" format data['created'] = datetime.fromtimestamp(stat.st_ctime).strftime('%Y-%b-%d %H:%M') data['modified'] = datetime.fromtimestamp(stat.st_mtime).strftime('%Y-%b-%d %H:%M') - data['device'] = str(stat.st_dev) + #data['device'] = str(stat.st_dev) From 09c109946e0c7502c1e78a728f4781009e7911da Mon Sep 17 00:00:00 2001 From: BananaFeet Date: Sat, 7 Nov 2020 22:52:31 -0800 Subject: [PATCH 2/2] Refactored time formating into separate function. file_name and file_size are still a work in progress --- browserApp/model/file.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/browserApp/model/file.py b/browserApp/model/file.py index e47c0a2..6df5b4b 100644 --- a/browserApp/model/file.py +++ b/browserApp/model/file.py @@ -38,6 +38,10 @@ def get_child(self, n): return FileItem(os.path.join(self.full_path, self.file_list[n])) + def format_time(self, time_value): + '''Function for formating time''' + return datetime.fromtimestamp(time_value).strftime('%Y-%b-%d %H:%M') + def get_info(self): data = { 'full_path': self.full_path, @@ -45,11 +49,12 @@ def get_info(self): if os.path.isfile(self.full_path): stat = os.stat(self.full_path) + print(stat.st_ctime) data['Type'] = os.path.splitext(self.full_path)[1] # Get extension from filename - #data['file_name: '] = # Get filename + data['file_name: '] = os.path.splitext(self.full_path)[0] # Get filename data['file_size'] = os.path.getsize(self.full_path) # store the file size in "12.23MB" format - data['created'] = datetime.fromtimestamp(stat.st_ctime).strftime('%Y-%b-%d %H:%M') - data['modified'] = datetime.fromtimestamp(stat.st_mtime).strftime('%Y-%b-%d %H:%M') + data['created'] = self.format_time(stat.st_ctime) + data['modified'] = self.format_time(stat.st_mtime) #data['device'] = str(stat.st_dev)