Skip to content

Commit 58d4ab5

Browse files
committed
Log file show size
1 parent aada99a commit 58d4ab5

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

delayed_rm/delayed_rm.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
import argparse
99
import tempfile
1010
import shutil
11+
import math
1112
import time
1213
import sys
1314

1415

15-
__version__ = "2.9.3"
16+
__version__ = "2.10.0"
1617

1718

1819
#
@@ -51,6 +52,16 @@ class _Secret:
5152
#
5253

5354

55+
def _size(p: Path) -> str:
56+
"""
57+
Get file size as a human readable string
58+
"""
59+
s = p.stat().st_size
60+
lg = int(math.log(s, 1000))
61+
si = " KMGT"[lg].replace(" ", "")
62+
return f"{round(s/(1000**lg))} {si}B"
63+
64+
5465
def _eprint(e: str | BaseException) -> None:
5566
"""
5667
Print e to stderr
@@ -213,7 +224,7 @@ def delayed_rm_raw(delay: int, log: bool, r: bool, f: bool, paths: list[Path]) -
213224
if r or f or paths:
214225
_eprint("--log may not be used with other arguments")
215226
return False
216-
print(f"{log_f.read_text()}Log file: {log_f}" if log_f.exists() else "Log is empty")
227+
print(f"{log_f.read_text()}Log file ({_size(log_f)}): {log_f}" if log_f.exists() else "Log is empty")
217228
return True
218229
if not paths:
219230
_eprint("nothing to remove")

0 commit comments

Comments
 (0)