From 7e5b3c667c8b2342788294de8d30decc84c6db2b Mon Sep 17 00:00:00 2001 From: piotrj Date: Fri, 9 Feb 2024 17:52:16 +0100 Subject: [PATCH] error-proof time conversion --- src/core.py | 9 ++++++++- src/dude.py | 12 ++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/core.py b/src/core.py index e073a7a..dfcfcb2 100644 --- a/src/core.py +++ b/src/core.py @@ -45,6 +45,13 @@ from send2trash import send2trash +def localtime_catched(t): + try: + #mtime sometimes happens to be negative (Virtual box ?) + return localtime(t) + except: + return localtime(0) + def bytes_to_str(num): if num < 1024: return "%sB" % num @@ -940,7 +947,7 @@ def link_wrapper(self,\ LOG_DIR = "./test/log" Path(LOG_DIR).mkdir(parents=True,exist_ok=True) - log=LOG_DIR + sep + strftime('%Y_%m_%d_%H_%M_%S',localtime(time()) ) +'.log' + log=LOG_DIR + sep + strftime('%Y_%m_%d_%H_%M_%S',localtime_catched(time()) ) +'.log' print('log:',log) logging.basicConfig(level=logging.INFO,format='%(asctime)s %(levelname)s %(message)s', filename=log,filemode='w') diff --git a/src/dude.py b/src/dude.py index 85cdd25..76afb18 100755 --- a/src/dude.py +++ b/src/dude.py @@ -47,7 +47,7 @@ from fnmatch import fnmatch from shutil import rmtree -from time import sleep,strftime,localtime,time,perf_counter +from time import sleep,strftime,time,perf_counter import sys import logging @@ -3314,7 +3314,7 @@ def groups_show(self): self_groups_tree_item_to_data = self.groups_tree_item_to_data = {} dude_core_scanned_paths=dude_core.scanned_paths - + localtime_catched_local = localtime_catched for size,size_dict in dude_core.files_of_size_of_crc_items() : size_h = local_bytes_to_str(size) @@ -3346,7 +3346,7 @@ def groups_show(self): '',\ str(ctime),str(dev),str(inode),crc,\ '','',\ - strftime('%Y/%m/%d %H:%M:%S',localtime(ctime//1000000000)),self_FILE),tags='',text=dude_core_scanned_paths[pathnr] if show_full_paths else '',image=self_icon_nr[pathnr]) #DE_NANO= 1_000_000_000 + strftime('%Y/%m/%d %H:%M:%S',localtime_catched_local(ctime//1000000000)),self_FILE),tags='',text=dude_core_scanned_paths[pathnr] if show_full_paths else '',image=self_icon_nr[pathnr]) #DE_NANO= 1_000_000_000 #kind,crc,index_tuple #kind,crc,(pathnr,path,file,ctime,dev,inode) @@ -3479,7 +3479,7 @@ def tree_folder_update(self,arbitrary_path=None): current_folder_items_tagged_size=0 local_strftime = strftime - local_localtime = localtime + local_localtime_catched = localtime_catched folder_items=set() folder_items_add=folder_items.add @@ -3514,7 +3514,7 @@ def tree_folder_update(self,arbitrary_path=None): ctime,size_num = stat_res.st_ctime_ns,stat_res.st_size file_id=self_idfunc(inode,dev) - ctime_h = local_strftime('%Y/%m/%d %H:%M:%S',local_localtime(ctime//1000000000)) #DE_NANO + ctime_h = local_strftime('%Y/%m/%d %H:%M:%S',local_localtime_catched(ctime//1000000000)) #DE_NANO size_h=local_bytes_to_str(size_num) @@ -4857,7 +4857,7 @@ def show_homepage(self): #dont mix device id for different hosts in portable mode CACHE_DIR = sep.join([CACHE_DIR_DIR,node()]) - log_file = strftime('%Y_%m_%d_%H_%M_%S',localtime(time()) ) +'.txt' + log_file = strftime('%Y_%m_%d_%H_%M_%S',localtime_catched(time()) ) +'.txt' log=abspath(p_args.log[0]) if p_args.log else LOG_DIR + sep + log_file #LOG_LEVEL = logging.DEBUG if p_args.debug else logging.INFO