PaganOS Luna 0.6.0
PL EN DE
← pag

Commit e7401ee

3
plików
+801
dodanych
-45
usuniętych
@@ -24,6 +24,7 @@ pag --help # same as above
24 24 - [Quick start](#quick-start)
25 25 - [How it works](#how-it-works)
26 26 - [`pag install` flow](#pag-install-flow)
27 + - [Parallel downloads – per-package status](#parallel-downloads--per-package-status)
27 28 - [Trust chain](#trust-chain)
28 29 - [Immutable system](#immutable-system)
29 30 - [Rollback](#rollback)
@@ -102,6 +103,27 @@ Key properties:
102 103 - **File sharing** – a file owned by two packages is not removed when one of
103 104 them is removed (only the database entry is removed).
104 105
106 +### Parallel downloads – per-package status
107 +
108 +When installing or updating many packages, pag downloads them in parallel
109 +(up to 4 workers) and shows **a separate animated line for every active
110 +download** – with the percentage, package name, bytes downloaded and ETA:
111 +
112 +```text
113 + ⏬ [▓▓▓▓▓█▓»~_~_~_~_~_~_] 7/12 (58%)
114 + ↓ [███»~~~~~~] 38% (mesa: 12.3/29.1 MB, ETA 8s)
115 + ↓ [█████»~~~~] 67% (glibc: 8.8/10.0 MB, ETA 3s)
116 + ↓ [▓▓▓▓▓▓▓▓»~] 91% (linux-firmware: 26.2/28.7 MB, ETA 2s)
117 + ✅ python-3.14.0 (30.1 MB, 14s)
118 +```
119 +
120 +Completed downloads stay in the scrollback, while the overall bar counts
121 +finished packages. Outside a TTY (installer logs, cron) pag emits no ANSI
122 +sequences – it prints a start line, 25/50/75% milestones and the result.
123 +
124 +The bar appearance can be changed with `PAG_NO_ANIM=1` (static bar) and
125 +`PAG_BAR_STYLE=snake|classic` (default: `drakkar`).
126 +
105 127 ### Trust chain
106 128
107 129 ```mermaid
@@ -289,6 +311,16 @@ Flathub and suggests names – e.g. `pag firefox` will find the package.
289 311 | `pag initramfs-update` | Rebuild initramfs |
290 312 | `pag grub-update` | Regenerate GRUB entries for all deployments |
291 313
314 +### EASTER EGG
315 +
316 +| Command | Description |
317 +|---|---|
318 +| `pag wroom` | Hidden, animated Commodore-style ASCII racing game (3 lanes, collisions, session best) |
319 +
320 +Controls: `←/→` (or `A/D`) change lane, `↑/↓` (or `W/S`) gas/brake,
321 +`P` pause, `R`/`SPACE` restart, `Q` quit. The game only runs in a terminal,
322 +does not require root and is not listed in `pag --help`.
323 +
292 324 ---
293 325
294 326 ## Environment variables
@@ -303,6 +335,8 @@ Flathub and suggests names – e.g. `pag firefox` will find the package.
303 335 | `PAG_HOOK_TIMEOUT` | Hook timeout in seconds (default `60`) |
304 336 | `PAG_LANG_DIR` | Directory with translation files (`pl.json`, `en.json`) |
305 337 | `PAG_LANG_NO_FILES=1` | Ignore translation files (export built-ins) |
338 +| `PAG_NO_ANIM=1` | Disable progress bar animation (static bar) |
339 +| `PAG_BAR_STYLE` | Progress bar style: `drakkar` (default), `snake`, `classic` |
306 340 | `PAG_ROOT_DEVICE` / `PAG_GRUB_ROOT` | Explicit `root=` for GRUB (ISO/IMG build) |
307 341 | `PAG_IN_CHROOT=1` | Force chroot mode when detecting the root device |
308 342
@@ -24,6 +24,7 @@ pag --help # to samo co wyżej
24 24 - [Szybki start](#szybki-start)
25 25 - [Jak to działa](#jak-to-działa)
26 26 - [Przepływ `pag install`](#przepływ-pag-install)
27 + - [Pobieranie równoległe – status każdej paczki](#pobieranie-równoległe--status-każdej-paczki)
27 28 - [Łańcuch zaufania](#łańcuch-zaufania)
28 29 - [System immutable](#system-immutable)
29 30 - [Rollback](#rollback)
@@ -102,6 +103,27 @@ Kluczowe własności:
102 103 - **Współdzielenie plików** – plik należący do dwóch pakietów nie jest usuwany
103 104 przy usunięciu jednego z nich (usuwany jest tylko wpis w bazie).
104 105
106 +### Pobieranie równoległe – status każdej paczki
107 +
108 +Przy instalacji lub aktualizacji wielu pakietów pag pobiera je równolegle
109 +(do 4 wątków) i pokazuje **osobny, animowany wiersz dla każdego aktywnego
110 +pobierania** – z procentem, nazwą paczki, liczbą pobranych bajtów i ETA:
111 +
112 +```text
113 + ⏬ [▓▓▓▓▓█▓»~_~_~_~_~_~_] 7/12 (58%)
114 + ↓ [███»~~~~~~] 38% (mesa: 12.3/29.1 MB, ETA 8s)
115 + ↓ [█████»~~~~] 67% (glibc: 8.8/10.0 MB, ETA 3s)
116 + ↓ [▓▓▓▓▓▓▓▓»~] 91% (linux-firmware: 26.2/28.7 MB, ETA 2s)
117 + ✅ python-3.14.0 (30.1 MB, 14s)
118 +```
119 +
120 +Ukończone pobrania zostają w scrollbacku, a pasek zbiorczy pokazuje liczbę
121 +gotowych paczek. Poza TTY (logi instalatora, cron) pag nie używa sekwencji
122 +ANSI – wypisuje linię startu, kamienie milowe 25/50/75% i wynik.
123 +
124 +Wygląd pasków można zmienić: `PAG_NO_ANIM=1` (statyczny pasek),
125 +`PAG_BAR_STYLE=snake|classic` (domyślnie `drakkar`).
126 +
105 127 ### Łańcuch zaufania
106 128
107 129 ```mermaid
@@ -289,6 +311,16 @@ i Flathub oraz podpowiada nazwy – np. `pag firefox` znajdzie pakiet.
289 311 | `pag initramfs-update` | Przebudowuje initramfs |
290 312 | `pag grub-update` | Regeneruje wpisy GRUB dla wszystkich wdrożeń |
291 313
314 +### EASTER EGG
315 +
316 +| Komenda | Opis |
317 +|---|---|
318 +| `pag wroom` | Ukryty, animowany wyścig ASCII w stylu Commodore (3 pasy, kolizje, rekord sesji) |
319 +
320 +Sterowanie: `←/→` (lub `A/D`) zmiana pasa, `↑/↓` (lub `W/S`) gaz/hamulec,
321 +`P` pauza, `R`/`SPACJA` restart, `Q` wyjście. Gra działa tylko w terminalu,
322 +nie wymaga roota i nie jest pokazywana w `pag --help`.
323 +
292 324 ---
293 325
294 326 ## Zmienne środowiskowe
@@ -303,6 +335,8 @@ i Flathub oraz podpowiada nazwy – np. `pag firefox` znajdzie pakiet.
303 335 | `PAG_HOOK_TIMEOUT` | Timeout hooka w sekundach (domyślnie `60`) |
304 336 | `PAG_LANG_DIR` | Katalog z plikami tłumaczeń (`pl.json`, `en.json`) |
305 337 | `PAG_LANG_NO_FILES=1` | Ignoruje pliki tłumaczeń (eksport wbudowanych) |
338 +| `PAG_NO_ANIM=1` | Wyłącza animację pasków postępu (statyczny pasek) |
339 +| `PAG_BAR_STYLE` | Styl paska postępu: `drakkar` (domyślnie), `snake`, `classic` |
306 340 | `PAG_ROOT_DEVICE` / `PAG_GRUB_ROOT` | Jawny `root=` dla GRUB (build ISO/IMG) |
307 341 | `PAG_IN_CHROOT=1` | Wymusza tryb chroot przy wykrywaniu urządzenia root |
308 342
@@ -144,6 +144,48 @@ def _classic_bar(pct: float, width: int) -> str:
144 144 return "█" * filled + "░" * (width - filled)
145 145
146 146
147 +def _fmt_size(n: float) -> str:
148 + """Rozmiar w czytelnych jednostkach (1.2 MB, 345.6 KB)."""
149 + for unit in ("B", "KB", "MB", "GB"):
150 + if n < 1024:
151 + return f"{n:.1f} {unit}"
152 + n /= 1024
153 + return f"{n:.1f} TB"
154 +
155 +
156 +def _fmt_eta(seconds: float) -> str:
157 + """Czas pozostały w zwięzłej formie: 8s, 1.4m, 2.1h."""
158 + if seconds < 60:
159 + return f"{seconds:.0f}s"
160 + if seconds < 3600:
161 + return f"{seconds / 60:.1f}m"
162 + return f"{seconds / 3600:.1f}h"
163 +
164 +
165 +def _shrink_text(text: str, room: int) -> str:
166 + """Skróć `text` do `room` kolumn (wielokropek na końcu)."""
167 + if room <= 0:
168 + return ""
169 + if len(text) <= room:
170 + return text
171 + return "…" if room == 1 else text[:room - 1] + "…"
172 +
173 +
174 +def _fit_widget_line(line: str, stream) -> str:
175 + """Przytnij linię panelu do szerokości terminala (bez zawijania).
176 +
177 + Zawinięta linia rozjeżdża wielolinijkowy panel: kolejne odświeżenia
178 + trafiają do nowych wierszy zamiast nadpisywać poprzednie.
179 + """
180 + cap = _term_width(stream) - _BAR_MARGIN
181 + if cap <= 0 or len(line) <= cap:
182 + return line
183 + keep = cap - 1
184 + head = (keep + 1) // 2
185 + tail = keep - head
186 + return line[:head] + "…" + (line[-tail:] if tail > 0 else "")
187 +
188 +
147 189 def _drakkar_bar(pct: float, width: int, t: float, filled: int) -> str:
148 190 """Drakkar (łódź wikingów) płynący po falującym morzu.
149 191
@@ -309,8 +351,7 @@ class ProgressBar(_Bar):
309 351 if self.n >= self.total:
310 352 eta_str = _("done")
311 353 elif speed > 0:
312 - eta = (self.total - self.n) / speed
313 - eta_str = f"{eta:.0f}s" if eta < 60 else f"{eta/60:.1f}m"
354 + eta_str = _fmt_eta((self.total - self.n) / speed)
314 355 else:
315 356 eta_str = "?..."
316 357 bar = _pagan_bar(pct, self.width, time.time(), animated=self.tty)
@@ -359,13 +400,12 @@ class DownloadBar(_Bar):
359 400 elapsed = time.time() - self.start
360 401 speed = self.downloaded / elapsed if elapsed > 0 else 0
361 402 if self.total > 0 and speed > 0:
362 - eta = (self.total - self.downloaded) / speed
363 - eta_str = f"{eta:.0f}s" if eta < 60 else f"{eta/60:.1f}m"
403 + eta_str = _fmt_eta((self.total - self.downloaded) / speed)
364 404 else:
365 405 eta_str = "?..."
366 406 bar = _pagan_bar(pct, self.width, time.time(), animated=self.tty)
367 - sz = self._fmt_size(self.total)
368 - spd = self._fmt_size(int(speed))
407 + sz = _fmt_size(self.total)
408 + spd = _fmt_size(int(speed))
369 409 tail = f" [{bar}] {pct:.0f}% {sz} {spd}/s ETA {eta_str}"
370 410 # Nazwa pliku bywa długa (np. linux-firmware-…-1.pag) i wtedy CAŁA linia
371 411 # nie mieści się w terminalu (zawijanie → nowa linia przy każdym %).
@@ -385,13 +425,192 @@ class DownloadBar(_Bar):
385 425 if self.total > 0:
386 426 self._newline()
387 427
388 - @staticmethod
389 - def _fmt_size(n: int) -> str:
390 - for unit in ("B", "KB", "MB", "GB"):
391 - if n < 1024:
392 - return f"{n:.1f} {unit}"
393 - n /= 1024
394 - return f"{n:.1f} TB"
428 +
429 +class _ParallelDownloadDisplay:
430 + """Panel pobierania równoległego: pasek zbiorczy + linia na każde pobranie.
431 +
432 + Linia pobrania pokazuje procent, a w nawiasie nazwę pakietu, liczbę
433 + pobranych bajtów i ETA – czyli dokładnie to, czego brakowało przy
434 + równoległym pobieraniu:
435 +
436 + ⏬ [████»~~~~] 4/12 (33%)
437 + ↓ [███»~~~~~~] 38% (mesa: 12.3/29.1 MB, ETA 8s)
438 + ↓ [█████»~~~~] 67% (glibc: 8.8/10.0 MB, ETA 3s)
439 +
440 + Na TTY panel jest rysowany „w miejscu” (ANSI): pasek zbiorczy i aktywne
441 + pobrania są nadpisywane, a ukończone pobrania zostają wypisane na stałe
442 + nad panelem. Poza TTY nie ruszamy kursora – log dostaje linię startu,
443 + kamienie milowe (25/50/75%) i wynik, więc pozostaje czytelny.
444 + """
445 + BAR_W = 20
446 + _POLL = 0.1
447 +
448 + def __init__(self, total: int, stream=None):
449 + self.stream = stream if stream is not None else sys.stderr
450 + self.tty = self.stream.isatty()
451 + self.total = max(1, int(total))
452 + self.completed = 0
453 + self._lock = threading.RLock()
454 + self._slots: Dict[int, dict] = {}
455 + self._next_id = 0
456 + self._drawn = 0
457 + self._stop = threading.Event()
458 + self._thread = None
459 + self._cursor_hidden = False
460 + if self.tty:
461 + self._emit("\x1b[?25l") # ukryj kursor na czas panelu
462 + self._cursor_hidden = True
463 + self._thread = threading.Thread(target=self._anim_loop, daemon=True)
464 + self._thread.start()
465 +
466 + # -- rysowanie -----------------------------------------------------------
467 + def _emit(self, text: str):
468 + with _DRAW_LOCK:
469 + self.stream.write(text)
470 + self.stream.flush()
471 +
472 + def _cap(self) -> int:
473 + return _term_width(self.stream) - _BAR_MARGIN
474 +
475 + def _clear_panel(self):
476 + """Wyczyść panel i ustaw kursor na początku jego pierwszej linii."""
477 + if not self.tty or self._drawn <= 0:
478 + return
479 + out = ["\r\x1b[2K"]
480 + out.extend("\x1b[1A\r\x1b[2K" for _ in range(self._drawn - 1))
481 + self._emit("".join(out))
482 + self._drawn = 0
483 +
484 + def _render_locked(self):
485 + if not self.tty:
486 + return
487 + self._clear_panel()
488 + lines = [self._overall_line()]
489 + lines.extend(self._slot_line(s) for s in self._slots.values())
490 + self._emit("\n".join(lines))
491 + self._drawn = len(lines)
492 +
493 + def _render(self):
494 + with self._lock:
495 + self._render_locked()
496 +
497 + def _anim_loop(self):
498 + while not self._stop.wait(self._POLL):
499 + self._render()
500 +
501 + def _overall_line(self) -> str:
502 + pct = self.completed / self.total * 100.0
503 + bar = _pagan_bar(pct, self.BAR_W, time.time(), animated=self.tty)
504 + line = f" ⏬ [{bar}] {self.completed}/{self.total} ({pct:.0f}%)"
505 + return _fit_widget_line(line, self.stream)
506 +
507 + def _slot_line(self, s: dict) -> str:
508 + total = int(s.get("total") or 0)
509 + done = int(s.get("downloaded") or 0)
510 + pct = (done / total * 100.0) if total > 0 else 0.0
511 + elapsed = time.time() - s["start"]
512 + speed = done / elapsed if elapsed > 0 else 0.0
513 + finished = total > 0 and done >= total
514 + if finished:
515 + eta = _("done")
516 + elif total > 0 and speed > 0:
517 + eta = _fmt_eta((total - done) / speed)
518 + else:
519 + eta = "?…"
520 + bar = _pagan_bar(pct, self.BAR_W, time.time(), animated=self.tty)
521 + prefix = f" ↓ [{bar}] {pct:3.0f}% "
522 + size = (f"{_fmt_size(done)}/{_fmt_size(total)}" if total > 0
523 + else _fmt_size(done))
524 + suffix = (f": {size}, {eta})" if finished
525 + else f": {size}, ETA {eta})")
526 + # Nazwa bywa długa – skracamy TYLKO ją, zostawiając %, rozmiar i ETA.
527 + room = self._cap() - len(prefix) - 1 - len(suffix)
528 + name = _shrink_text(s["name"], room)
529 + return _fit_widget_line(f"{prefix}({name}{suffix}", self.stream)
530 +
531 + # -- API wątków pobierających --------------------------------------------
532 + def start(self, name: str, expected_size: int = 0) -> int:
533 + with self._lock:
534 + sid = self._next_id
535 + self._next_id += 1
536 + self._slots[sid] = {
537 + "name": name,
538 + "downloaded": 0,
539 + "total": int(expected_size or 0),
540 + "start": time.time(),
541 + "milestone": -1,
542 + }
543 + if self.tty:
544 + self._render_locked()
545 + else:
546 + self._emit(f" ↓ {name}\n")
547 + return sid
548 +
549 + def progress(self, sid: int, downloaded: int, total: int = 0):
550 + with self._lock:
551 + s = self._slots.get(sid)
552 + if s is None:
553 + return
554 + s["downloaded"] = int(downloaded)
555 + if total and total > 0:
556 + s["total"] = int(total)
557 + if self.tty:
558 + return # odświeży wątek animacji
559 + total = s["total"]
560 + pct = downloaded / total * 100.0 if total > 0 else 0.0
561 + step = int(pct // 25) * 25
562 + if step > s["milestone"]:
563 + s["milestone"] = step
564 + if total > 0:
565 + detail = f"{_fmt_size(downloaded)}/{_fmt_size(total)}"
566 + else:
567 + detail = _fmt_size(downloaded)
568 + self._emit(f" ↓ {s['name']}: {pct:.0f}% ({detail})\n")
569 +
570 + def finish(self, sid: int, ok: bool = True):
571 + with self._lock:
572 + s = self._slots.pop(sid, None)
573 + if s is None:
574 + return
575 + self.completed += 1
576 + line = self._done_line(s, ok)
577 + if self.tty:
578 + self._clear_panel()
579 + self._emit(line + "\n")
580 + self._render_locked()
581 + else:
582 + self._emit(line + "\n")
583 +
584 + def log(self, text: str):
585 + """Wypisz komunikat (np. ponowienie pobierania) bez psucia panelu."""
586 + with self._lock:
587 + if self.tty:
588 + self._clear_panel()
589 + self._emit(text + "\n")
590 + self._render_locked()
591 + else:
592 + self._emit(text + "\n")
593 +
594 + def _done_line(self, s: dict, ok: bool) -> str:
595 + if not ok:
596 + return f" ❌ {s['name']}: {_('download_fail')}"
597 + total = int(s.get("total") or 0)
598 + size = _fmt_size(total if total > 0 else s.get("downloaded", 0))
599 + elapsed = _fmt_eta(time.time() - s["start"])
600 + return _fit_widget_line(f" ✅ {s['name']} ({size}, {elapsed})",
601 + self.stream)
602 +
603 + def close(self):
604 + self._stop.set()
605 + if self._thread is not None:
606 + self._thread.join(timeout=0.3)
607 + self._thread = None
608 + with self._lock:
609 + if self.tty:
610 + self._clear_panel()
611 + if self._cursor_hidden:
612 + self._emit("\x1b[?25h") # przywróć kursor
613 + self._cursor_hidden = False
395 614
396 615
397 616 class _StepBar(_Bar):
@@ -606,6 +825,18 @@ T = {
606 825 "pkg_not_found": "Package not found: {} (not in any repo)",
607 826 "not_found_hint": "Check the spelling or run 'pag search <query>'.",
608 827 "downloading": "Downloading",
828 + "done": "done",
829 + "wroom_terminal": "PAG WROOM needs an interactive terminal – run: pag wroom",
830 + "wroom_too_small": "Enlarge the terminal (min. {arg1}x{arg2})",
831 + "wroom_tagline": "PAGAN RACING 4.2.0 · 38911 BYTES FREE",
832 + "wroom_controls": "←/→ lane ↑/↓ gas/brake P pause Q quit",
833 + "wroom_press": "PRESS SPACE TO RACE",
834 + "wroom_over": "RACE OVER",
835 + "wroom_score": "Score: {arg1}",
836 + "wroom_best": "Best: {arg1}",
837 + "wroom_restart": "R / SPACE – race again Q – quit",
838 + "wroom_paused": "PAUSED",
839 + "wroom_hud": "SCORE {arg1:06d} SPEED {arg2:3d} km/h LIVES {arg3}",
609 840 "download_fail": "download failed",
610 841 "gpg_fail": "GPG verification failed",
611 842 "sha256_mismatch": "SHA256 mismatch",
@@ -756,6 +987,18 @@ T = {
756 987 "pkg_not_found": "Nie znaleziono pakietu: {} (brak w repozytoriach)",
757 988 "not_found_hint": "Sprawdź pisownię lub uruchom 'pag search <fraza>'.",
758 989 "downloading": "Pobieranie",
990 + "done": "gotowe",
991 + "wroom_terminal": "PAG WROOM wymaga terminala – uruchom: pag wroom",
992 + "wroom_too_small": "Powiększ terminal (min. {arg1}x{arg2})",
993 + "wroom_tagline": "PAGAN RACING 4.2.0 · 38911 BAJTÓW WOLNE",
994 + "wroom_controls": "←/→ pas ↑/↓ gaz/hamulec P pauza Q wyjście",
995 + "wroom_press": "NACIŚNIJ SPACJĘ, ABY RUSZYĆ",
996 + "wroom_over": "KONIEC WYŚCIGU",
997 + "wroom_score": "Wynik: {arg1}",
998 + "wroom_best": "Rekord: {arg1}",
999 + "wroom_restart": "R / SPACJA – jeszcze raz Q – wyjście",
1000 + "wroom_paused": "PAUZA",
1001 + "wroom_hud": "WYNIK {arg1:06d} PRĘDKOŚĆ {arg2:3d} km/h ŻYCIA {arg3}",
759 1002 "download_fail": "błąd pobierania",
760 1003 "gpg_fail": "błąd weryfikacji GPG",
761 1004 "sha256_mismatch": "niezgodność SHA256",
@@ -7339,9 +7582,22 @@ def _verify_so_deps(to_install: list, repo: dict, installed: dict) -> int:
7339 7582 print()
7340 7583 return len(missing)
7341 7584
7342 -def _download_pkg(pkg, attempts: int = 3, progress: bool = True):
7343 - """Pobiera pakiet do cache. `progress=False` wycisza pasek (np. gdy
7344 - równoległy pobierający pokazuje własny pasek zbiorczy)."""
7585 +def _download_pkg(pkg, attempts: int = 3, progress: bool = True,
7586 + on_progress=None, on_log=None):
7587 + """Pobiera pakiet do cache.
7588 +
7589 + `progress=False` wycisza pojedynczy pasek (np. gdy równoległy pobierający
7590 + pokazuje własny panel zbiorczy). `on_progress(downloaded, total)` pozwala
7591 + takiemu panelowi śledzić postęp bez wypisywania własnych linii, a
7592 + `on_log(text)` przekierowuje komunikaty (ponowienia, błędy) do panelu,
7593 + żeby nie rozbijały jego wielolinijkowego układu.
7594 + """
7595 + def _log(msg: str) -> None:
7596 + if on_log is not None:
7597 + on_log(msg)
7598 + else:
7599 + print(msg, file=sys.stderr)
7600 +
7345 7601 url = f"{pkg.repo_url}/{pkg.filename}"
7346 7602 dest = os.path.join(PAG_CACHE, pkg.filename)
7347 7603 if os.path.exists(dest) and (not pkg.sha256 or _sha256_file(dest) == pkg.sha256):
@@ -7354,16 +7610,22 @@ def _download_pkg(pkg, attempts: int = 3, progress: bool = True):
7354 7610 with urlopen(req, timeout=600) as resp:
7355 7611 total = int(resp.headers.get("Content-Length", 0))
7356 7612 bar = DownloadBar(pkg.filename, total) if progress else None
7357 - with open(dest, "wb") as f:
7358 - while True:
7359 - chunk = resp.read(65536)
7360 - if not chunk:
7361 - break
7362 - f.write(chunk)
7363 - if bar is not None:
7364 - bar.update(len(chunk))
7365 - if bar is not None:
7366 - bar.close()
7613 + done = 0
7614 + try:
7615 + with open(dest, "wb") as f:
7616 + while True:
7617 + chunk = resp.read(65536)
7618 + if not chunk:
7619 + break
7620 + f.write(chunk)
7621 + done += len(chunk)
7622 + if bar is not None:
7623 + bar.update(len(chunk))
7624 + if on_progress is not None:
7625 + on_progress(done, total)
7626 + finally:
7627 + if bar is not None:
7628 + bar.close()
7367 7629 if pkg.sha256 and _sha256_file(dest) != pkg.sha256:
7368 7630 last_err = _("sha256_mismatch")
7369 7631 try:
@@ -7371,7 +7633,7 @@ def _download_pkg(pkg, attempts: int = 3, progress: bool = True):
7371 7633 except OSError:
7372 7634 pass
7373 7635 if attempt < attempts:
7374 - print(_(' ↻ Retrying download of {arg1} ({arg2}/{arg3})...', arg1=(pkg.filename), arg2=(attempt), arg3=(attempts - 1)), file=sys.stderr)
7636 + _log(_(' ↻ Retrying download of {arg1} ({arg2}/{arg3})...', arg1=(pkg.filename), arg2=(attempt), arg3=(attempts - 1)))
7375 7637 time.sleep(attempt)
7376 7638 continue
7377 7639 return None
@@ -7387,10 +7649,10 @@ def _download_pkg(pkg, attempts: int = 3, progress: bool = True):
7387 7649 except OSError:
7388 7650 pass
7389 7651 if attempt < attempts:
7390 - print(_(' ↻ Retrying download of {arg1} ({arg2}/{arg3})...', arg1=(pkg.filename), arg2=(attempt), arg3=(attempts - 1)), file=sys.stderr)
7652 + _log(_(' ↻ Retrying download of {arg1} ({arg2}/{arg3})...', arg1=(pkg.filename), arg2=(attempt), arg3=(attempts - 1)))
7391 7653 time.sleep(attempt)
7392 7654 continue
7393 - print(_(' ⚠ Download error {arg1}: {arg2}', arg1=(pkg.filename), arg2=(last_err)), file=sys.stderr)
7655 + _log(_(' ⚠ Download error {arg1}: {arg2}', arg1=(pkg.filename), arg2=(last_err)))
7394 7656 return None
7395 7657
7396 7658 def _download_pkg_sig(pkg, dest):
@@ -7437,25 +7699,37 @@ def _download_packages_parallel(pkgs: List[PackageInfo], max_workers: int = 4) -
7437 7699 """
7438 7700 Równoległe pobieranie wielu pakietów przez ThreadPoolExecutor.
7439 7701 Znacząco przyspiesza przy dużych aktualizacjach (50+ pakietów).
7702 +
7703 + Każdy aktywny wątek ma własną linię w panelu: procent, nazwa pakietu,
7704 + pobrane/rozmiar i ETA (patrz `_ParallelDownloadDisplay`).
7440 7705 Zwraca słownik {nazwa_pakietu: ścieżka_lub_None}.
7441 7706 """
7442 7707 results = {}
7443 - total = len(pkgs)
7444 - completed = 0
7445 - with ThreadPoolExecutor(max_workers=max_workers) as executor:
7446 - future_to_pkg = {executor.submit(_download_pkg, pkg, progress=False): pkg for pkg in pkgs}
7447 - for future in as_completed(future_to_pkg):
7448 - pkg = future_to_pkg[future]
7449 - try:
7450 - results[pkg.name] = future.result()
7451 - except Exception:
7452 - results[pkg.name] = None
7453 - completed += 1
7454 - # Pasek postępu (animowany „drakkar” na TTY)
7455 - pct = completed / total * 100
7456 - bar = _pagan_bar(pct, 20, time.time(), animated=sys.stderr.isatty())
7457 - print(f"\r ⏬ [{bar}] {completed}/{total} ({pct:.0f}%)", end="", file=sys.stderr, flush=True)
7458 - print(file=sys.stderr) # nowa linia po zakończeniu
7708 + display = _ParallelDownloadDisplay(len(pkgs))
7709 +
7710 + def _worker(pkg: PackageInfo):
7711 + sid = display.start(pkg.name, getattr(pkg, "size_bytes", 0) or 0)
7712 + path = None
7713 + try:
7714 + path = _download_pkg(
7715 + pkg, progress=False,
7716 + on_progress=lambda done, total: display.progress(sid, done, total),
7717 + on_log=display.log)
7718 + return path
7719 + finally:
7720 + display.finish(sid, ok=bool(path))
7721 +
7722 + try:
7723 + with ThreadPoolExecutor(max_workers=max_workers) as executor:
7724 + future_to_pkg = {executor.submit(_worker, pkg): pkg for pkg in pkgs}
7725 + for future in as_completed(future_to_pkg):
7726 + pkg = future_to_pkg[future]
7727 + try:
7728 + results[pkg.name] = future.result()
7729 + except Exception:
7730 + results[pkg.name] = None
7731 + finally:
7732 + display.close()
7459 7733 return results
7460 7734
7461 7735 def load_world():
@@ -7705,6 +7979,418 @@ def _get_usage():
7705 7979 return USAGE_EN
7706 7980
7707 7981
7982 +# =============================================================================
7983 +# EASTER EGG: PAG WROOM – wyścigi ASCII w stylu Commodore
7984 +# -----------------------------------------------------------------------------
7985 +
7986 +def cmd_wroom():
7987 + """Ukryta gra: `pag wroom`.
7988 +
7989 + Animowany top-down wyścig w ASCII: trzy pasy, ruszający się tor, przeciwnicy,
7990 + punkty, ETA niepotrzebne – liczy się rekord. Sterowanie strzałkami (lub
7991 + WSAD), P pauza, Q wyjście. Gra działa tylko na terminalu; poza TTY wypisuje
7992 + krótką podpowiedź, a po wyjściu przywraca ekran i ustawienia terminala.
7993 + """
7994 + if not (sys.stdin.isatty() and sys.stdout.isatty()):
7995 + print(_('wroom_terminal'))
7996 + return 1
7997 + if os.environ.get("TERM", "") == "dumb":
7998 + print(_('wroom_terminal'))
7999 + return 1
8000 + try:
8001 + import random
8002 + import select
8003 + import termios
8004 + import tty
8005 + except ImportError:
8006 + print(_('wroom_terminal'))
8007 + return 1
8008 +
8009 + ANSI_RE = re.compile(r"\x1b\[[0-9;?]*[A-Za-z]")
8010 +
8011 + def _vlen(text):
8012 + return len(ANSI_RE.sub("", text))
8013 +
8014 + def _vcut(text, width):
8015 + """Przytnij linię do `width` WIDOCZNYCH kolumn (nie licząc ANSI)."""
8016 + if _vlen(text) <= width:
8017 + return text
8018 + out, vis, i = [], 0, 0
8019 + while i < len(text) and vis < width:
8020 + m = ANSI_RE.match(text, i)
8021 + if m:
8022 + out.append(m.group(0))
8023 + i = m.end()
8024 + continue
8025 + out.append(text[i])
8026 + vis += 1
8027 + i += 1
8028 + return "".join(out)
8029 +
8030 + def _center(text, width):
8031 + v = _vlen(text)
8032 + if v >= width:
8033 + return _vcut(text, width)
8034 + pad = width - v
8035 + return " " * (pad // 2) + text + " " * (pad - pad // 2)
8036 +
8037 + # --- geometria toru i sprite'y (każdy znak = 1 kolumna) -------------------
8038 + SPR_ROOF = " ▄█▄ "
8039 + SPR_BODY = "▐███▌"
8040 + LANE_W = 8
8041 + N_LANES = 3
8042 + ROAD_W = LANE_W * N_LANES + 2
8043 + MIN_W, MIN_H = 56, 16
8044 +
8045 + GLYPHS = {
8046 + "P": ("████ ", "█ █", "████ ", "█ ", "█ "),
8047 + "A": (" ███ ", "█ █", "█████", "█ █", "█ █"),
8048 + "G": (" ████", "█ ", "█ ██", "█ █", " ████"),
8049 + "W": ("█ █", "█ █", "█ █ █", "██ ██", "█ █"),
8050 + "R": ("████ ", "█ █", "████ ", "█ █ ", "█ █ "),
8051 + "O": (" ███ ", "█ █", "█ █", "█ █", " ███ "),
8052 + "M": ("█ █", "██ ██", "█ █ █", "█ █", "█ █"),
8053 + }
8054 +
8055 + def _logo():
8056 + rows = []
8057 + for r in range(5):
8058 + line = ""
8059 + for ch in "PAG WROOM":
8060 + if ch == " ":
8061 + line += " "
8062 + else:
8063 + line += GLYPHS[ch][r] + " "
8064 + rows.append(line.rstrip())
8065 + return rows
8066 +
8067 + LOGO = _logo()
8068 +
8069 + state = {
8070 + "phase": "title", "best": 0, "paused": False,
8071 + "lane": 1, "x": 1.0, "speed": 90.0, "boost": 0.0,
8072 + "distance": 0.0, "lives": 3, "opponents": [],
8073 + "spawn": 0.8, "invuln": 1.0, "flash": 0.0,
8074 + "scroll": 0.0, "time": 0.0, "road_h": 12,
8075 + }
8076 +
8077 + def _new_game():
8078 + state.update(phase="play", paused=False, lane=1, x=1.0,
8079 + speed=90.0, boost=0.0, distance=0.0, lives=3,
8080 + opponents=[], spawn=0.8, invuln=1.0, flash=0.0,
8081 + scroll=0.0, time=0.0)
8082 +
8083 + # --- wejście (bez blokowania) --------------------------------------------
8084 + ARROWS = {"\x1b[D": "LEFT", "\x1b[C": "RIGHT",
8085 + "\x1b[A": "UP", "\x1b[B": "DOWN",
8086 + "\x1bOD": "LEFT", "\x1bOC": "RIGHT",
8087 + "\x1bOA": "UP", "\x1bOB": "DOWN"}
8088 + fd = sys.stdin.fileno()
8089 + pending = ""
8090 +
8091 + def _keys():
8092 + nonlocal pending
8093 + keys = []
8094 + try:
8095 + ready, _, _ = select.select([fd], [], [], 0)
8096 + if not ready:
8097 + return keys
8098 + data = pending + os.read(fd, 64).decode("utf-8", "ignore")
8099 + pending = ""
8100 + except (OSError, UnicodeDecodeError):
8101 + return keys
8102 + i = 0
8103 + while i < len(data):
8104 + if data[i] == "\x1b":
8105 + # Niekompletna sekwencja strzałki – dokończymy w następnej
8106 + # klatce. Sam ESC (bez reszty) nie wychodzi z gry: wyjściem
8107 + # jest Q, więc przypadkowy Alt/strzałka nie zabija wyścigu.
8108 + if i + 1 >= len(data):
8109 + pending = data[i:]
8110 + break
8111 + if data[i + 1] not in "[O":
8112 + i += 1
8113 + continue
8114 + if i + 2 >= len(data):
8115 + pending = data[i:]
8116 + break
8117 + seq = data[i:i + 3]
8118 + key = ARROWS.get(seq)
8119 + if key:
8120 + keys.append(key)
8121 + i += 3
8122 + continue
8123 + ch = data[i]
8124 + i += 1
8125 + if ch in "qQ":
8126 + keys.append("QUIT")
8127 + elif ch in "aA":
8128 + keys.append("LEFT")
8129 + elif ch in "dD":
8130 + keys.append("RIGHT")
8131 + elif ch in "wW":
8132 + keys.append("UP")
8133 + elif ch in "sS":
8134 + keys.append("DOWN")
8135 + elif ch in "pP":
8136 + keys.append("PAUSE")
8137 + elif ch in " \r\n rR":
8138 + keys.append("START")
8139 + return keys
8140 +
8141 + # --- rysowanie toru -------------------------------------------------------
8142 + def _paint(row, start, text, color):
8143 + cells, cols = row
8144 + for i, ch in enumerate(text):
8145 + pos = start + i
8146 + if 0 <= pos < len(cells) and ch != " ":
8147 + cells[pos] = ch
8148 + cols[pos] = color
8149 +
8150 + def _render_cells(row):
8151 + cells, cols = row
8152 + parts, i = [], 0
8153 + while i < len(cells):
8154 + j = i
8155 + while j + 1 < len(cells) and cols[j + 1] == cols[i]:
8156 + j += 1
8157 + seg = "".join(cells[i:j + 1])
8158 + parts.append(_c(cols[i], seg) if cols[i] else seg)
8159 + i = j + 1
8160 + return "".join(parts)
8161 +
8162 + def _road_row(r, phase):
8163 + cells = [" "] * ROAD_W
8164 + cols = [None] * ROAD_W
8165 + cells[0] = "║"
8166 + cols[0] = "yellow"
8167 + cells[-1] = "║"
8168 + cols[-1] = "yellow"
8169 + for sep in (LANE_W, LANE_W * 2):
8170 + if (r + phase) % 4 < 2:
8171 + cells[1 + sep] = "│"
8172 + cols[1 + sep] = "dim"
8173 + return cells, cols
8174 +
8175 + def _lane_start(pos, width):
8176 + return int(round(1 + pos * LANE_W + (LANE_W - width) / 2))
8177 +
8178 + def _play_lines(W, H):
8179 + road_h = max(6, H - 4)
8180 + rows = [_center(_c("cyan", "PAG WROOM"), W)]
8181 + hud = _('wroom_hud', arg1=(int(state["distance"])),
8182 + arg2=(int(state["speed"])), arg3=(state["lives"]))
8183 + rows.append(_center(hud, W))
8184 +
8185 + board = [_road_row(r, int(state["scroll"])) for r in range(road_h)]
8186 + for o in state["opponents"]:
8187 + base = int(round(o["y"]))
8188 + for dy, spr in ((0, SPR_ROOF), (1, SPR_BODY)):
8189 + rr = base + dy
8190 + if 0 <= rr < road_h:
8191 + _paint(board[rr], _lane_start(o["lane"], len(spr)),
8192 + spr, o["color"])
8193 +
8194 + if not (state["invuln"] > 0 and int(state["time"] * 10) % 2):
8195 + for dy, spr in ((0, SPR_ROOF), (1, SPR_BODY)):
8196 + rr = road_h - 2 + dy
8197 + _paint(board[rr], _lane_start(state["x"], len(spr)),
8198 + spr, "cyan")
8199 +
8200 + if state["flash"] > 0:
8201 + _paint(board[road_h - 2], ROAD_W // 2 - 2, "BUM!", "red")
8202 +
8203 + left = max(0, (W - ROAD_W) // 2)
8204 + right = max(0, W - ROAD_W - left)
8205 + for r in range(road_h):
8206 + rows.append(" " * left + _render_cells(board[r]) + " " * right)
8207 +
8208 + rows.append("")
8209 + rows.append(_center(_c("dim", _('wroom_controls')), W))
8210 + if state["paused"]:
8211 + rows[H // 2] = _center(_c("yellow", _('wroom_paused')), W)
8212 + return rows[:H]
8213 +
8214 + def _menu_lines(W, H, blink):
8215 + block = []
8216 + if W >= len(LOGO[0]) + 2:
8217 + block.extend(_c("cyan", ln) for ln in LOGO)
8218 + else:
8219 + block.append(_c("cyan", "P A G W R O O M"))
8220 + block.append("")
8221 + block.append(_c("dim", _('wroom_tagline')))
8222 + if H >= 18:
8223 + block.append("")
8224 + block.append(" " + _c("cyan", "▄███▄") + " " +
8225 + _c("red", "▄███▄") + " " +
8226 + _c("yellow", "▄███▄"))
8227 + if H >= 22:
8228 + block.extend(["", _c("dim", 'LOAD "WROOM",8,1'),
8229 + _c("dim", "READY."), _c("dim", "RUN")])
8230 + block.append("")
8231 + if state["phase"] == "over":
8232 + block.append(_c("red", _('wroom_over')))
8233 + block.append("")
8234 + block.append(_('wroom_score', arg1=(int(state["distance"]))))
8235 + block.append(_('wroom_best', arg1=(state["best"])))
8236 + block.append("")
8237 + block.append(_('wroom_restart'))
8238 + else:
8239 + block.append(_('wroom_controls'))
8240 + block.append("")
8241 + block.append(_c("yellow", _('wroom_press')) if blink else "")
8242 +
8243 + top = max(0, (H - len(block)) // 2)
8244 + rows = [""] * H
8245 + for i, line in enumerate(block):
8246 + if top + i < H:
8247 + rows[top + i] = _center(line, W)
8248 + return rows
8249 +
8250 + # --- fizyka i kolizje -----------------------------------------------------
8251 + def _spawn():
8252 + free = [lane for lane in range(N_LANES)
8253 + if not any(o["lane"] == lane and o["y"] < 4
8254 + for o in state["opponents"])]
8255 + if not free:
8256 + return
8257 + state["opponents"].append({
8258 + "lane": random.choice(free),
8259 + "y": -2.0,
8260 + "speed": state["speed"] * random.uniform(0.45, 0.78),
8261 + "color": random.choice(("red", "yellow", "green")),
8262 + })
8263 +
8264 + def _update(dt):
8265 + state["time"] += dt
8266 + if state["phase"] != "play" or state["paused"]:
8267 + return
8268 +
8269 + state["boost"] *= max(0.0, 1.0 - dt * 3.0)
8270 + base = 90.0 + min(120.0, state["distance"] * 0.02)
8271 + target = max(45.0, base + state["boost"])
8272 + state["speed"] += (target - state["speed"]) * min(1.0, dt * 2.0)
8273 + state["distance"] += state["speed"] * dt * 0.45
8274 + state["scroll"] += state["speed"] * dt * 0.09
8275 + state["x"] += (state["lane"] - state["x"]) * min(1.0, dt * 9.0)
8276 + if state["invuln"] > 0:
8277 + state["invuln"] = max(0.0, state["invuln"] - dt)
8278 + if state["flash"] > 0:
8279 + state["flash"] = max(0.0, state["flash"] - dt)
8280 +
8281 + state["spawn"] -= dt
8282 + if state["spawn"] <= 0:
8283 + _spawn()
8284 + state["spawn"] = max(0.45, 1.35 - state["speed"] / 320.0)
8285 +
8286 + for o in list(state["opponents"]):
8287 + o["y"] += (state["speed"] - o["speed"]) * dt * 0.06
8288 + if o["y"] > state["road_h"] + 2 or o["y"] < -4:
8289 + state["opponents"].remove(o)
8290 +
8291 + if state["invuln"] > 0:
8292 + return
8293 + player_cy = state["road_h"] - 1.0
8294 + for o in list(state["opponents"]):
8295 + if (abs((o["y"] + 1.0) - player_cy) < 1.25
8296 + and abs(o["lane"] - state["x"]) < 0.55):
8297 + state["lives"] -= 1
8298 + state["flash"] = 0.6
8299 + state["invuln"] = 1.8
8300 + state["speed"] = max(45.0, state["speed"] * 0.5)
8301 + state["boost"] = 0.0
8302 + state["opponents"].remove(o)
8303 + state["opponents"] = [x for x in state["opponents"]
8304 + if x["y"] < state["road_h"] - 5]
8305 + try:
8306 + out.write("\a")
8307 + out.flush()
8308 + except OSError:
8309 + pass
8310 + if state["lives"] <= 0:
8311 + state["phase"] = "over"
8312 + state["best"] = max(state["best"],
8313 + int(state["distance"]))
8314 + break
8315 +
8316 + # --- pętla gry ------------------------------------------------------------
8317 + old_attrs = termios.tcgetattr(fd)
8318 + out = sys.stdout
8319 + try:
8320 + tty.setcbreak(fd)
8321 + out.write("\x1b[?1049h\x1b[?25l\x1b[2J")
8322 + out.flush()
8323 + running = True
8324 + last = time.monotonic()
8325 + last_size = None
8326 + while running:
8327 + for key in _keys():
8328 + if key == "QUIT":
8329 + running = False
8330 + break
8331 + if state["phase"] in ("title", "over"):
8332 + if key == "START":
8333 + _new_game()
8334 + elif key == "PAUSE":
8335 + state["paused"] = not state["paused"]
8336 + elif state["paused"]:
8337 + continue
8338 + elif key == "LEFT":
8339 + state["lane"] = max(0, state["lane"] - 1)
8340 + elif key == "RIGHT":
8341 + state["lane"] = min(N_LANES - 1, state["lane"] + 1)
8342 + elif key == "UP":
8343 + state["boost"] = min(55.0, state["boost"] + 14.0)
8344 + elif key == "DOWN":
8345 + state["boost"] = max(-45.0, state["boost"] - 14.0)
8346 + if not running:
8347 + break
8348 +
8349 + size = shutil.get_terminal_size((80, 24))
8350 + W, H = size.columns, size.lines
8351 + if last_size != (W, H):
8352 + last_size = (W, H)
8353 + out.write("\x1b[2J")
8354 + state["road_h"] = max(6, H - 4)
8355 +
8356 + now = time.monotonic()
8357 + dt = min(0.1, max(0.0, now - last))
8358 + last = now
8359 + if W >= MIN_W and H >= MIN_H:
8360 + _update(dt)
8361 +
8362 + if W < MIN_W or H < MIN_H:
8363 + lines = [""] * H
8364 + msg = _('wroom_too_small', arg1=(MIN_W), arg2=(MIN_H))
8365 + lines[H // 2] = _center(_c("yellow", msg), W)
8366 + elif state["phase"] == "play":
8367 + lines = _play_lines(W, H)
8368 + else:
8369 + blink = int(time.monotonic() * 2) % 2 == 0
8370 + lines = _menu_lines(W, H, blink)
8371 +
8372 + buf = ["\x1b[H"]
8373 + for i, line in enumerate(lines):
8374 + buf.append(_vcut(line, W))
8375 + buf.append("\x1b[K")
8376 + if i != len(lines) - 1:
8377 + buf.append("\n")
8378 + out.write("".join(buf))
8379 + out.flush()
8380 +
8381 + spent = time.monotonic() - now
8382 + if spent < 1.0 / 20.0:
8383 + time.sleep(1.0 / 20.0 - spent)
8384 + finally:
8385 + try:
8386 + out.write("\x1b[0m\x1b[?25h\x1b[?1049l")
8387 + out.flush()
8388 + except OSError:
8389 + pass
8390 + termios.tcsetattr(fd, termios.TCSADRAIN, old_attrs)
8391 + return 0
8392 +
8393 +
7708 8394 def _extract_lang(outdir: str) -> int:
7709 8395 """Eksport wbudowanych tłumaczeń do outdir/{pl,en}.json (+ klucz "usage").
7710 8396
@@ -7773,6 +8459,7 @@ def main():
7773 8459 "snapshots": cmd_snapshot_list,
7774 8460 "snapshot-grub": cmd_snapshot_grub,
7775 8461 "sbom": lambda: cmd_sbom(args),
8462 + "wroom": cmd_wroom, # easter egg – działa bez roota
7776 8463 }
7777 8464
7778 8465 if cmd in READ_ONLY:
@@ -7801,6 +8488,7 @@ def main():
7801 8488 # zasugeruj poprawną komendę ZAMIAST wpadać w smart search (który
7802 8489 # potrafi wisieć na `flatpak search` aż do Ctrl-C).
7803 8490 _known = set(READ_ONLY) | set(WRITE_CMDS)
8491 + _known.discard("wroom") # easter egg – nie podpowiadaj go w literówkach
7804 8492 _close = difflib.get_close_matches(cmd, _known, n=1, cutoff=0.75)
7805 8493 if _close:
7806 8494 print(_("❌ Unknown command: '{arg1}'. Did you mean '{arg2}'?", arg1=(cmd), arg2=(_close[0])))