Skip to content

Commit de7ea79

Browse files
committed
Update diskover.py fixed datimetime utc deprecation warnings in python 3.12
Update diskover.py fixed datimetime utc deprecation warnings in python 3.12
1 parent e18ecee commit de7ea79

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

diskover/diskover.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import re
2626
import warnings
2727
import signal
28-
from datetime import datetime, timedelta
28+
from datetime import datetime, timedelta, timezone
2929
from threading import Thread, Lock, current_thread
3030
from concurrent import futures
3131
from queue import Queue
@@ -475,7 +475,7 @@ def get_tree_size(executor, thread, root, top, path, sizes, inodes, depth=0, max
475475

476476
# check for invalid time stamps
477477
try:
478-
mtime = datetime.utcfromtimestamp(int(f_stat.st_mtime)).isoformat()
478+
mtime = datetime.fromtimestamp(int(f_stat.st_mtime), timezone.utc).isoformat()
479479
except ValueError:
480480
logmsg = '[{0}] MTIME TIMESTAMP WARNING {1}'.format(thread, os.path.join(parent_path, file_name))
481481
logger.warning(logmsg)
@@ -486,7 +486,7 @@ def get_tree_size(executor, thread, root, top, path, sizes, inodes, depth=0, max
486486
pass
487487

488488
try:
489-
atime = datetime.utcfromtimestamp(int(f_stat.st_atime)).isoformat()
489+
atime = datetime.fromtimestamp(int(f_stat.st_atime), tz=timezone.utc).isoformat()
490490
except ValueError:
491491
logmsg = '[{0}] ATIME TIMESTAMP WARNING {1}'.format(thread, os.path.join(parent_path, file_name))
492492
logger.warning(logmsg)
@@ -497,7 +497,7 @@ def get_tree_size(executor, thread, root, top, path, sizes, inodes, depth=0, max
497497
pass
498498

499499
try:
500-
ctime = datetime.utcfromtimestamp(int(f_stat.st_ctime)).isoformat()
500+
ctime = datetime.fromtimestamp(int(f_stat.st_ctime), timezone.utc).isoformat()
501501
except ValueError:
502502
logmsg = '[{0}] CTIME TIMESTAMP WARNING {1}'.format(thread, os.path.join(parent_path, file_name))
503503
logger.warning(logmsg)
@@ -635,7 +635,7 @@ def get_tree_size(executor, thread, root, top, path, sizes, inodes, depth=0, max
635635

636636
# handle timestamp errors in s3fs and possibly other fuse mounts
637637
try:
638-
mtime = datetime.utcfromtimestamp(int(d_stat.st_mtime)).isoformat()
638+
mtime = datetime.fromtimestamp(int(d_stat.st_mtime), timezone.utc).isoformat()
639639
except ValueError:
640640
logmsg = '[{0}] MTIME TIMESTAMP WARNING {1}'.format(thread, os.path.join(parent_path, file_name))
641641
logger.warning(logmsg)
@@ -646,7 +646,7 @@ def get_tree_size(executor, thread, root, top, path, sizes, inodes, depth=0, max
646646
pass
647647

648648
try:
649-
atime = datetime.utcfromtimestamp(int(d_stat.st_atime)).isoformat()
649+
atime = datetime.fromtimestamp(int(d_stat.st_atime), timezone.utc).isoformat()
650650
except ValueError:
651651
logmsg = '[{0}] ATIME TIMESTAMP WARNING {1}'.format(thread, os.path.join(parent_path, file_name))
652652
logger.warning(logmsg)
@@ -657,7 +657,7 @@ def get_tree_size(executor, thread, root, top, path, sizes, inodes, depth=0, max
657657
pass
658658

659659
try:
660-
ctime = datetime.utcfromtimestamp(int(d_stat.st_ctime)).isoformat()
660+
ctime = datetime.fromtimestamp(int(d_stat.st_ctime), timezone.utc).isoformat()
661661
except ValueError:
662662
logmsg = '[{0}] CTIME TIMESTAMP WARNING {1}'.format(thread, os.path.join(parent_path, file_name))
663663
logger.warning(logmsg)
@@ -838,7 +838,7 @@ def crawl_tree(root, top, maxdepth, sizes, inodes):
838838
if config['LOGTOFILE']: logger_warn.critical(logmsg, exc_info=1)
839839
close_app_critical_error()
840840
scandir_walk_time = time.time() - scandir_walk_start
841-
end_time = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S")
841+
end_time = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S")
842842

843843
# check if directory is empty or all files/dirs excluded
844844
if not root in sizes:
@@ -903,7 +903,7 @@ def banner():
903903
'I didn\'t even know that was there.',
904904
'Bringing light to the darkness.']
905905

906-
print(r"""\u001b[31;1m
906+
print("""\u001b[31;1m
907907
_ _ _
908908
| (_) | |
909909
__| |_ ___| | _______ _____ _ __
@@ -1238,7 +1238,7 @@ def log_setup():
12381238
skipfilecount[tree_dir] = 0
12391239
total_doc_count[tree_dir] = 0
12401240
inodecount[tree_dir] = 0
1241-
start_time = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S")
1241+
start_time = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S")
12421242
index_info_crawlstart(es, options.index, tree_dir, start_time, version, alt_scanner)
12431243

12441244
# start thread for stat logging

0 commit comments

Comments
 (0)