dotlocalslashbin 0.0.23__tar.gz → 0.0.24__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.
- {dotlocalslashbin-0.0.23 → dotlocalslashbin-0.0.24}/PKG-INFO +1 -1
- {dotlocalslashbin-0.0.23 → dotlocalslashbin-0.0.24}/src/dotlocalslashbin.py +31 -26
- {dotlocalslashbin-0.0.23 → dotlocalslashbin-0.0.24}/LICENSES/MPL-2.0.txt +0 -0
- {dotlocalslashbin-0.0.23 → dotlocalslashbin-0.0.24}/README.md +0 -0
- {dotlocalslashbin-0.0.23 → dotlocalslashbin-0.0.24}/pyproject.toml +0 -0
|
@@ -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.
|
|
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
|
-
|
|
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
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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("/"):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|