dfk1352/LibreOffice-skills / skills/libreoffice-writer
libreoffice-writer
VerifiedUse when creating, editing, formatting, exporting, or extracting LibreOffice Writer (.odt) documents via UNO, including session-based edits, structured text targets, tables, images, lists, patch workflows, and snapshots.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 9.3 KB |
| references/troubleshooting.md | markdown | 3.9 KB |
| scripts/colors.py | script | 4.6 KB |
| scripts/constants.py | script | 180 B |
| scripts/exceptions.py | script | 748 B |
| scripts/patch_base.py | script | 12.1 KB |
| scripts/session.py | script | 2.6 KB |
| scripts/uno_bridge.py | script | 9.1 KB |
| scripts/writer/__init__.py | script | 554 B |
| scripts/writer/core.py | script | 3.4 KB |
| scripts/writer/exceptions.py | script | 2.5 KB |
| scripts/writer/patch.py | script | 9.4 KB |
| scripts/writer/session.py | script | 18.8 KB |
| scripts/writer/snapshot.py | script | 5.6 KB |
| scripts/writer/targets.py | script | 14.7 KB |
scripts/session.py
View on GitHub"""Shared session primitives for LibreOffice skills."""
from abc import ABC, abstractmethod
from pathlib import Path
from typing import Any, Literal, Self
from exceptions import SessionClosedError
class BaseSession(ABC):
"""Minimal shared protocol for long-lived skill sessions."""
def __init__(
self,
closed_error_type: type[Exception] = SessionClosedError,
) -> None:
self._closed = False
self._closed_error_type: type[Exception] = closed_error_type
self._uno_manager: Any = None
self._desktop: Any = None
self._doc: Any = None
self._path: Path | None = None
def __enter__(self) -> Self:
return self
def __exit__(self, exc_type, exc_val, exc_tb) -> Literal[False]:
self.close(save=(exc_type is None))
return False
def close(self, save: bool = True) -> None:
"""Persist changes if requested, then release session resources."""
if self._closed:
return
try:
if save:
self._doc.store()
self._doc.close(True)
finally:
try:
self._uno_manager.__exit__(None, None, None)
finally:
self._closed = True
self._doc = None
self._desktop = None
self._uno_manager = None
def reset(self) -> None:
"""Discard in-memory changes and reopen the backing document."""
self._require_open()
self._doc.close(True)
self._uno_manager.__exit__(None, None, None)
self._doc = None
self._desktop = None
self._uno_manager = None
try:
self._open_document()
self._closed = False
except Exception:
self._closed = True
raise
def restore_snapshot(self, snapshot: bytes) -> None:
"""Close the document, overwrite the file, and reopen."""
self._require_open()
self._doc.close(True)
self._uno_manager.__exit__(None, None, None)
self._doc = None
self._desktop = None
self._uno_manager = None
assert self._path is not None
self._path.write_bytes(snapshot)
try:
self._open_document()
self._closed = False
except Exception:
self._closed = True
raise
@abstractmethod
def _open_document(self) -> None:
"""Open the backing document and populate session state."""
def _require_open(self) -> None:
if self._closed:
raise self._closed_error_type("Session is already closed")
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |