Skip to content

Commit

Permalink
error-proof time conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
PJDude committed Feb 9, 2024
1 parent d6c3508 commit 7e5b3c6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
9 changes: 8 additions & 1 deletion src/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down
12 changes: 6 additions & 6 deletions src/dude.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 7e5b3c6

Please sign in to comment.