vinopilot 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.
- vinopilot-0.1.0.dist-info/METADATA +62 -0
- vinopilot-0.1.0.dist-info/RECORD +10 -0
- vinopilot-0.1.0.dist-info/WHEEL +4 -0
- vinopilot-0.1.0.dist-info/entry_points.txt +2 -0
- vinopilot-0.1.0.dist-info/licenses/LICENSE +21 -0
- vinopilot_tui/__init__.py +3 -0
- vinopilot_tui/__main__.py +3 -0
- vinopilot_tui/app.py +478 -0
- vinopilot_tui/app.tcss +66 -0
- vinopilot_tui/cli.py +187 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: vinopilot
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Terminal UI for vinoPilot: install, update and uninstall the vinoPilot apps
|
|
5
|
+
Project-URL: Homepage, https://vinopilot.ca/
|
|
6
|
+
Project-URL: Repository, https://github.com/karanshukla/vinopilot
|
|
7
|
+
Project-URL: Issues, https://github.com/karanshukla/vinopilot/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/karanshukla/vinopilot/blob/main/CHANGELOG.md
|
|
9
|
+
Author: Karan Shukla
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: installer,linux,textual,tui,vinopilot
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Environment :: Console
|
|
15
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
16
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Topic :: System :: Installation/Setup
|
|
23
|
+
Requires-Python: >=3.11
|
|
24
|
+
Requires-Dist: textual<9,>=8
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
# vinoPilot in a terminal
|
|
28
|
+
|
|
29
|
+
The [vinoPilot](https://github.com/karanshukla/vinopilot) window, for a terminal: a table of the vinoPilot apps with their version, how each is installed and whether there's something newer, the installer's output underneath, and one key per action.
|
|
30
|
+
|
|
31
|
+
It's a thin frontend. Everything it knows comes from the `vinopilot` command's `--json` output, and every action is a `vinopilot` run, so what the window does and what the table does can't drift apart. If the command isn't there, the first screen offers to fetch it from the latest release with the same hash-checked installer the README gives.
|
|
32
|
+
|
|
33
|
+
## Install
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
uv tool install vinopilot
|
|
37
|
+
vinopilot-tui
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
or `pipx install vinopilot`. The command is `vinopilot-tui`, not `vinopilot`: that name is the Rust command this drives, and `uv tool` would otherwise overwrite it in `~/.local/bin`.
|
|
41
|
+
|
|
42
|
+
## Keys
|
|
43
|
+
|
|
44
|
+
| Key | Does |
|
|
45
|
+
|---|---|
|
|
46
|
+
| `c` | Check for updates (the only thing that goes online, besides the actions themselves) |
|
|
47
|
+
| `i` | Install the selected app; asks which way when there's more than one |
|
|
48
|
+
| `u` | Update it, the way it's installed |
|
|
49
|
+
| `a` | Update everything that has an update, vinoPilot included |
|
|
50
|
+
| `x` | Uninstall it, after a yes |
|
|
51
|
+
| `s` | Show the shell an action would run, without running it |
|
|
52
|
+
| `r` | Change where source checkouts go |
|
|
53
|
+
| `Esc` | Stop the running action |
|
|
54
|
+
| `q` | Quit |
|
|
55
|
+
|
|
56
|
+
After an action the table is rescanned: offline, or online again if you had checked for updates.
|
|
57
|
+
|
|
58
|
+
## Limits
|
|
59
|
+
|
|
60
|
+
- vinoAuthFace's steps run through `pkexec`. On a desktop the polkit agent asks for your password in a dialog. Over ssh with no agent, pkexec has no way to ask and the step fails.
|
|
61
|
+
- Stopping an action ends the `vinopilot` run, but a `pkexec` child is root's and runs on.
|
|
62
|
+
- `VINOPILOT_BIN=/path/to/vinopilot` picks the command to drive, for a checkout build.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
vinopilot_tui/__init__.py,sha256=S-EbpoSP-238V25-IZe1ADb9KIepNGoDhDSg1xDkjTk,115
|
|
2
|
+
vinopilot_tui/__main__.py,sha256=ms5-5wjqOB49NeaAd9fViSU1AlpCT6t6KmSvxBXnxJw,43
|
|
3
|
+
vinopilot_tui/app.py,sha256=Lg6lo-5zKvY5CYdfgHo9Bl31ZWTCtLjGkKiW9YODHzw,17550
|
|
4
|
+
vinopilot_tui/app.tcss,sha256=zrbGyMvlBMMwYZIzAXjqQCEFDC7VBNKxhSVZaB3uyLk,839
|
|
5
|
+
vinopilot_tui/cli.py,sha256=GCUHLNL9Gatj1OYCQD4BFeT49WmRvqANb7v8FRIoBsc,6332
|
|
6
|
+
vinopilot-0.1.0.dist-info/METADATA,sha256=-1tAbHXT1MMGoqkuO6p9b3NXZkb363gnUGfK42AOM_c,2944
|
|
7
|
+
vinopilot-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
8
|
+
vinopilot-0.1.0.dist-info/entry_points.txt,sha256=MZZl6NL_qXcXCW7KLWGkxAy-1XQJs-i7p1V9tDfA5-A,57
|
|
9
|
+
vinopilot-0.1.0.dist-info/licenses/LICENSE,sha256=iyzZi_FgxGtvs9sGWkiD7EOpLQmBkwR2OQQ-91oCoXs,1069
|
|
10
|
+
vinopilot-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Karan Shukla
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
vinopilot_tui/app.py
ADDED
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
"""The window, in a terminal: a table of the components, the installer's
|
|
2
|
+
output underneath, one key per action. Every action is a `vinopilot` run."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import argparse
|
|
7
|
+
import os
|
|
8
|
+
|
|
9
|
+
from rich.text import Text
|
|
10
|
+
from textual import work
|
|
11
|
+
from textual.app import App, ComposeResult
|
|
12
|
+
from textual.binding import Binding
|
|
13
|
+
from textual.containers import Horizontal, Vertical, VerticalScroll
|
|
14
|
+
from textual.screen import ModalScreen
|
|
15
|
+
from textual.widgets import (
|
|
16
|
+
Button,
|
|
17
|
+
DataTable,
|
|
18
|
+
Footer,
|
|
19
|
+
Input,
|
|
20
|
+
Label,
|
|
21
|
+
OptionList,
|
|
22
|
+
RichLog,
|
|
23
|
+
Static,
|
|
24
|
+
)
|
|
25
|
+
from textual.widgets.option_list import Option
|
|
26
|
+
|
|
27
|
+
from vinopilot_tui import __version__, cli
|
|
28
|
+
from vinopilot_tui.cli import CommandError, Event, Job, Pilot
|
|
29
|
+
|
|
30
|
+
CHANNEL_LABEL = {"release": "Release", "source": "Source"}
|
|
31
|
+
ACTIONS = ["install", "update", "uninstall"]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def channel_label(component: dict, channel: str) -> str:
|
|
35
|
+
"""`Release`, `Source`, `PyPI` or `crates.io`."""
|
|
36
|
+
if channel == "package":
|
|
37
|
+
return {"pypi": "PyPI", "crates.io": "crates.io"}.get(
|
|
38
|
+
component.get("registry") or "", "Package"
|
|
39
|
+
)
|
|
40
|
+
return CHANNEL_LABEL.get(channel, channel)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def tilde(path: str) -> str:
|
|
44
|
+
home = os.path.expanduser("~")
|
|
45
|
+
return "~" + path[len(home) :] if path.startswith(home) else path
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class ChooseScreen(ModalScreen[str | None]):
|
|
49
|
+
"""One of a few options, by id."""
|
|
50
|
+
|
|
51
|
+
BINDINGS = [Binding("escape", "dismiss(None)", "Cancel")]
|
|
52
|
+
|
|
53
|
+
def __init__(self, title: str, options: list[tuple[str, str]]) -> None:
|
|
54
|
+
super().__init__()
|
|
55
|
+
self.title_text = title
|
|
56
|
+
self.options = options
|
|
57
|
+
|
|
58
|
+
def compose(self) -> ComposeResult:
|
|
59
|
+
with Vertical(classes="dialog"):
|
|
60
|
+
yield Label(self.title_text, classes="title")
|
|
61
|
+
yield OptionList(*(Option(label, id=key) for key, label in self.options))
|
|
62
|
+
yield Label("Enter chooses, Esc cancels", classes="hint")
|
|
63
|
+
|
|
64
|
+
def on_mount(self) -> None:
|
|
65
|
+
option_list = self.query_one(OptionList)
|
|
66
|
+
option_list.highlighted = 0
|
|
67
|
+
option_list.focus()
|
|
68
|
+
|
|
69
|
+
def on_option_list_option_selected(self, event: OptionList.OptionSelected) -> None:
|
|
70
|
+
self.dismiss(event.option.id)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class ConfirmScreen(ModalScreen[bool]):
|
|
74
|
+
BINDINGS = [
|
|
75
|
+
Binding("y", "dismiss(True)", "Yes"),
|
|
76
|
+
Binding("n", "dismiss(False)", "No"),
|
|
77
|
+
Binding("escape", "dismiss(False)", "Cancel", show=False),
|
|
78
|
+
]
|
|
79
|
+
|
|
80
|
+
def __init__(self, question: str, detail: str = "") -> None:
|
|
81
|
+
super().__init__()
|
|
82
|
+
self.question = question
|
|
83
|
+
self.detail = detail
|
|
84
|
+
|
|
85
|
+
def compose(self) -> ComposeResult:
|
|
86
|
+
with Vertical(classes="dialog"):
|
|
87
|
+
yield Label(self.question, classes="title")
|
|
88
|
+
if self.detail:
|
|
89
|
+
yield Static(self.detail)
|
|
90
|
+
with Horizontal(classes="buttons"):
|
|
91
|
+
yield Button("Yes", id="yes", variant="error")
|
|
92
|
+
yield Button("No", id="no", variant="primary")
|
|
93
|
+
|
|
94
|
+
def on_mount(self) -> None:
|
|
95
|
+
self.query_one("#no", Button).focus()
|
|
96
|
+
|
|
97
|
+
def on_button_pressed(self, event: Button.Pressed) -> None:
|
|
98
|
+
self.dismiss(event.button.id == "yes")
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
class TextScreen(ModalScreen[None]):
|
|
102
|
+
"""Read-only text, such as the shell an action runs."""
|
|
103
|
+
|
|
104
|
+
BINDINGS = [
|
|
105
|
+
Binding("escape", "dismiss", "Close"),
|
|
106
|
+
Binding("q", "dismiss", "Close", show=False),
|
|
107
|
+
]
|
|
108
|
+
|
|
109
|
+
def __init__(self, title: str, text: str) -> None:
|
|
110
|
+
super().__init__()
|
|
111
|
+
self.title_text = title
|
|
112
|
+
self.text = text
|
|
113
|
+
|
|
114
|
+
def compose(self) -> ComposeResult:
|
|
115
|
+
with Vertical(classes="dialog"):
|
|
116
|
+
yield Label(self.title_text, classes="title")
|
|
117
|
+
with VerticalScroll():
|
|
118
|
+
yield Static(Text(self.text))
|
|
119
|
+
yield Label("Esc closes", classes="hint")
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
class InputScreen(ModalScreen[str | None]):
|
|
123
|
+
BINDINGS = [Binding("escape", "dismiss(None)", "Cancel")]
|
|
124
|
+
|
|
125
|
+
def __init__(self, title: str, value: str) -> None:
|
|
126
|
+
super().__init__()
|
|
127
|
+
self.title_text = title
|
|
128
|
+
self.value = value
|
|
129
|
+
|
|
130
|
+
def compose(self) -> ComposeResult:
|
|
131
|
+
with Vertical(classes="dialog"):
|
|
132
|
+
yield Label(self.title_text, classes="title")
|
|
133
|
+
yield Input(value=self.value)
|
|
134
|
+
yield Label("Enter saves, Esc cancels", classes="hint")
|
|
135
|
+
|
|
136
|
+
def on_mount(self) -> None:
|
|
137
|
+
self.query_one(Input).focus()
|
|
138
|
+
|
|
139
|
+
def on_input_submitted(self, event: Input.Submitted) -> None:
|
|
140
|
+
self.dismiss(event.value.strip() or None)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
class MissingScreen(ModalScreen[bool]):
|
|
144
|
+
"""No `vinopilot` command: offer the release installer, or leave."""
|
|
145
|
+
|
|
146
|
+
BINDINGS = [Binding("escape", "dismiss(False)", "Quit", show=False)]
|
|
147
|
+
|
|
148
|
+
def compose(self) -> ComposeResult:
|
|
149
|
+
with Vertical(classes="dialog"):
|
|
150
|
+
yield Label("The vinopilot command isn't installed", classes="title")
|
|
151
|
+
yield Static(
|
|
152
|
+
"This terminal UI drives the vinopilot command, which does the "
|
|
153
|
+
"installing. Get it from the latest release? Its installer checks "
|
|
154
|
+
"the download against the release's SHA256SUMS and puts the command "
|
|
155
|
+
"in ~/.local/bin, no sudo.\n\n"
|
|
156
|
+
f"Or in a shell:\n curl -fsSL {cli.INSTALLER} | bash -s -- --no-gui"
|
|
157
|
+
)
|
|
158
|
+
with Horizontal(classes="buttons"):
|
|
159
|
+
yield Button("Install", id="install", variant="primary")
|
|
160
|
+
yield Button("Quit", id="quit")
|
|
161
|
+
yield RichLog(id="missing-log", markup=False, highlight=False, wrap=True)
|
|
162
|
+
|
|
163
|
+
def on_button_pressed(self, event: Button.Pressed) -> None:
|
|
164
|
+
if event.button.id == "quit":
|
|
165
|
+
self.dismiss(False)
|
|
166
|
+
return
|
|
167
|
+
event.button.disabled = True
|
|
168
|
+
self.install()
|
|
169
|
+
|
|
170
|
+
@work(thread=True, exclusive=True)
|
|
171
|
+
def install(self) -> None:
|
|
172
|
+
log = self.query_one(RichLog)
|
|
173
|
+
job = cli.installer()
|
|
174
|
+
for event in job.events():
|
|
175
|
+
if event.kind == "line":
|
|
176
|
+
self.app.call_from_thread(log.write, event.text)
|
|
177
|
+
elif event.outcome == "done" and cli.find():
|
|
178
|
+
self.app.call_from_thread(self.dismiss, True)
|
|
179
|
+
return
|
|
180
|
+
else:
|
|
181
|
+
why = event.reason or "the command still isn't there"
|
|
182
|
+
self.app.call_from_thread(log.write, f"✗ Not installed: {why}")
|
|
183
|
+
self.app.call_from_thread(self.query_one("#install", Button).__setattr__, "disabled", False)
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
class PilotApp(App[None]):
|
|
187
|
+
TITLE = "vinoPilot"
|
|
188
|
+
CSS_PATH = "app.tcss"
|
|
189
|
+
BINDINGS = [
|
|
190
|
+
Binding("c", "check", "Check for updates"),
|
|
191
|
+
Binding("i", "install", "Install"),
|
|
192
|
+
Binding("u", "update", "Update"),
|
|
193
|
+
Binding("a", "update_all", "Update all"),
|
|
194
|
+
Binding("x", "uninstall", "Uninstall"),
|
|
195
|
+
Binding("s", "steps", "Steps"),
|
|
196
|
+
Binding("r", "source_root", "Source folder"),
|
|
197
|
+
Binding("escape", "stop", "Stop", show=False),
|
|
198
|
+
Binding("q", "quit", "Quit"),
|
|
199
|
+
]
|
|
200
|
+
|
|
201
|
+
def __init__(self) -> None:
|
|
202
|
+
super().__init__()
|
|
203
|
+
self.pilot: Pilot | None = None
|
|
204
|
+
self.version = ""
|
|
205
|
+
self.components: list[dict] = []
|
|
206
|
+
self.checked = False
|
|
207
|
+
self.scanning = False
|
|
208
|
+
self.job: Job | None = None
|
|
209
|
+
self.status_text = ""
|
|
210
|
+
|
|
211
|
+
def compose(self) -> ComposeResult:
|
|
212
|
+
yield Static("", id="status")
|
|
213
|
+
yield DataTable(id="table", cursor_type="row", zebra_stripes=True)
|
|
214
|
+
yield RichLog(id="log", markup=False, highlight=False, wrap=True)
|
|
215
|
+
yield Footer()
|
|
216
|
+
|
|
217
|
+
def on_mount(self) -> None:
|
|
218
|
+
table = self.query_one(DataTable)
|
|
219
|
+
table.add_columns("App", "Version", "Via", "Update", "About")
|
|
220
|
+
found = cli.find()
|
|
221
|
+
if found is None:
|
|
222
|
+
self.push_screen(MissingScreen(), self.after_missing)
|
|
223
|
+
else:
|
|
224
|
+
self.attach(found)
|
|
225
|
+
|
|
226
|
+
def after_missing(self, installed: bool | None) -> None:
|
|
227
|
+
found = cli.find() if installed else None
|
|
228
|
+
if found is None:
|
|
229
|
+
self.exit()
|
|
230
|
+
else:
|
|
231
|
+
self.log_line("✓ Installed the vinopilot command")
|
|
232
|
+
self.attach(found)
|
|
233
|
+
|
|
234
|
+
def attach(self, binary: str) -> None:
|
|
235
|
+
self.pilot = Pilot(binary)
|
|
236
|
+
try:
|
|
237
|
+
self.version = self.pilot.version()
|
|
238
|
+
except (CommandError, OSError) as e:
|
|
239
|
+
self.log_line(f"✗ {binary} won't run: {e}")
|
|
240
|
+
return
|
|
241
|
+
self.scan(False)
|
|
242
|
+
|
|
243
|
+
# --- the table ---------------------------------------------------------
|
|
244
|
+
|
|
245
|
+
@work(thread=True, exclusive=True, group="scan")
|
|
246
|
+
def scan(self, online: bool) -> None:
|
|
247
|
+
assert self.pilot is not None
|
|
248
|
+
self.call_from_thread(self.set_scanning, True, online)
|
|
249
|
+
try:
|
|
250
|
+
doc = self.pilot.check() if online else self.pilot.list()
|
|
251
|
+
except (CommandError, OSError) as e:
|
|
252
|
+
self.call_from_thread(self.log_line, f"✗ {e}")
|
|
253
|
+
self.call_from_thread(self.set_scanning, False, online)
|
|
254
|
+
return
|
|
255
|
+
self.call_from_thread(self.show, doc, online)
|
|
256
|
+
|
|
257
|
+
def set_scanning(self, scanning: bool, online: bool) -> None:
|
|
258
|
+
self.scanning = scanning
|
|
259
|
+
if scanning:
|
|
260
|
+
self.set_status("Checking for updates…" if online else "Looking…")
|
|
261
|
+
else:
|
|
262
|
+
self.set_status()
|
|
263
|
+
|
|
264
|
+
def show(self, doc: dict, online: bool) -> None:
|
|
265
|
+
self.components = list(doc.get("components", []))
|
|
266
|
+
self.checked = self.checked or online
|
|
267
|
+
self.source_root = str(doc.get("source_root", ""))
|
|
268
|
+
table = self.query_one(DataTable)
|
|
269
|
+
row = table.cursor_row
|
|
270
|
+
table.clear()
|
|
271
|
+
for c in self.components:
|
|
272
|
+
table.add_row(*self.cells(c), key=c["id"])
|
|
273
|
+
if self.components:
|
|
274
|
+
table.move_cursor(row=min(row, len(self.components) - 1))
|
|
275
|
+
self.set_scanning(False, online)
|
|
276
|
+
|
|
277
|
+
def cells(self, c: dict) -> tuple:
|
|
278
|
+
installed = c.get("installed")
|
|
279
|
+
update = c.get("update") or {}
|
|
280
|
+
if installed:
|
|
281
|
+
version = installed.get("version") or "?"
|
|
282
|
+
via = channel_label(c, installed["channel"])
|
|
283
|
+
else:
|
|
284
|
+
version, via = "-", Text("not installed", style="dim")
|
|
285
|
+
if not self.checked:
|
|
286
|
+
state: str | Text = ""
|
|
287
|
+
elif not installed:
|
|
288
|
+
latest = (c.get("latest") or {}).get("release") or {}
|
|
289
|
+
state = Text(f"latest {latest['value']}", style="dim") if "value" in latest else ""
|
|
290
|
+
elif update.get("state") == "available":
|
|
291
|
+
state = Text(f"{update['to']} available", style="bold")
|
|
292
|
+
elif update.get("state") == "up_to_date":
|
|
293
|
+
state = Text("up to date", style="dim")
|
|
294
|
+
else:
|
|
295
|
+
state = Text(update.get("reason") or "?", style="dim")
|
|
296
|
+
return (c["name"], version, via, state, Text(c.get("blurb", ""), style="dim"))
|
|
297
|
+
|
|
298
|
+
def set_status(self, busy: str = "") -> None:
|
|
299
|
+
parts = [f"vinoPilot {self.version}" if self.version else "vinoPilot"]
|
|
300
|
+
if getattr(self, "source_root", ""):
|
|
301
|
+
parts.append(f"source folder {tilde(self.source_root)}")
|
|
302
|
+
if busy:
|
|
303
|
+
parts.append(busy + ("" if self.job is None else " (Esc stops)"))
|
|
304
|
+
elif self.checked:
|
|
305
|
+
n = sum(
|
|
306
|
+
1 for c in self.components if (c.get("update") or {}).get("state") == "available"
|
|
307
|
+
)
|
|
308
|
+
parts.append(
|
|
309
|
+
f"{n} update{'s' if n != 1 else ''} available" if n else "no updates found"
|
|
310
|
+
)
|
|
311
|
+
self.status_text = " · ".join(parts)
|
|
312
|
+
self.query_one("#status", Static).update(self.status_text)
|
|
313
|
+
|
|
314
|
+
def selected(self) -> dict | None:
|
|
315
|
+
table = self.query_one(DataTable)
|
|
316
|
+
if not self.components or table.cursor_row >= len(self.components):
|
|
317
|
+
self.notify("Nothing selected", severity="warning")
|
|
318
|
+
return None
|
|
319
|
+
return self.components[table.cursor_row]
|
|
320
|
+
|
|
321
|
+
def ready(self) -> bool:
|
|
322
|
+
"""Whether an action can start now."""
|
|
323
|
+
if self.pilot is None:
|
|
324
|
+
self.notify("No vinopilot command", severity="error")
|
|
325
|
+
return False
|
|
326
|
+
if self.job is not None:
|
|
327
|
+
self.notify(f"{self.job.label} is still running (Esc stops it)", severity="warning")
|
|
328
|
+
return False
|
|
329
|
+
if self.scanning:
|
|
330
|
+
self.notify("Still looking", severity="warning")
|
|
331
|
+
return False
|
|
332
|
+
return True
|
|
333
|
+
|
|
334
|
+
# --- actions -----------------------------------------------------------
|
|
335
|
+
|
|
336
|
+
def action_check(self) -> None:
|
|
337
|
+
if self.ready():
|
|
338
|
+
self.scan(True)
|
|
339
|
+
|
|
340
|
+
def action_install(self) -> None:
|
|
341
|
+
if not self.ready() or (c := self.selected()) is None:
|
|
342
|
+
return
|
|
343
|
+
if c.get("installed"):
|
|
344
|
+
self.notify(f"{c['name']} is already installed; use Update", severity="warning")
|
|
345
|
+
return
|
|
346
|
+
channels = c.get("channels") or []
|
|
347
|
+
if not channels:
|
|
348
|
+
self.notify(f"{c['name']} has nothing to install", severity="warning")
|
|
349
|
+
return
|
|
350
|
+
if len(channels) == 1:
|
|
351
|
+
self.run_job(self.pilot.install(c["id"], channels[0]))
|
|
352
|
+
return
|
|
353
|
+
options = [(ch, channel_label(c, ch)) for ch in channels]
|
|
354
|
+
self.push_screen(
|
|
355
|
+
ChooseScreen(f"Install {c['name']} from", options),
|
|
356
|
+
lambda via: via and self.run_job(self.pilot.install(c["id"], via)),
|
|
357
|
+
)
|
|
358
|
+
|
|
359
|
+
def action_update(self) -> None:
|
|
360
|
+
if not self.ready() or (c := self.selected()) is None:
|
|
361
|
+
return
|
|
362
|
+
if not c.get("installed"):
|
|
363
|
+
self.notify(f"{c['name']} isn't installed; use Install", severity="warning")
|
|
364
|
+
return
|
|
365
|
+
self.run_job(self.pilot.update(c["id"]))
|
|
366
|
+
|
|
367
|
+
def action_update_all(self) -> None:
|
|
368
|
+
if self.ready():
|
|
369
|
+
self.run_job(self.pilot.update_all())
|
|
370
|
+
|
|
371
|
+
def action_uninstall(self) -> None:
|
|
372
|
+
if not self.ready() or (c := self.selected()) is None:
|
|
373
|
+
return
|
|
374
|
+
installed = c.get("installed")
|
|
375
|
+
if not installed:
|
|
376
|
+
self.notify(f"{c['name']} isn't installed", severity="warning")
|
|
377
|
+
return
|
|
378
|
+
via = channel_label(c, installed["channel"])
|
|
379
|
+
self.push_screen(
|
|
380
|
+
ConfirmScreen(f"Uninstall {c['name']} ({via})?", "y uninstalls, n keeps it"),
|
|
381
|
+
lambda yes: yes and self.run_job(self.pilot.uninstall(c["id"])),
|
|
382
|
+
)
|
|
383
|
+
|
|
384
|
+
def action_steps(self) -> None:
|
|
385
|
+
if self.pilot is None or (c := self.selected()) is None:
|
|
386
|
+
return
|
|
387
|
+
options = [
|
|
388
|
+
(a, f"{a} ({channel_label(c, ch)})" if (ch := self.channel_for(c, a)) else a)
|
|
389
|
+
for a in ACTIONS
|
|
390
|
+
]
|
|
391
|
+
self.push_screen(
|
|
392
|
+
ChooseScreen(f"Show the steps for {c['name']}", options),
|
|
393
|
+
lambda action: action and self.show_steps(c, action),
|
|
394
|
+
)
|
|
395
|
+
|
|
396
|
+
def channel_for(self, c: dict, action: str) -> str | None:
|
|
397
|
+
"""The channel `vinopilot steps` would pick: how it's installed, else the first."""
|
|
398
|
+
installed = c.get("installed")
|
|
399
|
+
if installed:
|
|
400
|
+
return installed["channel"]
|
|
401
|
+
channels = c.get("channels") or []
|
|
402
|
+
return channels[0] if channels and action == "install" else None
|
|
403
|
+
|
|
404
|
+
def show_steps(self, c: dict, action: str) -> None:
|
|
405
|
+
assert self.pilot is not None
|
|
406
|
+
try:
|
|
407
|
+
text = self.pilot.steps(c["id"], action)
|
|
408
|
+
except (CommandError, OSError) as e:
|
|
409
|
+
self.log_line(f"✗ {e}")
|
|
410
|
+
return
|
|
411
|
+
self.push_screen(TextScreen(f"{action} {c['name']}: what would run", text))
|
|
412
|
+
|
|
413
|
+
def action_source_root(self) -> None:
|
|
414
|
+
if not self.ready():
|
|
415
|
+
return
|
|
416
|
+
self.push_screen(
|
|
417
|
+
InputScreen("Where source checkouts go", getattr(self, "source_root", "")),
|
|
418
|
+
self.set_source_root,
|
|
419
|
+
)
|
|
420
|
+
|
|
421
|
+
def set_source_root(self, path: str | None) -> None:
|
|
422
|
+
if not path or self.pilot is None:
|
|
423
|
+
return
|
|
424
|
+
try:
|
|
425
|
+
self.pilot.set_source_root(path)
|
|
426
|
+
except (CommandError, OSError) as e:
|
|
427
|
+
self.log_line(f"✗ {e}")
|
|
428
|
+
return
|
|
429
|
+
self.log_line(f"Source folder: {path}")
|
|
430
|
+
self.scan(self.checked)
|
|
431
|
+
|
|
432
|
+
def action_stop(self) -> None:
|
|
433
|
+
if self.job is not None:
|
|
434
|
+
self.job.stop()
|
|
435
|
+
self.log_line("Stopping…")
|
|
436
|
+
|
|
437
|
+
def action_quit(self) -> None:
|
|
438
|
+
if self.job is not None:
|
|
439
|
+
self.job.stop()
|
|
440
|
+
self.exit()
|
|
441
|
+
|
|
442
|
+
# --- jobs --------------------------------------------------------------
|
|
443
|
+
|
|
444
|
+
@work(thread=True, exclusive=True, group="job")
|
|
445
|
+
def run_job(self, job: Job) -> None:
|
|
446
|
+
self.job = job
|
|
447
|
+
self.call_from_thread(self.set_status, job.label)
|
|
448
|
+
self.call_from_thread(self.log_line, f"== {job.label}")
|
|
449
|
+
for event in job.events():
|
|
450
|
+
if event.kind == "line":
|
|
451
|
+
self.call_from_thread(self.log_line, event.text)
|
|
452
|
+
else:
|
|
453
|
+
self.call_from_thread(self.log_done, event)
|
|
454
|
+
self.job = None
|
|
455
|
+
self.call_from_thread(self.scan, self.checked)
|
|
456
|
+
|
|
457
|
+
def log_done(self, event: Event) -> None:
|
|
458
|
+
what = f" {event.app}" if event.app else ""
|
|
459
|
+
if event.outcome == "done":
|
|
460
|
+
self.log_line(f"✓ Done{what}")
|
|
461
|
+
elif event.outcome == "stopped":
|
|
462
|
+
self.log_line(f"Stopped{what}")
|
|
463
|
+
else:
|
|
464
|
+
self.log_line(f"✗ Failed{what}: {event.reason or 'see above'}")
|
|
465
|
+
|
|
466
|
+
def log_line(self, text: str) -> None:
|
|
467
|
+
self.query_one("#log", RichLog).write(text)
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
def main() -> None:
|
|
471
|
+
parser = argparse.ArgumentParser(prog="vinopilot-tui", description=__doc__.splitlines()[0])
|
|
472
|
+
parser.add_argument("--version", action="version", version=f"vinopilot-tui {__version__}")
|
|
473
|
+
parser.parse_args()
|
|
474
|
+
PilotApp().run()
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
if __name__ == "__main__":
|
|
478
|
+
main()
|
vinopilot_tui/app.tcss
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#status {
|
|
2
|
+
height: 1;
|
|
3
|
+
padding: 0 1;
|
|
4
|
+
background: $panel;
|
|
5
|
+
color: $text-muted;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
#table {
|
|
9
|
+
height: 1fr;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
#log {
|
|
13
|
+
height: 12;
|
|
14
|
+
border-top: solid $primary;
|
|
15
|
+
padding: 0 1;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
ChooseScreen, ConfirmScreen, TextScreen, InputScreen, MissingScreen {
|
|
19
|
+
align: center middle;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.dialog {
|
|
23
|
+
width: 72;
|
|
24
|
+
height: auto;
|
|
25
|
+
max-height: 90%;
|
|
26
|
+
border: thick $primary;
|
|
27
|
+
background: $surface;
|
|
28
|
+
padding: 1 2;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
TextScreen .dialog {
|
|
32
|
+
width: 90%;
|
|
33
|
+
height: 90%;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
TextScreen VerticalScroll {
|
|
37
|
+
height: 1fr;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
MissingScreen .dialog {
|
|
41
|
+
width: 84;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
#missing-log {
|
|
45
|
+
height: 10;
|
|
46
|
+
margin-top: 1;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.title {
|
|
50
|
+
text-style: bold;
|
|
51
|
+
margin-bottom: 1;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.hint {
|
|
55
|
+
color: $text-muted;
|
|
56
|
+
margin-top: 1;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.buttons {
|
|
60
|
+
height: auto;
|
|
61
|
+
margin-top: 1;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.buttons Button {
|
|
65
|
+
margin-right: 2;
|
|
66
|
+
}
|
vinopilot_tui/cli.py
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"""The Rust `vinopilot` command, driven through `--json` (docs/json-api.md).
|
|
2
|
+
|
|
3
|
+
Nothing here knows the catalog: which apps exist, how they install, what's
|
|
4
|
+
newer. That all comes back as JSON from the command.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import json
|
|
10
|
+
import os
|
|
11
|
+
import shutil
|
|
12
|
+
import subprocess
|
|
13
|
+
from collections.abc import Iterator
|
|
14
|
+
from dataclasses import dataclass, field
|
|
15
|
+
|
|
16
|
+
INSTALLER = "https://github.com/karanshukla/vinopilot/releases/latest/download/install.sh"
|
|
17
|
+
|
|
18
|
+
# How the missing-command screen gets the command: the release installer,
|
|
19
|
+
# hash-checked by itself, without the window. Patched in tests.
|
|
20
|
+
INSTALL_COMMAND = ["bash", "-c", f"curl -fsSL {INSTALLER} | bash -s -- --no-gui"]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def find() -> str | None:
|
|
24
|
+
"""`$VINOPILOT_BIN`, else `vinopilot` on PATH or in `~/.local/bin`
|
|
25
|
+
(where the release installer puts it, PATH or not)."""
|
|
26
|
+
pinned = os.environ.get("VINOPILOT_BIN")
|
|
27
|
+
if pinned:
|
|
28
|
+
return pinned if os.access(pinned, os.X_OK) else None
|
|
29
|
+
path = os.environ.get("PATH", os.defpath)
|
|
30
|
+
local = os.path.join(os.path.expanduser("~"), ".local", "bin")
|
|
31
|
+
return shutil.which("vinopilot", path=f"{path}{os.pathsep}{local}")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class CommandError(Exception):
|
|
35
|
+
"""The command exited non-zero where a document was expected."""
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@dataclass(frozen=True)
|
|
39
|
+
class Event:
|
|
40
|
+
"""One line of an action's output, or its end."""
|
|
41
|
+
|
|
42
|
+
kind: str # "line" or "done"
|
|
43
|
+
text: str = ""
|
|
44
|
+
app: str = ""
|
|
45
|
+
channel: str = ""
|
|
46
|
+
outcome: str = "" # done, stopped, failed
|
|
47
|
+
reason: str = ""
|
|
48
|
+
|
|
49
|
+
@staticmethod
|
|
50
|
+
def parse(line: str) -> Event:
|
|
51
|
+
try:
|
|
52
|
+
doc = json.loads(line)
|
|
53
|
+
except ValueError:
|
|
54
|
+
# The command's own stderr, merged in: usage errors, `✗ ...`.
|
|
55
|
+
return Event("line", text=line)
|
|
56
|
+
if not isinstance(doc, dict) or doc.get("event") not in ("line", "done"):
|
|
57
|
+
return Event("line", text=line)
|
|
58
|
+
if doc["event"] == "line":
|
|
59
|
+
return Event("line", text=str(doc.get("text", "")))
|
|
60
|
+
result = doc.get("result") or {}
|
|
61
|
+
return Event(
|
|
62
|
+
"done",
|
|
63
|
+
app=str(doc.get("app", "")),
|
|
64
|
+
channel=str(doc.get("channel", "")),
|
|
65
|
+
outcome=str(result.get("outcome", "failed")),
|
|
66
|
+
reason=str(result.get("reason") or ""),
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
@dataclass
|
|
71
|
+
class Job:
|
|
72
|
+
"""A running install, update or uninstall; iterate `events()` to follow it."""
|
|
73
|
+
|
|
74
|
+
process: subprocess.Popen[str]
|
|
75
|
+
label: str
|
|
76
|
+
done: list[Event] = field(default_factory=list)
|
|
77
|
+
|
|
78
|
+
def events(self) -> Iterator[Event]:
|
|
79
|
+
assert self.process.stdout is not None
|
|
80
|
+
last = ""
|
|
81
|
+
for raw in self.process.stdout:
|
|
82
|
+
line = raw.rstrip("\n")
|
|
83
|
+
event = Event.parse(line)
|
|
84
|
+
if event.kind == "done":
|
|
85
|
+
self.done.append(event)
|
|
86
|
+
else:
|
|
87
|
+
last = event.text or last
|
|
88
|
+
yield event
|
|
89
|
+
code = self.process.wait()
|
|
90
|
+
if not self.done:
|
|
91
|
+
# Exited without saying so: a usage error, a crash, or stopped
|
|
92
|
+
# before it started.
|
|
93
|
+
outcome = "stopped" if code < 0 else ("done" if code == 0 else "failed")
|
|
94
|
+
event = Event("done", outcome=outcome, reason=last if outcome == "failed" else "")
|
|
95
|
+
self.done.append(event)
|
|
96
|
+
yield event
|
|
97
|
+
|
|
98
|
+
def stop(self) -> None:
|
|
99
|
+
"""Ends the job. A pkexec child is root's and outlives this."""
|
|
100
|
+
if self.process.poll() is None:
|
|
101
|
+
self.process.terminate()
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
@dataclass(frozen=True)
|
|
105
|
+
class Pilot:
|
|
106
|
+
"""A `vinopilot` binary."""
|
|
107
|
+
|
|
108
|
+
bin: str
|
|
109
|
+
|
|
110
|
+
def _args(self, *args: str, source_root: str | None = None) -> list[str]:
|
|
111
|
+
argv = [self.bin]
|
|
112
|
+
if source_root:
|
|
113
|
+
argv += ["--source-root", source_root]
|
|
114
|
+
return argv + list(args)
|
|
115
|
+
|
|
116
|
+
def _run(self, *args: str, json_out: bool = True) -> str:
|
|
117
|
+
argv = self._args(*args)
|
|
118
|
+
if json_out:
|
|
119
|
+
argv.insert(1, "--json")
|
|
120
|
+
out = subprocess.run(argv, capture_output=True, text=True, stdin=subprocess.DEVNULL)
|
|
121
|
+
if out.returncode != 0:
|
|
122
|
+
raise CommandError((out.stderr or out.stdout).strip() or f"exit {out.returncode}")
|
|
123
|
+
return out.stdout
|
|
124
|
+
|
|
125
|
+
def version(self) -> str:
|
|
126
|
+
"""`0.1.0`, from `vinopilot --version`."""
|
|
127
|
+
return self._run("--version", json_out=False).split()[-1]
|
|
128
|
+
|
|
129
|
+
def list(self) -> dict:
|
|
130
|
+
"""The offline document: what's installed, and how."""
|
|
131
|
+
return json.loads(self._run("list"))
|
|
132
|
+
|
|
133
|
+
def check(self) -> dict:
|
|
134
|
+
"""The same, plus `latest` and a judged `update`. Goes online."""
|
|
135
|
+
return json.loads(self._run("check"))
|
|
136
|
+
|
|
137
|
+
def steps(self, app: str, action: str, via: str | None = None) -> str:
|
|
138
|
+
"""The shell an action would run, as text."""
|
|
139
|
+
args = ["steps", app, action]
|
|
140
|
+
if via:
|
|
141
|
+
args += ["--via", via]
|
|
142
|
+
return self._run(*args, json_out=False)
|
|
143
|
+
|
|
144
|
+
def source_root(self) -> str:
|
|
145
|
+
return json.loads(self._run("config"))["source_root"]
|
|
146
|
+
|
|
147
|
+
def set_source_root(self, path: str) -> None:
|
|
148
|
+
self._run("config", "source_root", path, json_out=False)
|
|
149
|
+
|
|
150
|
+
def start(self, label: str, *args: str) -> Job:
|
|
151
|
+
"""Starts an action; its output arrives as `Event`s, stderr merged in."""
|
|
152
|
+
argv = self._args(*args)
|
|
153
|
+
argv.insert(1, "--json")
|
|
154
|
+
process = subprocess.Popen(
|
|
155
|
+
argv,
|
|
156
|
+
stdin=subprocess.DEVNULL,
|
|
157
|
+
stdout=subprocess.PIPE,
|
|
158
|
+
stderr=subprocess.STDOUT,
|
|
159
|
+
text=True,
|
|
160
|
+
bufsize=1,
|
|
161
|
+
)
|
|
162
|
+
return Job(process, label)
|
|
163
|
+
|
|
164
|
+
def install(self, app: str, via: str) -> Job:
|
|
165
|
+
return self.start(f"Installing {app}", "install", app, "--via", via)
|
|
166
|
+
|
|
167
|
+
def update(self, app: str) -> Job:
|
|
168
|
+
return self.start(f"Updating {app}", "update", app)
|
|
169
|
+
|
|
170
|
+
def update_all(self) -> Job:
|
|
171
|
+
return self.start("Updating everything", "update", "--all")
|
|
172
|
+
|
|
173
|
+
def uninstall(self, app: str) -> Job:
|
|
174
|
+
return self.start(f"Uninstalling {app}", "uninstall", app, "--yes")
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def installer() -> Job:
|
|
178
|
+
"""Runs the release installer, to get the command when there is none."""
|
|
179
|
+
process = subprocess.Popen(
|
|
180
|
+
INSTALL_COMMAND,
|
|
181
|
+
stdin=subprocess.DEVNULL,
|
|
182
|
+
stdout=subprocess.PIPE,
|
|
183
|
+
stderr=subprocess.STDOUT,
|
|
184
|
+
text=True,
|
|
185
|
+
bufsize=1,
|
|
186
|
+
)
|
|
187
|
+
return Job(process, "Installing vinopilot")
|