Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/workflows/catalogs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Skin catalogs

# Rebuilds the Enigma2 skin catalogs from the public enigma2 sources
# and publishes them to the "catalogs" branch.
on:
schedule:
- cron: "17 3 * * *"
workflow_dispatch:
pull_request:
paths:
- "catalogs/**"
- ".github/workflows/catalogs.yml"

permissions:
contents: write

concurrency:
group: skin-catalogs-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: "3.13"

- name: Build catalogs
id: build
run: |
if ! python catalogs/build_catalogs.py --out out; then
echo "partial=true" >> "$GITHUB_OUTPUT"
fi
test -s out/index.json

- name: Upload catalogs as artifact
uses: actions/upload-artifact@v4
with:
name: skin-catalogs
path: out/
retention-days: 14

# Publishing only happens from main (nightly run or manual run), never from a pull request.
- name: Publish to the catalogs branch
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
run: |
cd out
git init -q -b catalogs
git add .
git -c user.name="github-actions[bot]" \
-c user.email="41898282+github-actions[bot]@users.noreply.github.com" \
commit -q -m "Skin catalogs $(date -u +%F)"
git push -f "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" catalogs

- name: Report images that failed
if: steps.build.outputs.partial == 'true'
run: |
echo "::warning::Some images could not be built; the others were published. See the Build catalogs step."
exit 1
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ Source/e2skinner2/bin/
Source/e2skinner2/obj/
*.suo
/Source/.vs

# Skin catalog builder (local runs)
catalogs/cache/
catalogs/out/
__pycache__/
63 changes: 63 additions & 0 deletions catalogs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Enigma2 skin catalogs

Machine-readable catalogs that tell OpenSkin Designer what each Enigma2 image supports:
skin attributes and their accepted values, XML tags, renderers, converters (with their
arguments), screens with the widgets they expect, skin parameters, fonts and colors.

They are generated from the public enigma2 source repositories, so they stay current
without manual work.

## Where the catalogs are published

A GitHub Action (`.github/workflows/catalogs.yml`) rebuilds them every night and on demand,
and publishes them to the **`catalogs`** branch of this repository:

```
https://raw.githubusercontent.com/OwnerPlugins/OpenSkin-Designer/catalogs/index.json
https://raw.githubusercontent.com/OwnerPlugins/OpenSkin-Designer/catalogs/<image>.json
```

| File | Content |
| --- | --- |
| `index.json` | The images available, with branch and file name |
| `<image>.json` | The catalog of one image (used by OpenSkin Designer) |
| `<image>.md` | The same catalog in readable form |
| `compare.md` / `compare.json` | What differs between the images |

## Images

The list lives in `images.json`. Each entry has an `id`, a display `name`, the git `repo`
URL, the `branch` and the plugin repositories scanned with it.

- **Add** an image: copy an entry and change `id`, `name`, `repo` and `branch`.
- **Change** an image: edit its `repo` or `branch`.
- **Remove** an image: set `"enabled": false`, or delete the entry.
- **Plugins**: list them under `plugins`; an empty `branch` means the default branch.

## Running it locally

Needs git and Python 3.10 or newer (3.12+ recommended). Nothing is written to GitHub.

```
python catalogs/build_catalogs.py # all enabled images
python catalogs/build_catalogs.py --only openatv # one image
```

Sources are cached in `catalogs/cache`, results go to `catalogs/out` (both git-ignored).

## Scripts

| Script | Purpose |
| --- | --- |
| `build_catalogs.py` | Downloads the sources listed in `images.json` and builds every catalog |
| `e2catalog.py` | Builds the catalog of one enigma2 source tree |
| `e2compare.py` | Compares several catalogs |

## Limits

The catalogs come from static analysis of the Python code:

- skin names computed at runtime and widgets created in loops are not seen;
- `Setup` screens take their layout from `setup.xml`, which is not read yet;
- converter arguments and renderer attributes are best-effort: roughly one converter in
three reads its arguments in a way the script does not recognize.
94 changes: 94 additions & 0 deletions catalogs/build_catalogs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/usr/bin/env python3
"""build_catalogs.py - build the skin catalogs from images.json.

Usage: python build_catalogs.py [--images images.json] [--cache cache] [--out out] [--only openatv openpli]

For every enabled image: download (or update) its enigma2 repository and plugin
repositories into the cache folder, then write out/<id>.json and out/<id>.md,
and finally out/compare.* and out/index.json.
Needs only git and Python 3.10 or newer. Writes nothing to GitHub.
"""
import argparse, json, os, subprocess, sys

HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, HERE)
import e2catalog # noqa: E402

SPARSE = ["lib/python", "lib/gui", "data"]


def git(args, cwd=None):
r = subprocess.run(["git"] + args, cwd=cwd, capture_output=True, text=True)
if r.returncode != 0:
raise RuntimeError(f"git {' '.join(args)}: {r.stderr.strip()}")
return r.stdout.strip()


def fetch(repo, branch, dest, sparse):
"""Shallow clone, or update an existing one. Only the folders the catalog needs."""
if os.path.isdir(os.path.join(dest, ".git")):
ref = branch or "HEAD"
git(["fetch", "--depth", "1", "--filter=blob:none", "origin", ref], cwd=dest)
git(["checkout", "-q", "--force", "FETCH_HEAD"], cwd=dest)
else:
args = ["clone", "-q", "--depth", "1", "--filter=blob:none"]
if sparse:
args.append("--sparse")
if branch:
args += ["-b", branch]
git(args + [repo, dest])
if sparse:
git(["sparse-checkout", "set"] + SPARSE, cwd=dest)
return git(["log", "-1", "--format=%ad", "--date=short"], cwd=dest)


def main():
ap = argparse.ArgumentParser()
ap.add_argument("--images", default=os.path.join(HERE, "images.json"))
ap.add_argument("--cache", default=os.path.join(HERE, "cache"))
ap.add_argument("--out", default=os.path.join(HERE, "out"))
ap.add_argument("--only", nargs="*", help="only these image ids")
a = ap.parse_args()

cfg = json.load(open(a.images, encoding="utf-8"))
os.makedirs(a.cache, exist_ok=True)
os.makedirs(a.out, exist_ok=True)
done, failed = [], []
for img in cfg["images"]:
if not img.get("enabled", True) or (a.only and img["id"] not in a.only):
continue
print(f"== {img['name']} ({img.get('branch') or 'default'})", flush=True)
try:
root = os.path.join(a.cache, img["id"])
print(" image updated on", fetch(img["repo"], img.get("branch"), root, True), flush=True)
plugin_dirs = []
for p in img.get("plugins", []):
pdir = os.path.join(a.cache, img["id"] + "__" + p["name"])
print(f" plugin {p['name']}:", fetch(p["repo"], p.get("branch"), pdir, False), flush=True)
plugin_dirs.append(pdir)
cat = e2catalog.build(root, img["id"], plugin_dirs)
cat["displayName"] = img["name"]
with open(os.path.join(a.out, img["id"] + ".json"), "w", encoding="utf-8") as f:
json.dump(cat, f, indent=1, ensure_ascii=False)
with open(os.path.join(a.out, img["id"] + ".md"), "w", encoding="utf-8") as f:
f.write(e2catalog.to_markdown(cat))
print(f" {len(cat['screens'])} screens, {len(cat['skinEngine']['attributes'])} attributes, "
f"{len(cat['parseErrors'])} unreadable files", flush=True)
done.append(img["id"])
except Exception as exc: # one broken image does not stop the others
print(" ERROR:", exc, flush=True)
failed.append(img["id"])

if len(done) > 1:
files = [os.path.join(a.out, i + ".json") for i in done]
subprocess.run([sys.executable, os.path.join(HERE, "e2compare.py")] + files +
["--md", os.path.join(a.out, "compare.md"), "--json", os.path.join(a.out, "compare.json")])
with open(os.path.join(a.out, "index.json"), "w", encoding="utf-8") as f:
json.dump({"images": [{"id": i["id"], "name": i["name"], "branch": i.get("branch"), "file": i["id"] + ".json"}
for i in cfg["images"] if i["id"] in done]}, f, indent=1)
print(f"\nDone: {len(done)} ok, {len(failed)} failed {failed if failed else ''}. Output in {a.out}")
sys.exit(1 if failed else 0)


if __name__ == "__main__":
main()
Loading
Loading