dotlocalslashbin 0.0.11__tar.gz → 0.0.14__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
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: dotlocalslashbin
3
- Version: 0.0.11
3
+ Version: 0.0.14
4
4
  Summary: Download and extract files to `~/.local/bin/`.
5
5
  Author-email: Keith Maxwell <keith.maxwell@gmail.com>
6
6
  Description-Content-Type: text/markdown
@@ -16,6 +16,7 @@ Requires-Dist: reuse ; extra == "test"
16
16
  Requires-Dist: ruff ; extra == "test"
17
17
  Requires-Dist: twine ; extra == "test"
18
18
  Requires-Dist: usort ; extra == "test"
19
+ Requires-Dist: yamllint ; extra == "test"
19
20
  Project-URL: Home, https://github.com/maxwell-k/dotlocalslashbin/
20
21
  Provides-Extra: test
21
22
 
@@ -42,6 +43,7 @@ Optionally can:
42
43
  - invoke the target with an argument, for example `--version`
43
44
  - strip a prefix while extracting
44
45
  - ignore certain files while extracting
46
+ - clear the cache beforehand
45
47
 
46
48
  \* if the URL is an absolute path on the local file system; it is not downloaded
47
49
  to the cache.
@@ -21,6 +21,7 @@ Optionally can:
21
21
  - invoke the target with an argument, for example `--version`
22
22
  - strip a prefix while extracting
23
23
  - ignore certain files while extracting
24
+ - clear the cache beforehand
24
25
 
25
26
  \* if the URL is an absolute path on the local file system; it is not downloaded
26
27
  to the cache.
@@ -31,6 +31,7 @@ test = [
31
31
  "ruff",
32
32
  "twine",
33
33
  "usort",
34
+ "yamllint",
34
35
  ]
35
36
 
36
37
  [tool.ruff]
@@ -8,7 +8,12 @@
8
8
  # ///
9
9
  """Download and extract files to `~/.local/bin/`."""
10
10
  import tarfile
11
- from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser, Namespace
11
+ from argparse import (
12
+ ArgumentDefaultsHelpFormatter,
13
+ ArgumentParser,
14
+ BooleanOptionalAction,
15
+ Namespace,
16
+ )
12
17
  from dataclasses import dataclass
13
18
  from enum import Enum
14
19
  from hashlib import file_digest
@@ -23,8 +28,9 @@ from urllib.request import urlopen
23
28
  from zipfile import ZipFile
24
29
 
25
30
 
26
- __version__ = "0.0.11"
31
+ __version__ = "0.0.14"
27
32
 
33
+ _HOME = str(Path("~").expanduser())
28
34
  _OUTPUT = Path("~/.local/bin/")
29
35
  _SHA512_LENGTH = 128
30
36
 
@@ -32,7 +38,7 @@ _SHA512_LENGTH = 128
32
38
  class _CustomNamespace(Namespace):
33
39
  output: Path
34
40
  input: Path
35
- downloaded: Path
41
+ cache: Path
36
42
 
37
43
 
38
44
  Action = Enum("Action", ["command", "copy", "symlink", "untar", "unzip"])
@@ -48,7 +54,7 @@ class Item:
48
54
  action: Action
49
55
  downloaded: Path
50
56
  expected: str | None
51
- version: str | None
57
+ version: str
52
58
  prefix: str
53
59
  command: str | None
54
60
  ignore: set
@@ -58,6 +64,10 @@ def main() -> int:
58
64
  """Parse command line arguments and download each file."""
59
65
  args = _parse_args()
60
66
 
67
+ if args.clear:
68
+ for path in args.cache.expanduser().iterdir():
69
+ path.unlink()
70
+
61
71
  with args.input.expanduser().open("rb") as file:
62
72
  data = load(file)
63
73
 
@@ -69,7 +79,7 @@ def main() -> int:
69
79
  item.target = Path(record.get("target", default)).expanduser()
70
80
  item.ignore = record.get("ignore", set())
71
81
  item.expected = record.get("expected", None)
72
- item.version = record.get("version", None)
82
+ item.version = record.get("version", "")
73
83
  item.prefix = record.get("prefix", "")
74
84
  item.command = record.get("command", None)
75
85
 
@@ -79,7 +89,7 @@ def main() -> int:
79
89
  item.action = _guess_action(item)
80
90
 
81
91
  if item.url.startswith("https://"):
82
- item.downloaded = args.downloaded.expanduser() / item.url.rsplit("/", 1)[1]
92
+ item.downloaded = args.cache.expanduser() / item.url.rsplit("/", 1)[1]
83
93
  else:
84
94
  item.downloaded = Path(item.url)
85
95
  try:
@@ -88,8 +98,9 @@ def main() -> int:
88
98
  print(f"Error {e.code} downloading {e.url}")
89
99
  return 1
90
100
 
91
- arg0 = item.name if args.output == _OUTPUT else str(item.target.absolute())
92
- print(" ".join(("#" if item.version else "$", arg0, item.version or "")))
101
+ arg0 = str(item.target.absolute())
102
+ prompt = "#" if item.version else "$"
103
+ print(" ".join((prompt, arg0.replace(_HOME, "~"), item.version)))
93
104
  if item.version:
94
105
  run([arg0, item.version], check=True)
95
106
  print()
@@ -140,9 +151,16 @@ def _parse_args() -> _CustomNamespace:
140
151
  parser.add_argument("--input", default="bin.toml", help=help_, type=Path)
141
152
  help_ = "Target directory"
142
153
  parser.add_argument("--output", default=_OUTPUT, help=help_, type=Path)
143
- help_ = "Output directory"
154
+ help_ = "Cache directory"
144
155
  default = "~/.cache/dotlocalslashbin/"
145
- parser.add_argument("--downloaded", default=default, help=help_, type=Path)
156
+ parser.add_argument("--cache", default=default, help=help_, type=Path)
157
+ help_ = "Clear the cache directory first"
158
+ parser.add_argument(
159
+ "--clear",
160
+ default=False,
161
+ action=BooleanOptionalAction,
162
+ help=help_,
163
+ )
146
164
  return parser.parse_args(namespace=_CustomNamespace())
147
165
 
148
166