Skip to content

Commit

Permalink
Pull out the table padding logic into a common file
Browse files Browse the repository at this point in the history
Going to be applying it to the status table soon and I need this to
avoid copy/pasting all of the padding arithmetic.

This also updates the is_status output to look more like the status
output, showing real time stdout/stderr.
  • Loading branch information
naddeoa committed Jan 7, 2024
1 parent 9e434ee commit a5e5d44
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 45 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from naddeoa/booty:ubuntu22.04

RUN --mount=type=cache,target=/var/cache/apt sudo apt install -y python3 python3-pip # MANUAL install pip
RUN sudo apt-get update
RUN --mount=type=cache,target=/var/cache/apt sudo apt-get install -y python3 python3-pip # MANUAL install pip
COPY ./dist/*.whl ./
RUN --mount=type=cache,target=/home/myuser/.cache pip install --user ./*.whl # MANUAL install booty

Expand Down
4 changes: 2 additions & 2 deletions Dockerfile.base
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ from ubuntu:22.04
ENV DEBIAN_FRONTEND=noninteractive

RUN --mount=type=cache,target=/var/cache/apt <<EOF
apt update && apt upgrade -y
apt install -y sudo locales keyboard-configuration
apt-get update && apt-get upgrade -y
apt-get install -y sudo locales keyboard-configuration
EOF

# Set the timezone
Expand Down
1 change: 1 addition & 0 deletions Dockerfile.binary
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from naddeoa/booty:ubuntu22.04

RUN sudo apt-get update
COPY ./ssh ./.ssh
RUN sudo chown -R myuser:myuser ./.ssh
RUN chmod 600 .ssh/id_rsa
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Or download the appropriate binary from the latest release. This script just dow
move it somewhere on your path. The script will drop it in your `pwd`.

## Linux

```bash
curl https://raw.githubusercontent.com/naddeoa/booty/master/scripts/booty-download-linux.sh | bash
```
Expand All @@ -36,6 +37,7 @@ curl https://raw.githubusercontent.com/naddeoa/booty/master/scripts/booty-downlo
```

## Mac Arm

```bash
curl https://raw.githubusercontent.com/naddeoa/booty/master/scripts/booty-download-mac-universal.sh | bash
```
Expand All @@ -56,7 +58,7 @@ Options:
-i, --install Install all uninstalled targets
-d, --debug See the AST of the config file
-l, --log-dir TEXT Where to store logs. Defaults to ./logs
--no-sudo Don't allow booty to prompt with sudo -v. Instead, you
--no-sudo Don't allow booty to prompt with sudo -v. Instead, you
can manually run sudo -v before using booty to cache
credentials for any targets that use sudo. By default,
booty runs sudo -v upfront if you use sudo in any
Expand Down Expand Up @@ -263,4 +265,3 @@ There are a lot of good things about make though. My favorite relevant parts are

- Easy, independent dependency specification
- Plain old shell for each target definition.

3 changes: 3 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

Some features that might be useful. If you feel up to contributing then these could be a good starting place.

- Language spec
- import system and package system

- Debug display issues with scrolling/collapsing tree during steup. This probably because the height of the table decreases and then the
tallest area is "orphaned". I probably have to have a constant wosrt case padding at the bottom of the table, wich would be 12 lines?
- Refactor release process to delay the release creation until the last step. There is a period now where the copy/paste install fails
Expand Down
31 changes: 17 additions & 14 deletions booty/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,19 @@ def status(self) -> StatusResult:
status_result = StatusResult()
total_time = 0.0

group = Group(table, overall_progress)
with Live(group, refresh_per_second=_REFRESH_RATE):
padder = Padder()
padding = Padding(table, (0, 0, 0, 0))
group = Group(padding, overall_progress)

with Live(auto_refresh=False) as live:
for target in self.data.G.iterator():
deps_string = dependency_strings[target]

target_text = Text(target)
dependency_text = Text(deps_string)
status_text = Text("🟡 Checking...")

tree = StdTree(self._display_setup(self.data.execution_index[target]))
tree = StdTree(self._display_is_setup(self.data.execution_index[target]))

time_text = Text("") # Make update in real time

Expand All @@ -137,6 +140,10 @@ def status(self) -> StatusResult:
cmd = CommandExecutor(self.data, target, "is_setup")
for _ in cmd.execute():
time_text.plain = f"{time.perf_counter() - start_time:.2f}s"
tree.set_stdout(cmd.latest_stdout())
tree.set_stderr(cmd.latest_stderr())
padding.bottom = padder.get_padding(tree)
live.update(group, refresh=True)

target_time = time.perf_counter() - start_time
total_time += target_time
Expand All @@ -160,6 +167,7 @@ def status(self) -> StatusResult:
self.logger.log_is_setup(target, cmd.all_stdout(), cmd.all_stderr())

overall_progress.advance(overall_id)
live.update(group, refresh=True)

overall_progress.update(overall_id, completed=True)
overall_progress.update(overall_id, visible=False)
Expand All @@ -181,16 +189,14 @@ def install_missing(self, status_result: StatusResult) -> StatusResult:
overall_progress = Progress()
overall_id = overall_progress.add_task("Status", total=len(missing_packages))

# table_padding = Text("\n" * (len(missing_packages) + 1))

max_padding = 0
padder = Padder()
padding = Padding(table, (0, 0, 0, 0))
group = Group(padding, overall_progress)

total_time = 0.0
status_result = StatusResult()
gen = self.data.G.bfs()
with Live() as live:
with Live(auto_refresh=False) as live:
try:
next(gen) # Skip the first fake target
target = gen.send(True)
Expand All @@ -214,9 +220,8 @@ def install_missing(self, status_result: StatusResult) -> StatusResult:
time_text.plain = f"{time.perf_counter() - start_time:.2f}s"
tree.set_stdout(cmd.latest_stdout())
tree.set_stderr(cmd.latest_stderr())
max_padding = max(max_padding, tree.height())
padding.bottom = abs(max_padding - tree.height())
live.update(group)
padding.bottom = padder.get_padding(tree)
live.update(group, refresh=True)

cmd_time = time.perf_counter() - start_time
time_text.plain = f"{cmd_time:.2f}s"
Expand All @@ -226,17 +231,15 @@ def install_missing(self, status_result: StatusResult) -> StatusResult:
status_result.installed.append(target)
status_text.plain = "🟢 Installed"
tree.reset()
padding.bottom = abs(max_padding - tree.height())
live.update(group)

padding.bottom = padder.get_padding(tree)
else:
status_text.plain = "🔴 Error"
self.logger.log_setup(target, cmd.all_stdout(), cmd.all_stderr())
status_result.errors.append(target)

target = gen.send(cmd.code == 0)
overall_progress.advance(overall_id)
live.update(group)
live.update(group, refresh=True)

except StopIteration as e:
skipped: List[str] = e.value
Expand Down
1 change: 0 additions & 1 deletion booty/lang/stdlib.booty
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ recipe apt(packages):

recipe ppa(name):
setup:
apt(software-properties-common)
sudo add-apt-repository -y $((name))
sudo apt-get update
is_setup: grep $((name)) /etc/apt/sources.list
Expand Down
26 changes: 6 additions & 20 deletions booty/ui.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
from typing import List, Optional
from rich.console import Group
from rich.live import Live
from rich.progress import Progress
from rich.padding import Padding
from rich.table import Table
from rich.text import Text
from rich.tree import Tree

Expand Down Expand Up @@ -68,20 +63,11 @@ def height(self) -> int:
return cmd_height + stdout_height + stderr_height


class PaddedTable:
def __init__(self, table: Table, total: int) -> None:
self.table = table
self._progress = Progress()
# self.progress_id = progress.add_task("Status", total=total)
class Padder:
def __init__(self) -> None:
self._max_padding = 0
self._padding = Padding(table, (0, 0, 0, 0))
self._group = Group(self._padding, self._progress)

# def get_std_tree(self, cmd: str) -> StdTree:
# self.std_tree = StdTree(self._display_setup(self.data.execution_index[target]))

def update(self, live: Live) -> None:
pass

# self._padding.bottom = abs(self._max_padding - self.std_tree.height())
# live.update(group)
def get_padding(self, tree: StdTree) -> int:
height = tree.height()
self._max_padding = max(self._max_padding, height)
return self._max_padding - height
3 changes: 2 additions & 1 deletion examples/install.booty
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

essentials: apt(wget git vim autokey-gtk silversearcher-ag gawk xclip
gnome-disk-utility cryptsetup build-essential dconf-editor ripgrep xdotool
luarocks cmake libterm-readkey-perl expect ssh curl fzf)
luarocks cmake libterm-readkey-perl expect ssh curl fzf software-properties-common)

files.git -> essentials
files.git: git([email protected]:~/git/files, ~/files)
Expand Down Expand Up @@ -141,6 +141,7 @@ node:
## Racket
##

racket -> essentials
racket:
setup:
ppa(ppa:plt/racket)
Expand Down
9 changes: 5 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@ keywords = ["bootstrap", "booty", "setup", "cli", "tool"]
authors = ["Anthony Naddeo <[email protected]>"]
license = "MIT"
readme = "README.md"
packages = [{ include = "booty/**/*.py" }]

packages = [
{ include = "booty/**/*.py"},
{ include = "booty/**/*.lark"},
{ include = "booty/**/*.booty"}
]

[tool.poetry.scripts]
booty = "booty.cli:cli"


[tool.poetry.dependencies]
python = ">=3.9, <3.13"
lark = "^1.1.8"
click = "^8.1.7"
rich = "^13.7.0"


[tool.poetry.group.dev.dependencies]
pyright = "^1.1.338"
ruff = "^0.1.7"
Expand Down

0 comments on commit a5e5d44

Please sign in to comment.