Skip to content

Commit

Permalink
Log file show size
Browse files Browse the repository at this point in the history
  • Loading branch information
zwimer committed Oct 5, 2024
1 parent aada99a commit 58d4ab5
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions delayed_rm/delayed_rm.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
import argparse
import tempfile
import shutil
import math
import time
import sys


__version__ = "2.9.3"
__version__ = "2.10.0"


#
Expand Down Expand Up @@ -51,6 +52,16 @@ class _Secret:
#


def _size(p: Path) -> str:
"""
Get file size as a human readable string
"""
s = p.stat().st_size
lg = int(math.log(s, 1000))
si = " KMGT"[lg].replace(" ", "")
return f"{round(s/(1000**lg))} {si}B"


def _eprint(e: str | BaseException) -> None:
"""
Print e to stderr
Expand Down Expand Up @@ -213,7 +224,7 @@ def delayed_rm_raw(delay: int, log: bool, r: bool, f: bool, paths: list[Path]) -
if r or f or paths:
_eprint("--log may not be used with other arguments")
return False
print(f"{log_f.read_text()}Log file: {log_f}" if log_f.exists() else "Log is empty")
print(f"{log_f.read_text()}Log file ({_size(log_f)}): {log_f}" if log_f.exists() else "Log is empty")
return True
if not paths:
_eprint("nothing to remove")
Expand Down

0 comments on commit 58d4ab5

Please sign in to comment.