delayed-rm 2.9.2__tar.gz → 2.10.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: delayed_rm
3
- Version: 2.9.2
3
+ Version: 2.10.0
4
4
  Summary: Ever wish you had a few minutes to undo an rm? Now you do!
5
5
  License: GPLv3
6
6
  Project-URL: Homepage, https://github.com/zwimer/delayed_rm
@@ -8,11 +8,12 @@ import subprocess
8
8
  import argparse
9
9
  import tempfile
10
10
  import shutil
11
+ import math
11
12
  import time
12
13
  import sys
13
14
 
14
15
 
15
- __version__ = "2.9.2"
16
+ __version__ = "2.10.0"
16
17
 
17
18
 
18
19
  #
@@ -51,6 +52,16 @@ class _Secret:
51
52
  #
52
53
 
53
54
 
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
+
54
65
  def _eprint(e: str | BaseException) -> None:
55
66
  """
56
67
  Print e to stderr
@@ -213,7 +224,7 @@ def delayed_rm_raw(delay: int, log: bool, r: bool, f: bool, paths: list[Path]) -
213
224
  if r or f or paths:
214
225
  _eprint("--log may not be used with other arguments")
215
226
  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")
217
228
  return True
218
229
  if not paths:
219
230
  _eprint("nothing to remove")
@@ -229,25 +240,20 @@ def delayed_rm_raw(delay: int, log: bool, r: bool, f: bool, paths: list[Path]) -
229
240
  return True
230
241
 
231
242
 
232
- def main(prog: str, *args: str) -> bool:
233
- base: str = Path(prog).name
234
- parser = argparse.ArgumentParser(prog=base)
235
- parser.add_argument("--version", action="version", version=f"{base} {__version__}")
243
+ def cli() -> None:
244
+ """
245
+ delayed_rm CLI
246
+ """
247
+ parser = argparse.ArgumentParser()
248
+ parser.add_argument("--version", action="version", version=f"{parser.prog} {__version__}")
236
249
  parser.add_argument("--delay", "--ttl", type=int, default=900, help="The deletion delay in seconds")
237
250
  parser.add_argument(
238
- "--log", action="store_true", help=f"Show {base}'s log files; may not be used with other arguments"
251
+ "--log", action="store_true", help=f"Show {parser.prog}'s log files; may not be used with other arguments"
239
252
  )
240
253
  parser.add_argument("-r", action="store_true", help="rm -r; must use -f with this")
241
254
  parser.add_argument("-f", action="store_true", help="rm -f; must use -r with this")
242
255
  parser.add_argument("paths", type=Path, nargs="*", help="The items to delete")
243
- return not delayed_rm_raw(**vars(parser.parse_args(args)))
244
-
245
-
246
- def cli() -> None:
247
- """
248
- delayed_rm CLI
249
- """
250
- sys.exit(main(*sys.argv))
256
+ sys.exit(not delayed_rm_raw(**vars(parser.parse_args())))
251
257
 
252
258
 
253
259
  #
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: delayed_rm
3
- Version: 2.9.2
3
+ Version: 2.10.0
4
4
  Summary: Ever wish you had a few minutes to undo an rm? Now you do!
5
5
  License: GPLv3
6
6
  Project-URL: Homepage, https://github.com/zwimer/delayed_rm
File without changes
File without changes
File without changes
File without changes