officecli-patch 0.1.1__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.
- officecli_patch-0.1.1/PKG-INFO +7 -0
- officecli_patch-0.1.1/pyproject.toml +3 -0
- officecli_patch-0.1.1/setup.cfg +4 -0
- officecli_patch-0.1.1/setup.py +12 -0
- officecli_patch-0.1.1/src/officecli_patch/__init__.py +1 -0
- officecli_patch-0.1.1/src/officecli_patch/_release.py +1 -0
- officecli_patch-0.1.1/src/officecli_patch/launcher.py +89 -0
- officecli_patch-0.1.1/src/officecli_patch.egg-info/PKG-INFO +7 -0
- officecli_patch-0.1.1/src/officecli_patch.egg-info/SOURCES.txt +10 -0
- officecli_patch-0.1.1/src/officecli_patch.egg-info/dependency_links.txt +1 -0
- officecli_patch-0.1.1/src/officecli_patch.egg-info/entry_points.txt +2 -0
- officecli_patch-0.1.1/src/officecli_patch.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from os import environ
|
|
2
|
+
from setuptools import find_packages, setup
|
|
3
|
+
|
|
4
|
+
setup(
|
|
5
|
+
name="officecli-patch",
|
|
6
|
+
version=environ.get("OFFICECLI_PATCH_VERSION", "0.2.0"),
|
|
7
|
+
description="Cross-platform launcher for officecli-patch GitHub Release binaries",
|
|
8
|
+
python_requires=">=3.9",
|
|
9
|
+
package_dir={"": "src"},
|
|
10
|
+
packages=find_packages("src"),
|
|
11
|
+
entry_points={"console_scripts": ["officecli-patch=officecli_patch.launcher:main"]},
|
|
12
|
+
)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""PyPI launcher package for officecli-patch."""
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
REPOSITORY = 'bruce601080102/officecli-patch'
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"""Install and run the matching officecli-patch GitHub Release asset."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import hashlib
|
|
5
|
+
import os
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
import platform
|
|
8
|
+
import subprocess
|
|
9
|
+
import sys
|
|
10
|
+
from urllib.request import Request, urlopen
|
|
11
|
+
|
|
12
|
+
from ._release import REPOSITORY
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def asset_name() -> str:
|
|
16
|
+
system = platform.system().lower()
|
|
17
|
+
machine = platform.machine().lower()
|
|
18
|
+
arch = "x64" if machine in {"amd64", "x86_64"} else "arm64" if machine in {"arm64", "aarch64"} else None
|
|
19
|
+
if arch is None:
|
|
20
|
+
raise RuntimeError(f"不支援的 CPU 架構:{platform.machine()}")
|
|
21
|
+
if system == "windows":
|
|
22
|
+
return f"officecli-patch-win-{arch}.exe"
|
|
23
|
+
if system == "darwin":
|
|
24
|
+
return f"officecli-patch-mac-{arch}"
|
|
25
|
+
if system == "linux":
|
|
26
|
+
libc = platform.libc_ver()[0].lower()
|
|
27
|
+
try:
|
|
28
|
+
ldd = subprocess.run(["ldd", "--version"], capture_output=True, text=True, check=False).stdout.lower()
|
|
29
|
+
except OSError:
|
|
30
|
+
ldd = ""
|
|
31
|
+
family = "linux-alpine" if "musl" in libc or "musl" in ldd else "linux"
|
|
32
|
+
return f"officecli-patch-{family}-{arch}"
|
|
33
|
+
raise RuntimeError(f"不支援的作業系統:{platform.system()}")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def cache_dir() -> Path:
|
|
37
|
+
base = Path(os.getenv("LOCALAPPDATA", "")) if os.name == "nt" else Path(os.getenv("XDG_CACHE_HOME", Path.home() / ".cache"))
|
|
38
|
+
return base / "officecli-patch" / "bin"
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def download(url: str, target: Path) -> None:
|
|
42
|
+
request = Request(url, headers={"User-Agent": "officecli-patch-pypi"})
|
|
43
|
+
with urlopen(request, timeout=180) as response, target.open("wb") as output:
|
|
44
|
+
while block := response.read(1024 * 1024):
|
|
45
|
+
output.write(block)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def expected_checksum(name: str) -> str:
|
|
49
|
+
request = Request(
|
|
50
|
+
f"https://github.com/{REPOSITORY}/releases/latest/download/checksums.txt",
|
|
51
|
+
headers={"User-Agent": "officecli-patch-pypi"},
|
|
52
|
+
)
|
|
53
|
+
with urlopen(request, timeout=60) as response:
|
|
54
|
+
for line in response.read().decode("utf-8").splitlines():
|
|
55
|
+
digest, filename = line.split(maxsplit=1)
|
|
56
|
+
if filename.strip().lstrip("*") == name:
|
|
57
|
+
return digest.lower()
|
|
58
|
+
raise RuntimeError(f"Release checksums.txt 找不到 {name}")
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def binary() -> Path:
|
|
62
|
+
if REPOSITORY.startswith("CHANGE_ME/"):
|
|
63
|
+
raise RuntimeError("此 PyPI launcher 尚未設定 GitHub repository。請使用正式發布的 wheel。")
|
|
64
|
+
name = asset_name()
|
|
65
|
+
target = cache_dir() / name
|
|
66
|
+
if target.is_file():
|
|
67
|
+
return target
|
|
68
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
69
|
+
temporary = target.with_suffix(target.suffix + ".download")
|
|
70
|
+
try:
|
|
71
|
+
download(f"https://github.com/{REPOSITORY}/releases/latest/download/{name}", temporary)
|
|
72
|
+
actual = hashlib.sha256(temporary.read_bytes()).hexdigest()
|
|
73
|
+
if actual != expected_checksum(name):
|
|
74
|
+
raise RuntimeError(f"下載檔案的 SHA-256 驗證失敗:{name}")
|
|
75
|
+
temporary.replace(target)
|
|
76
|
+
if os.name != "nt":
|
|
77
|
+
target.chmod(0o755)
|
|
78
|
+
finally:
|
|
79
|
+
temporary.unlink(missing_ok=True)
|
|
80
|
+
return target
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def main() -> None:
|
|
84
|
+
try:
|
|
85
|
+
result = subprocess.run([str(binary()), *sys.argv[1:]])
|
|
86
|
+
except (OSError, RuntimeError) as error:
|
|
87
|
+
print(f"officecli-patch: {error}", file=sys.stderr)
|
|
88
|
+
raise SystemExit(1)
|
|
89
|
+
raise SystemExit(result.returncode)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
pyproject.toml
|
|
2
|
+
setup.py
|
|
3
|
+
src/officecli_patch/__init__.py
|
|
4
|
+
src/officecli_patch/_release.py
|
|
5
|
+
src/officecli_patch/launcher.py
|
|
6
|
+
src/officecli_patch.egg-info/PKG-INFO
|
|
7
|
+
src/officecli_patch.egg-info/SOURCES.txt
|
|
8
|
+
src/officecli_patch.egg-info/dependency_links.txt
|
|
9
|
+
src/officecli_patch.egg-info/entry_points.txt
|
|
10
|
+
src/officecli_patch.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
officecli_patch
|