zelpi-kit 0.1.0__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.
- zelpi_kit/__init__.py +3 -0
- zelpi_kit/__main__.py +5 -0
- zelpi_kit/cli.py +282 -0
- zelpi_kit/env.py +218 -0
- zelpi_kit/install.py +350 -0
- zelpi_kit/net.py +151 -0
- zelpi_kit/run.py +59 -0
- zelpi_kit/store.py +293 -0
- zelpi_kit/wheel.py +164 -0
- zelpi_kit-0.1.0.dist-info/METADATA +58 -0
- zelpi_kit-0.1.0.dist-info/RECORD +14 -0
- zelpi_kit-0.1.0.dist-info/WHEEL +5 -0
- zelpi_kit-0.1.0.dist-info/entry_points.txt +2 -0
- zelpi_kit-0.1.0.dist-info/top_level.txt +1 -0
zelpi_kit/store.py
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
"""ZELPI_HOME layout, atomic JSON files, the token file, OS locks. Nothing here imports kit code."""
|
|
2
|
+
import errno
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
import re
|
|
6
|
+
import shutil
|
|
7
|
+
import stat
|
|
8
|
+
|
|
9
|
+
VER_RE = re.compile(r"(?:0|[1-9][0-9]{0,3})(?:\.(?:0|[1-9][0-9]{0,3})){2}\Z") # ASCII, no leading zeros
|
|
10
|
+
SHORT_RE = re.compile(r"^[a-z0-9]{1,16}$")
|
|
11
|
+
ENV_RE = re.compile(r"^[a-z0-9]{1,16}-[0-9a-f]{12}$")
|
|
12
|
+
TOKEN_RE = re.compile(r"zk_dl_[A-Za-z0-9_\-]{8,200}")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class KitError(Exception):
|
|
16
|
+
"""An expected failure: the message is for the operator and is printed as is."""
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def vt(v):
|
|
20
|
+
return tuple(int(x) for x in v.split("."))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def home():
|
|
24
|
+
h = os.environ.get("ZELPI_HOME") or os.path.join(os.path.expanduser("~"), ".zelpi")
|
|
25
|
+
return os.path.abspath(h)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def ensure_home():
|
|
29
|
+
try:
|
|
30
|
+
os.makedirs(home(), exist_ok=True)
|
|
31
|
+
except OSError as e:
|
|
32
|
+
raise KitError("cannot create ZELPI_HOME %s: %s" % (home(), e.strerror or e))
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def p(*parts):
|
|
36
|
+
return os.path.join(home(), *parts)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def kit_dir(short):
|
|
40
|
+
return p("kits", short)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def version_dir(short, version):
|
|
44
|
+
return p("kits", short, version)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def env_dir(name):
|
|
48
|
+
return p("envs", name)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def lock_path(kind, short, version=None):
|
|
52
|
+
return p("locks", "%s-%s%s.lock" % (kind, short, "-" + version if version else ""))
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def redact(text, token=None):
|
|
56
|
+
text = str(text)
|
|
57
|
+
if token:
|
|
58
|
+
text = text.replace(token, "***")
|
|
59
|
+
return TOKEN_RE.sub("zk_dl_***", text)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
# ---------- files ----------
|
|
63
|
+
|
|
64
|
+
def write_json(path, obj, mode=0o600, sync=True):
|
|
65
|
+
"""Temp file next to the target (created with the final mode, so never briefly wider), fsync, os.replace."""
|
|
66
|
+
os.makedirs(os.path.dirname(path), exist_ok=True)
|
|
67
|
+
tmp = "%s.%d.tmp" % (path, os.getpid())
|
|
68
|
+
try:
|
|
69
|
+
os.unlink(tmp)
|
|
70
|
+
except OSError:
|
|
71
|
+
pass
|
|
72
|
+
fd = os.open(tmp, os.O_WRONLY | os.O_CREAT | os.O_EXCL, mode)
|
|
73
|
+
try:
|
|
74
|
+
with os.fdopen(fd, "w", encoding="utf-8") as f:
|
|
75
|
+
json.dump(obj, f, indent=1)
|
|
76
|
+
f.flush()
|
|
77
|
+
if sync:
|
|
78
|
+
os.fsync(f.fileno())
|
|
79
|
+
os.replace(tmp, path)
|
|
80
|
+
except BaseException:
|
|
81
|
+
try:
|
|
82
|
+
os.unlink(tmp)
|
|
83
|
+
except OSError:
|
|
84
|
+
pass
|
|
85
|
+
raise
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def read_json(path):
|
|
89
|
+
with open(path, "r", encoding="utf-8") as f:
|
|
90
|
+
return json.load(f)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def safe_rmtree(path):
|
|
94
|
+
"""Remove a tree, but only if it is inside ZELPI_HOME (never follows a path out of it)."""
|
|
95
|
+
real, root = os.path.realpath(path), os.path.realpath(home())
|
|
96
|
+
if real == root or os.path.commonpath([real, root]) != root:
|
|
97
|
+
raise KitError("refusing to remove %s (outside ZELPI_HOME)" % path)
|
|
98
|
+
|
|
99
|
+
def _writable(func, pth, exc): # read-only files on Windows
|
|
100
|
+
os.chmod(pth, stat.S_IWRITE)
|
|
101
|
+
func(pth)
|
|
102
|
+
|
|
103
|
+
shutil.rmtree(real, onerror=_writable)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
# ---------- token ----------
|
|
107
|
+
|
|
108
|
+
def token_path():
|
|
109
|
+
return p("dl_token.json")
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def save_token(site, token):
|
|
113
|
+
ensure_home()
|
|
114
|
+
write_json(token_path(), {"site": site, "token": token})
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def load_token():
|
|
118
|
+
try:
|
|
119
|
+
d = read_json(token_path())
|
|
120
|
+
site, tok = d["site"], d["token"]
|
|
121
|
+
if not (isinstance(site, str) and TOKEN_RE.fullmatch(tok)):
|
|
122
|
+
raise ValueError
|
|
123
|
+
return site, tok
|
|
124
|
+
except FileNotFoundError:
|
|
125
|
+
raise KitError("not logged in: run 'zelpi-kit login'")
|
|
126
|
+
except (ValueError, KeyError, TypeError):
|
|
127
|
+
raise KitError("the token file %s is damaged: run 'zelpi-kit login' again" % token_path())
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
# ---------- kits ----------
|
|
131
|
+
|
|
132
|
+
def read_current(short):
|
|
133
|
+
"""current.json {version, previous, env}, validated; None when nothing is installed."""
|
|
134
|
+
try:
|
|
135
|
+
d = read_json(os.path.join(kit_dir(short), "current.json"))
|
|
136
|
+
except FileNotFoundError:
|
|
137
|
+
return None
|
|
138
|
+
except ValueError:
|
|
139
|
+
d = None
|
|
140
|
+
ok = (isinstance(d, dict) and isinstance(d.get("version"), str) and VER_RE.match(d["version"])
|
|
141
|
+
and (d.get("previous") is None or (isinstance(d["previous"], str) and VER_RE.match(d["previous"])))
|
|
142
|
+
and isinstance(d.get("env"), str) and ENV_RE.match(d["env"]))
|
|
143
|
+
if not ok:
|
|
144
|
+
raise KitError("kits/%s/current.json is damaged: run 'zelpi-kit install %s'" % (short, short))
|
|
145
|
+
return d
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def read_current_safe(short):
|
|
149
|
+
"""Like read_current, but a damaged pointer counts as 'nothing installed' (install repairs it)."""
|
|
150
|
+
try:
|
|
151
|
+
return read_current(short)
|
|
152
|
+
except KitError:
|
|
153
|
+
return None
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def installed_versions(short):
|
|
157
|
+
try:
|
|
158
|
+
names = os.listdir(kit_dir(short))
|
|
159
|
+
except OSError:
|
|
160
|
+
return []
|
|
161
|
+
good = [n for n in names if VER_RE.match(n) and os.path.isdir(os.path.join(kit_dir(short), n))]
|
|
162
|
+
return sorted(good, key=vt)
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def installed_shorts():
|
|
166
|
+
try:
|
|
167
|
+
return sorted(n for n in os.listdir(p("kits")) if SHORT_RE.match(n) and os.path.isdir(p("kits", n)))
|
|
168
|
+
except OSError:
|
|
169
|
+
return []
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def save_catalogue(cat):
|
|
173
|
+
# no token, no email: only what `run` needs to warn about a denied version
|
|
174
|
+
keep = [{k: kit.get(k) for k in ("project", "short", "latest", "min_version", "deny")} for kit in cat.get("kits", [])]
|
|
175
|
+
try:
|
|
176
|
+
write_json(p("catalogue.json"), {"kits": keep}, sync=False)
|
|
177
|
+
except OSError:
|
|
178
|
+
pass # a cache; never fail a command over it
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def cached_kit(short):
|
|
182
|
+
try:
|
|
183
|
+
for k in read_json(p("catalogue.json"))["kits"]:
|
|
184
|
+
if k.get("short") == short:
|
|
185
|
+
return k
|
|
186
|
+
except (OSError, ValueError, KeyError, TypeError):
|
|
187
|
+
pass
|
|
188
|
+
return None
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
# ---------- OS locks (never PID files: the OS drops them when the process dies, kill -9 included) ----------
|
|
192
|
+
|
|
193
|
+
if os.name == "nt":
|
|
194
|
+
# Windows: the lock is the file's SHARING MODE, not LockFileEx/msvcrt.locking. A byte-range lock belongs to the
|
|
195
|
+
# process that took it and dies with that process's handle, so an agent running as our child would not hold it.
|
|
196
|
+
# A sharing mode belongs to the file object: the agent inherits the handle and the file stays open (and
|
|
197
|
+
# "locked") as long as the agent lives, even if zelpi-kit itself is killed. Shared = open for read, share read
|
|
198
|
+
# (many agents may run one version); exclusive = open for read+write, share nothing (fails while any agent runs).
|
|
199
|
+
import ctypes
|
|
200
|
+
from ctypes import wintypes
|
|
201
|
+
|
|
202
|
+
_k32 = ctypes.WinDLL("kernel32", use_last_error=True)
|
|
203
|
+
_k32.CreateFileW.argtypes = [wintypes.LPCWSTR, wintypes.DWORD, wintypes.DWORD, ctypes.c_void_p, wintypes.DWORD,
|
|
204
|
+
wintypes.DWORD, wintypes.HANDLE]
|
|
205
|
+
_k32.CreateFileW.restype = wintypes.HANDLE
|
|
206
|
+
_k32.CloseHandle.argtypes = [wintypes.HANDLE]
|
|
207
|
+
_k32.SetHandleInformation.argtypes = [wintypes.HANDLE, wintypes.DWORD, wintypes.DWORD]
|
|
208
|
+
_INVALID = ctypes.c_void_p(-1).value
|
|
209
|
+
|
|
210
|
+
def _open_lock(path, exclusive):
|
|
211
|
+
h = _k32.CreateFileW(path, 0xC0000000 if exclusive else 0x80000000, 0 if exclusive else 1, None, 4, 0x80, None)
|
|
212
|
+
if h is None or h == _INVALID:
|
|
213
|
+
err = ctypes.get_last_error()
|
|
214
|
+
if err in (32, 33): # sharing / lock violation: somebody holds it
|
|
215
|
+
return None
|
|
216
|
+
raise ctypes.WinError(err)
|
|
217
|
+
return h
|
|
218
|
+
|
|
219
|
+
def _close_lock(h):
|
|
220
|
+
_k32.CloseHandle(h)
|
|
221
|
+
|
|
222
|
+
def _inheritable(h):
|
|
223
|
+
if not _k32.SetHandleInformation(h, 1, 1):
|
|
224
|
+
raise ctypes.WinError(ctypes.get_last_error())
|
|
225
|
+
else:
|
|
226
|
+
import fcntl
|
|
227
|
+
|
|
228
|
+
def _open_lock(path, exclusive):
|
|
229
|
+
fd = os.open(path, os.O_RDWR | os.O_CREAT, 0o600)
|
|
230
|
+
try:
|
|
231
|
+
fcntl.flock(fd, (fcntl.LOCK_EX if exclusive else fcntl.LOCK_SH) | fcntl.LOCK_NB)
|
|
232
|
+
return fd
|
|
233
|
+
except OSError as e:
|
|
234
|
+
os.close(fd)
|
|
235
|
+
if e.errno in (errno.EWOULDBLOCK, errno.EAGAIN, errno.EACCES):
|
|
236
|
+
return None
|
|
237
|
+
raise
|
|
238
|
+
|
|
239
|
+
def _close_lock(fd):
|
|
240
|
+
os.close(fd)
|
|
241
|
+
|
|
242
|
+
def _inheritable(fd): # flock lives on the open file description: it survives os.execv when the fd does
|
|
243
|
+
os.set_inheritable(fd, True)
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
class Lock:
|
|
247
|
+
"""Non-blocking lock on a file under ZELPI_HOME/locks, held until release() or the process (or its heir) dies."""
|
|
248
|
+
|
|
249
|
+
def __init__(self, path, exclusive):
|
|
250
|
+
self.path, self.exclusive, self.h = path, exclusive, None
|
|
251
|
+
|
|
252
|
+
def acquire(self):
|
|
253
|
+
os.makedirs(os.path.dirname(self.path), exist_ok=True)
|
|
254
|
+
self.h = _open_lock(self.path, self.exclusive)
|
|
255
|
+
return self.h is not None
|
|
256
|
+
|
|
257
|
+
@property
|
|
258
|
+
def held(self):
|
|
259
|
+
return self.h is not None
|
|
260
|
+
|
|
261
|
+
def make_inheritable(self):
|
|
262
|
+
_inheritable(self.h)
|
|
263
|
+
|
|
264
|
+
def release(self):
|
|
265
|
+
if self.h is not None:
|
|
266
|
+
_close_lock(self.h)
|
|
267
|
+
self.h = None
|
|
268
|
+
|
|
269
|
+
def __enter__(self):
|
|
270
|
+
return self
|
|
271
|
+
|
|
272
|
+
def __exit__(self, *a):
|
|
273
|
+
self.release()
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
def running_agents():
|
|
277
|
+
"""["b601 1.2.0", ...] of every kit an agent (or another kit command) is running from."""
|
|
278
|
+
return ["%s %s" % (s, v) for s in installed_shorts() for v in installed_versions(s) if is_running(s, v)]
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
def is_running(short, version):
|
|
282
|
+
"""True while any agent holds the shared run lock of this version folder."""
|
|
283
|
+
path = lock_path("run", short, version)
|
|
284
|
+
if not os.path.exists(path):
|
|
285
|
+
return False
|
|
286
|
+
lk = Lock(path, True)
|
|
287
|
+
try:
|
|
288
|
+
if lk.acquire():
|
|
289
|
+
lk.release()
|
|
290
|
+
return False
|
|
291
|
+
return True
|
|
292
|
+
except OSError:
|
|
293
|
+
return True # cannot tell: assume running (callers refuse to delete)
|
zelpi_kit/wheel.py
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"""Wheel checks and unpacking. The zip is validated member by member BEFORE anything is written; nothing is imported."""
|
|
2
|
+
import base64
|
|
3
|
+
import csv
|
|
4
|
+
import hashlib
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
import re
|
|
8
|
+
import stat
|
|
9
|
+
import unicodedata
|
|
10
|
+
import zipfile
|
|
11
|
+
|
|
12
|
+
from .store import KitError
|
|
13
|
+
|
|
14
|
+
RESERVED = re.compile(r"^(CON|PRN|AUX|NUL|COM\d|LPT\d)(\..*)?$", re.I)
|
|
15
|
+
MAX_TOTAL = 2 << 30 # uncompressed bytes
|
|
16
|
+
MAX_MEMBERS = 20000
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def safe_name(name):
|
|
20
|
+
"""Reason string when a member / RECORD path is unsafe, else None."""
|
|
21
|
+
if not name or "\x00" in name or "\\" in name:
|
|
22
|
+
return "empty, NUL or backslash"
|
|
23
|
+
if name.startswith("/") or ":" in name: # absolute, drive letter, NTFS stream
|
|
24
|
+
return "absolute or drive path"
|
|
25
|
+
parts = name.rstrip("/").split("/")
|
|
26
|
+
for c in parts:
|
|
27
|
+
if c in ("", ".", ".."):
|
|
28
|
+
return "'..' or empty component"
|
|
29
|
+
if c[-1] in ". ":
|
|
30
|
+
return "component ends with '.' or space"
|
|
31
|
+
if RESERVED.match(c): # Windows device names (CON, COM3, NUL.txt ...): never open one
|
|
32
|
+
return "Windows device name"
|
|
33
|
+
return None
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def check_members(zf, short, version):
|
|
37
|
+
infos = zf.infolist()
|
|
38
|
+
if not infos or len(infos) > MAX_MEMBERS:
|
|
39
|
+
raise KitError("wheel refused: %d members" % len(infos))
|
|
40
|
+
seen, folded, total = set(), {}, 0
|
|
41
|
+
tops = {"zelpi_%s" % short, "zelpi_%s-%s.dist-info" % (short, version)}
|
|
42
|
+
for i in infos:
|
|
43
|
+
n = i.filename
|
|
44
|
+
why = safe_name(n)
|
|
45
|
+
if why:
|
|
46
|
+
raise KitError("wheel refused: unsafe member %r (%s)" % (n, why))
|
|
47
|
+
fmt = stat.S_IFMT(i.external_attr >> 16) # wheels usually carry permission bits only: fmt 0
|
|
48
|
+
if fmt and fmt not in (stat.S_IFREG, stat.S_IFDIR):
|
|
49
|
+
raise KitError("wheel refused: %r is a link or special file" % n)
|
|
50
|
+
if i.flag_bits & 1:
|
|
51
|
+
raise KitError("wheel refused: encrypted member %r" % n)
|
|
52
|
+
if n in seen:
|
|
53
|
+
raise KitError("wheel refused: duplicate member %r" % n)
|
|
54
|
+
seen.add(n)
|
|
55
|
+
key = unicodedata.normalize("NFC", n).casefold()
|
|
56
|
+
if key in folded:
|
|
57
|
+
raise KitError("wheel refused: %r and %r differ only by case" % (n, folded[key]))
|
|
58
|
+
folded[key] = n
|
|
59
|
+
if n.split("/")[0] not in tops:
|
|
60
|
+
raise KitError("wheel refused: %r is outside zelpi_%s/ and its dist-info" % (n, short))
|
|
61
|
+
total += i.file_size
|
|
62
|
+
if total > MAX_TOTAL:
|
|
63
|
+
raise KitError("wheel refused: unpacks to %d bytes" % total)
|
|
64
|
+
return infos
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def unpack(whl, dest, short, version):
|
|
68
|
+
"""Check every member, then write them one by one into the new, empty `dest`."""
|
|
69
|
+
try:
|
|
70
|
+
zf = zipfile.ZipFile(whl)
|
|
71
|
+
except (zipfile.BadZipFile, OSError) as e:
|
|
72
|
+
raise KitError("not a valid wheel: %s" % e)
|
|
73
|
+
with zf:
|
|
74
|
+
infos = check_members(zf, short, version)
|
|
75
|
+
root = os.path.realpath(dest)
|
|
76
|
+
os.makedirs(root)
|
|
77
|
+
for i in infos:
|
|
78
|
+
target = os.path.realpath(os.path.join(root, *i.filename.rstrip("/").split("/")))
|
|
79
|
+
if os.path.commonpath([target, root]) != root:
|
|
80
|
+
raise KitError("wheel refused: %r escapes the folder" % i.filename)
|
|
81
|
+
if i.filename.endswith("/"):
|
|
82
|
+
os.makedirs(target, exist_ok=True)
|
|
83
|
+
continue
|
|
84
|
+
os.makedirs(os.path.dirname(target), exist_ok=True)
|
|
85
|
+
left = i.file_size
|
|
86
|
+
with zf.open(i) as src, open(target, "xb") as out:
|
|
87
|
+
while True:
|
|
88
|
+
chunk = src.read(1 << 16)
|
|
89
|
+
if not chunk:
|
|
90
|
+
break
|
|
91
|
+
left -= len(chunk)
|
|
92
|
+
if left < 0:
|
|
93
|
+
raise KitError("wheel refused: %r is larger than it declares" % i.filename)
|
|
94
|
+
out.write(chunk)
|
|
95
|
+
if (i.external_attr >> 16) & 0o111:
|
|
96
|
+
os.chmod(target, 0o755)
|
|
97
|
+
return root
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _b64(digest):
|
|
101
|
+
return base64.urlsafe_b64encode(digest).rstrip(b"=").decode()
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def verify_record(root, short, version, strict=True):
|
|
105
|
+
"""Every RECORD entry exists with the right sha256 and size; strict (a fresh unpack): nothing else is there, not even a .pyc."""
|
|
106
|
+
di = "zelpi_%s-%s.dist-info" % (short, version)
|
|
107
|
+
rec = os.path.join(root, di, "RECORD")
|
|
108
|
+
try:
|
|
109
|
+
with open(rec, "r", encoding="utf-8", newline="") as f:
|
|
110
|
+
rows = list(csv.reader(f))
|
|
111
|
+
except OSError:
|
|
112
|
+
raise KitError("wheel refused: no %s/RECORD" % di)
|
|
113
|
+
listed = {}
|
|
114
|
+
for r in rows:
|
|
115
|
+
if not r:
|
|
116
|
+
continue
|
|
117
|
+
if len(r) != 3 or safe_name(r[0]):
|
|
118
|
+
raise KitError("RECORD refused: bad row %r" % (r,))
|
|
119
|
+
listed[r[0]] = r
|
|
120
|
+
for name, (_, h, size) in listed.items():
|
|
121
|
+
if name == di + "/RECORD":
|
|
122
|
+
continue
|
|
123
|
+
path = os.path.join(root, *name.split("/"))
|
|
124
|
+
if not h.startswith("sha256="):
|
|
125
|
+
raise KitError("RECORD refused: %s has no sha256" % name)
|
|
126
|
+
try:
|
|
127
|
+
with open(path, "rb") as f:
|
|
128
|
+
data = f.read()
|
|
129
|
+
except OSError:
|
|
130
|
+
raise KitError("RECORD lists %s but it is missing" % name)
|
|
131
|
+
if _b64(hashlib.sha256(data).digest()) != h[7:] or (size and int(size) != len(data)):
|
|
132
|
+
raise KitError("RECORD mismatch for %s: the package was altered" % name)
|
|
133
|
+
for d, _, files in os.walk(root) if strict else ():
|
|
134
|
+
for fn in files:
|
|
135
|
+
rel = os.path.relpath(os.path.join(d, fn), root).replace(os.sep, "/")
|
|
136
|
+
if rel not in listed:
|
|
137
|
+
raise KitError("RECORD does not list %s" % rel)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def read_kit(root, short, kit, entry):
|
|
141
|
+
"""kit.json + METADATA must agree with the catalogue (project, version, kind); returns kit.json."""
|
|
142
|
+
try:
|
|
143
|
+
with open(os.path.join(root, "zelpi_%s" % short, "kit.json"), "r", encoding="utf-8") as f:
|
|
144
|
+
kj = json.load(f)
|
|
145
|
+
with open(os.path.join(root, "zelpi_%s-%s.dist-info" % (short, entry["version"]), "METADATA"), encoding="utf-8") as f:
|
|
146
|
+
meta = f.read()
|
|
147
|
+
except (OSError, ValueError):
|
|
148
|
+
raise KitError("wheel refused: kit.json or METADATA missing or unreadable")
|
|
149
|
+
if not isinstance(kj, dict):
|
|
150
|
+
raise KitError("wheel refused: kit.json is not an object")
|
|
151
|
+
for k in ("project", "version", "kind"):
|
|
152
|
+
if kj.get(k) != (entry["version"] if k == "version" else kit[k]):
|
|
153
|
+
raise KitError("wheel refused: kit.json %s=%r does not match the catalogue (%r)"
|
|
154
|
+
% (k, kj.get(k), entry["version"] if k == "version" else kit[k]))
|
|
155
|
+
name = re.search(r"^Name:\s*(\S+)", meta, re.M)
|
|
156
|
+
ver = re.search(r"^Version:\s*(\S+)", meta, re.M)
|
|
157
|
+
if not name or not ver or re.sub(r"[-_.]+", "-", name.group(1)).lower() != kit["project"] or ver.group(1) != entry["version"]:
|
|
158
|
+
raise KitError("wheel refused: METADATA name/version do not match the catalogue")
|
|
159
|
+
if not isinstance(kj.get("python"), str):
|
|
160
|
+
raise KitError("wheel refused: kit.json has no python range")
|
|
161
|
+
sm = kj.get("smoke")
|
|
162
|
+
if not (isinstance(sm, list) and sm and all(isinstance(x, str) for x in sm)):
|
|
163
|
+
raise KitError("wheel refused: kit.json has no smoke command")
|
|
164
|
+
return kj
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: zelpi-kit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Installs, updates and runs ZELPI robot kits (invited partners only).
|
|
5
|
+
Author: ZELPI
|
|
6
|
+
License: Proprietary. All rights reserved.
|
|
7
|
+
Project-URL: Homepage, https://tryzelpi.com
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: License :: Other/Proprietary License
|
|
10
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
11
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Requires-Python: >=3.9
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# zelpi-kit
|
|
17
|
+
|
|
18
|
+
Installs, updates, rolls back and runs [ZELPI](https://tryzelpi.com) robot kits.
|
|
19
|
+
|
|
20
|
+
**Invited partners only.** This package is just the installer. It contains no robot software: the kits are served only
|
|
21
|
+
to people who have signed in to the ZELPI dashboard with an invite.
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
uv tool install zelpi-kit # or: pipx install zelpi-kit, or pip install zelpi-kit inside a virtual environment
|
|
26
|
+
|
|
27
|
+
Python 3.9 or newer, no dependencies. Tested on Windows and on Linux (x86_64 and ARM64). Not tested on macOS yet.
|
|
28
|
+
A robot kit may need its own Python version. `uv` on the PATH lets zelpi-kit fetch it for you.
|
|
29
|
+
|
|
30
|
+
## Use
|
|
31
|
+
|
|
32
|
+
zelpi-kit login # paste a download token from the dashboard's Keys page
|
|
33
|
+
zelpi-kit list # the robots your invite covers
|
|
34
|
+
zelpi-kit install b601
|
|
35
|
+
zelpi-kit run b601 agent --help # everything after the command goes to the kit untouched
|
|
36
|
+
zelpi-kit update b601
|
|
37
|
+
zelpi-kit rollback b601 # back to the previous version, works offline
|
|
38
|
+
zelpi-kit versions b601
|
|
39
|
+
zelpi-kit uninstall b601
|
|
40
|
+
zelpi-kit doctor # checks this computer
|
|
41
|
+
zelpi-kit logout # also revokes the token
|
|
42
|
+
|
|
43
|
+
A download token (`zk_dl_...`) only downloads kits. It is not a robot key (`zk_live_...`): never paste a robot key into `login`.
|
|
44
|
+
Everything lives in `~/.zelpi` (change it with the `ZELPI_HOME` environment variable).
|
|
45
|
+
|
|
46
|
+
## Robot arms
|
|
47
|
+
|
|
48
|
+
The kits drive real hardware. zelpi-kit never replaces a kit while an agent is running, switches versions only after the
|
|
49
|
+
download is verified and the new version has started once, and keeps the previous version for rollback. When an update
|
|
50
|
+
asks you to repeat the hardware checks, do them before any motion. Follow the safety guide of your kit.
|
|
51
|
+
|
|
52
|
+
## Known limits
|
|
53
|
+
|
|
54
|
+
The proxy settings in `HTTP_PROXY` / `HTTPS_PROXY` are not used for sign-in and kit downloads yet.
|
|
55
|
+
|
|
56
|
+
## License
|
|
57
|
+
|
|
58
|
+
Proprietary. All rights reserved. Use is limited to invited ZELPI partners.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
zelpi_kit/__init__.py,sha256=isNkwOUYrZNmENRd0XUQr-VDKIo-ewQrUbqfIVY64NA,196
|
|
2
|
+
zelpi_kit/__main__.py,sha256=Sxr7ynShCrw8_3tOWhG1WL9hnkW4lwn6-SJaR0oqJQ8,57
|
|
3
|
+
zelpi_kit/cli.py,sha256=3rowa0j7V_w1hdfnQYjkAfIQaDEII2ix7Vpb7NU--R8,11536
|
|
4
|
+
zelpi_kit/env.py,sha256=9Y_hlmwFVqyeVKo7Mj7p1kwuHIUBQjOlcaMxh7nSiks,10094
|
|
5
|
+
zelpi_kit/install.py,sha256=WP9mfSGhseiD5F423fZwqsOSOow072GgrE7pr6DX_RM,14834
|
|
6
|
+
zelpi_kit/net.py,sha256=EZhALbZZrS3fk3tXWKEistaWOT1KFMJTtMM4q_46zbY,6291
|
|
7
|
+
zelpi_kit/run.py,sha256=0ysmaT33ODqeGJGY031N9iGGtbN_5z0j2Xk5mmg5fJo,3195
|
|
8
|
+
zelpi_kit/store.py,sha256=84Sod6xHpBSEQOfcSjtlO9t2s_SVcxx795CuTH80vFk,9599
|
|
9
|
+
zelpi_kit/wheel.py,sha256=KOGmfzluEQ7yOknJHh1dl7hOAEZLOYzbFv9Aecw3r3Q,7264
|
|
10
|
+
zelpi_kit-0.1.0.dist-info/METADATA,sha256=a1-C2YgCDB_FuxV-Gv-Oa74s2flV_8N8ot6WDa1WTfw,2583
|
|
11
|
+
zelpi_kit-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
12
|
+
zelpi_kit-0.1.0.dist-info/entry_points.txt,sha256=sJiDHP8-62B1uKmIC8q-4LcgoAsqsYsbT7dV6j32QZM,49
|
|
13
|
+
zelpi_kit-0.1.0.dist-info/top_level.txt,sha256=mDhtyawP7TR1XCZB2nERazINKTfizq9LWZ27rvhdCXk,10
|
|
14
|
+
zelpi_kit-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
zelpi_kit
|