dotlocalslashbin 0.0.3__tar.gz → 0.0.5__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.3 → dotlocalslashbin-0.0.5}/PKG-INFO +1 -1
- {dotlocalslashbin-0.0.3 → dotlocalslashbin-0.0.5}/src/dotlocalslashbin.py +36 -20
- {dotlocalslashbin-0.0.3 → dotlocalslashbin-0.0.5}/LICENSES/MPL-2.0.txt +0 -0
- {dotlocalslashbin-0.0.3 → dotlocalslashbin-0.0.5}/README.md +0 -0
- {dotlocalslashbin-0.0.3 → dotlocalslashbin-0.0.5}/pyproject.toml +0 -0
|
@@ -18,16 +18,40 @@ from shutil import copy
|
|
|
18
18
|
from stat import S_IEXEC
|
|
19
19
|
from subprocess import run
|
|
20
20
|
from tomllib import load
|
|
21
|
+
from urllib.error import HTTPError
|
|
21
22
|
from urllib.request import urlopen
|
|
22
23
|
from zipfile import ZipFile
|
|
23
24
|
|
|
24
25
|
|
|
25
|
-
__version__ = "0.0.
|
|
26
|
+
__version__ = "0.0.5"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class CustomNamespace(Namespace):
|
|
30
|
+
output: Path
|
|
31
|
+
input: Path
|
|
32
|
+
downloaded: Path
|
|
33
|
+
completions: Path
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def parse_args():
|
|
37
|
+
parser = ArgumentParser(prog=Path(__file__).name, formatter_class=formatter_class)
|
|
38
|
+
parser.add_argument("--version", action="version", version=__version__)
|
|
39
|
+
help_ = "TOML specification"
|
|
40
|
+
parser.add_argument("--input", default="bin.toml", help=help_, type=Path)
|
|
41
|
+
help_ = "Target directory"
|
|
42
|
+
parser.add_argument("--output", default="~/.local/bin/", help=help_, type=Path)
|
|
43
|
+
help_ = "Download directory"
|
|
44
|
+
default = "~/.cache/dotlocalslashbin/"
|
|
45
|
+
parser.add_argument("--downloaded", default=default, help=help_, type=Path)
|
|
46
|
+
help_ = "Directory for ZSH completions"
|
|
47
|
+
default = "~/.local/share/zsh/site-functions/"
|
|
48
|
+
parser.add_argument("--completions", default=default, help=help_, type=Path)
|
|
49
|
+
return parser.parse_args(namespace=CustomNamespace)
|
|
26
50
|
|
|
27
51
|
|
|
28
52
|
@contextmanager
|
|
29
53
|
def _download(
|
|
30
|
-
args:
|
|
54
|
+
args: type[CustomNamespace],
|
|
31
55
|
*,
|
|
32
56
|
name: str,
|
|
33
57
|
url: str,
|
|
@@ -57,7 +81,7 @@ def _download(
|
|
|
57
81
|
assert target is not None
|
|
58
82
|
|
|
59
83
|
if url.startswith("https://"):
|
|
60
|
-
downloaded =
|
|
84
|
+
downloaded = args.downloaded.expanduser() / url.rsplit("/", 1)[1]
|
|
61
85
|
downloaded.parent.mkdir(parents=True, exist_ok=True)
|
|
62
86
|
if not downloaded.is_file():
|
|
63
87
|
with urlopen(url) as fp, downloaded.open("wb") as dp:
|
|
@@ -116,7 +140,7 @@ def _download(
|
|
|
116
140
|
member.path = member.path.removeprefix(prefix)
|
|
117
141
|
if member.path in ignore:
|
|
118
142
|
continue
|
|
119
|
-
file.extract(member, path=target.parent)
|
|
143
|
+
file.extract(member, path=target.parent, filter="tar")
|
|
120
144
|
elif action == "command" and command is not None:
|
|
121
145
|
kwargs = dict(target=target, downloaded=downloaded)
|
|
122
146
|
run(split(command.format(**kwargs)), check=True)
|
|
@@ -127,7 +151,7 @@ def _download(
|
|
|
127
151
|
target.chmod(target.stat().st_mode | S_IEXEC)
|
|
128
152
|
|
|
129
153
|
if completions:
|
|
130
|
-
output =
|
|
154
|
+
output = args.completions.expanduser() / f"_{target.name}"
|
|
131
155
|
output.parent.mkdir(parents=True, exist_ok=True)
|
|
132
156
|
kwargs = dict(target=target) # target may not be on PATH
|
|
133
157
|
with output.open("w") as file:
|
|
@@ -141,19 +165,7 @@ def _download(
|
|
|
141
165
|
|
|
142
166
|
|
|
143
167
|
def main() -> int:
|
|
144
|
-
|
|
145
|
-
parser.add_argument("--version", action="version", version=__version__)
|
|
146
|
-
help_ = "TOML specification"
|
|
147
|
-
parser.add_argument("--input", default="bin.toml", help=help_, type=Path)
|
|
148
|
-
help_ = "Target directory"
|
|
149
|
-
parser.add_argument("--output", default="~/.local/bin/", help=help_, type=Path)
|
|
150
|
-
help_ = "Download directory"
|
|
151
|
-
default = "~/.cache/dotlocalslashbin/"
|
|
152
|
-
parser.add_argument("--downloaded", default=default, help=help_)
|
|
153
|
-
help_ = "Directory for ZSH completions"
|
|
154
|
-
default = "~/.local/share/zsh/site-functions/"
|
|
155
|
-
parser.add_argument("--completions", default=default, help=help_)
|
|
156
|
-
args = parser.parse_args()
|
|
168
|
+
args = parse_args()
|
|
157
169
|
|
|
158
170
|
with args.input.expanduser().open("rb") as file:
|
|
159
171
|
data = load(file)
|
|
@@ -162,8 +174,12 @@ def main() -> int:
|
|
|
162
174
|
kwargs["name"] = name
|
|
163
175
|
if "target" in kwargs:
|
|
164
176
|
kwargs["target"] = Path(kwargs["target"])
|
|
165
|
-
|
|
166
|
-
|
|
177
|
+
try:
|
|
178
|
+
with _download(args, **kwargs) as (downloaded, target):
|
|
179
|
+
pass
|
|
180
|
+
except HTTPError as e:
|
|
181
|
+
print(f"Error {e.code} downloading {e.url}")
|
|
182
|
+
return 1
|
|
167
183
|
|
|
168
184
|
return 0
|
|
169
185
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|