dotlocalslashbin 0.0.22__py3-none-any.whl → 0.0.24__py3-none-any.whl

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,9 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dotlocalslashbin
3
- Version: 0.0.22
3
+ Version: 0.0.24
4
4
  Summary: Download and extract files to `~/.local/bin/`.
5
5
  Author-email: Keith Maxwell <keith.maxwell@gmail.com>
6
- Requires-Python: >=3.13
6
+ Requires-Python: >=3.11
7
7
  Description-Content-Type: text/markdown
8
8
  Classifier: Programming Language :: Python :: 3
9
9
  Classifier: License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)
@@ -0,0 +1,6 @@
1
+ dotlocalslashbin.py,sha256=9pHs1CJwCETotealCX_3HuwdkWc9tV-0QVdWHjSoVXg,6743
2
+ dotlocalslashbin-0.0.24.dist-info/METADATA,sha256=S_7yFfQQ6p7rUXYKgbB_MbR_awVrCax4iFfzqtABXqI,3225
3
+ dotlocalslashbin-0.0.24.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
4
+ dotlocalslashbin-0.0.24.dist-info/entry_points.txt,sha256=eK8C0lW2h7WAcr78hM-_OBrLotRptdLvjbnT7f67m34,58
5
+ dotlocalslashbin-0.0.24.dist-info/licenses/LICENSES/MPL-2.0.txt,sha256=ZqMQfVrWoFiqt1PqrCBHzLLtDjlGXdD-WETaPjANUXI,16727
6
+ dotlocalslashbin-0.0.24.dist-info/RECORD,,
dotlocalslashbin.py CHANGED
@@ -7,6 +7,7 @@
7
7
  # dependencies = []
8
8
  # ///
9
9
  """Download and extract files to `~/.local/bin/`."""
10
+ import gzip
10
11
  import tarfile
11
12
  from argparse import ArgumentParser, BooleanOptionalAction, Namespace
12
13
  from dataclasses import dataclass
@@ -14,7 +15,7 @@ from enum import Enum
14
15
  from hashlib import file_digest
15
16
  from pathlib import Path
16
17
  from shlex import split
17
- from shutil import copy
18
+ from shutil import copy, copyfileobj
18
19
  from stat import S_IEXEC
19
20
  from subprocess import run
20
21
  from tomllib import load
@@ -23,7 +24,7 @@ from urllib.request import urlopen
23
24
  from zipfile import ZipFile
24
25
 
25
26
 
26
- __version__ = "0.0.22"
27
+ __version__ = "0.0.24"
27
28
 
28
29
  _CACHE = Path("~/.cache/dotlocalslashbin/")
29
30
  _HOME = str(Path("~").expanduser())
@@ -38,7 +39,7 @@ class _CustomNamespace(Namespace):
38
39
  cache: Path
39
40
 
40
41
 
41
- Action = Enum("Action", ["command", "copy", "symlink", "untar", "unzip"])
42
+ Action = Enum("Action", ["command", "copy", "gunzip", "symlink", "untar", "unzip"])
42
43
 
43
44
 
44
45
  @dataclass(init=False)
@@ -123,19 +124,7 @@ def _process(item: Item) -> None:
123
124
 
124
125
  item.target.parent.mkdir(parents=True, exist_ok=True)
125
126
  item.target.unlink(missing_ok=True)
126
- if item.action == Action.copy:
127
- copy(item.downloaded, item.target)
128
- elif item.action == Action.symlink:
129
- item.target.symlink_to(item.downloaded)
130
- elif item.action == Action.unzip:
131
- with ZipFile(item.downloaded, "r") as file:
132
- file.extract(item.target.name, path=item.target.parent)
133
- elif item.action == Action.untar:
134
- _untar(item)
135
- elif item.action == Action.command and item.command is not None:
136
- kwargs = {"target": item.target, "downloaded": item.downloaded}
137
- run(split(item.command.format(**kwargs)), check=True)
138
-
127
+ _action(item)
139
128
  if not item.target.is_symlink():
140
129
  item.target.chmod(item.target.stat().st_mode | S_IEXEC)
141
130
 
@@ -172,21 +161,37 @@ def _download(item: Item) -> None:
172
161
  raise RuntimeError(msg)
173
162
 
174
163
 
175
- def _untar(item: Item) -> None:
176
- with tarfile.open(item.downloaded, "r") as file:
177
- for member in file.getmembers():
178
- if member.name in item.ignore:
179
- continue
180
- member.name = member.name.removeprefix(item.prefix)
181
- try:
182
- file.extract(member, path=item.target.parent, filter="tar")
183
- except TypeError: # before 3.11.4 e.g. Debian 12
184
- file.extract(member, path=item.target.parent)
164
+ def _action(item: Item) -> None:
165
+ if item.action == Action.copy:
166
+ copy(item.downloaded, item.target)
167
+ elif item.action == Action.symlink:
168
+ item.target.symlink_to(item.downloaded)
169
+ elif item.action == Action.unzip:
170
+ with ZipFile(item.downloaded, "r") as file:
171
+ file.extract(item.target.name, path=item.target.parent)
172
+ elif item.action == Action.gunzip:
173
+ with gzip.open(item.downloaded, "r") as fsrc, item.target.open("wb") as fdst:
174
+ copyfileobj(fsrc, fdst)
175
+ elif item.action == Action.untar:
176
+ with tarfile.open(item.downloaded, "r") as file:
177
+ for member in file.getmembers():
178
+ if member.name in item.ignore:
179
+ continue
180
+ member.name = member.name.removeprefix(item.prefix)
181
+ try:
182
+ file.extract(member, path=item.target.parent, filter="tar")
183
+ except TypeError: # before 3.11.4 e.g. Debian 12
184
+ file.extract(member, path=item.target.parent)
185
+ elif item.action == Action.command and item.command is not None:
186
+ cmd = item.command.format(target=item.target, downloaded=item.downloaded)
187
+ run(split(cmd), check=True)
185
188
 
186
189
 
187
190
  def _guess_action(item: Item) -> Action:
188
191
  if item.url.endswith((".tar.xz", ".tar.gz", ".tar")):
189
192
  guess = Action.untar
193
+ elif item.url.endswith((".gz",)):
194
+ guess = Action.gunzip
190
195
  elif item.url.endswith(".zip"):
191
196
  guess = Action.unzip
192
197
  elif item.url.startswith("/"):
@@ -1,6 +0,0 @@
1
- dotlocalslashbin.py,sha256=QZA1VBnHzecjxgy0j7J5VyuP7jRQIEvJGjB7viN8kSU,6462
2
- dotlocalslashbin-0.0.22.dist-info/METADATA,sha256=WDPy__mvGFBpq-yPmP-6cM9SeiVUMr-Z0NqDRJW64Fc,3225
3
- dotlocalslashbin-0.0.22.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
4
- dotlocalslashbin-0.0.22.dist-info/entry_points.txt,sha256=eK8C0lW2h7WAcr78hM-_OBrLotRptdLvjbnT7f67m34,58
5
- dotlocalslashbin-0.0.22.dist-info/licenses/LICENSES/MPL-2.0.txt,sha256=ZqMQfVrWoFiqt1PqrCBHzLLtDjlGXdD-WETaPjANUXI,16727
6
- dotlocalslashbin-0.0.22.dist-info/RECORD,,