~nhanb/pytaku

ff20e51f8c178bf981d80aa3737bf31a1059a506 — Bùi Thành Nhân 3 years ago 6640fd8 0.6.0
implement pytaku-collect-static command
4 files changed, 38 insertions(+), 2 deletions(-)

M .builds/debian.yml
M README.md
M pyproject.toml
M src/pytaku/__init__.py
M .builds/debian.yml => .builds/debian.yml +2 -1
@@ 69,7 69,8 @@ tasks:
        cd ~/pytaku &&
        ~/.local/bin/pytaku-migrate &&
        rm -r static &&
        cp -r ~/.local/lib/python3.9/site-packages/pytaku/static ./ &&
        ~/.local/bin/pytaku-collect-static . &&
        tree ./static &&
        sudo systemctl restart pytaku pytaku-scheduler &&
        echo 'All done.'
      "

M README.md => README.md +15 -0
@@ 127,6 127,21 @@ Alternatively, just setup a personal [tailscale](https://tailscale.com/)
network and let them worry about access control and end-to-end encryption for
you.

## Optional optimization

With the setup above, you're serving static assets using gunicorn, which is not
ideal performance-wise. For private usage this doesn't really matter. However,
if you want to properly serve static assets using nginx and the like, you can
copy all static assets into a designated directory with:

```sh
pytaku-collect-static target_dir
```

This will copy all assets into `target_dir/static`. You can now instruct
nginx/caddy/etc. to serve this dir on `/static/*` paths. There's an example
caddyfile to do this in the ./contrib/ dir.

# LICENSE

Copyright (C) 2021 Bùi Thành Nhân

M pyproject.toml => pyproject.toml +2 -1
@@ 1,6 1,6 @@
[tool.poetry]
name = "pytaku"
version = "0.5.2"
version = "0.6.0"
description = "Self-hostable web-based manga reader"
authors = ["Bùi Thành Nhân <hi@imnhan.com>"]
license = "AGPL-3.0-only"


@@ 18,6 18,7 @@ pytaku-dev = "pytaku:dev"
pytaku-migrate = "pytaku:migrate"
pytaku-generate-config = "pytaku:generate_config"
pytaku-scheduler = "pytaku:scheduler"
pytaku-collect-static = "pytaku:collect_static"

[tool.poetry.dependencies]
python = "^3.7"

M src/pytaku/__init__.py => src/pytaku/__init__.py +19 -0
@@ 60,3 60,22 @@ def scheduler():
    from .scheduler import main_loop

    main_loop()


def collect_static():
    from sys import argv

    if len(argv) != 2:
        print("Usage: pytaku-collect-static path/to/static/dir")
        print("A 'static' dir will be created inside the provided path.")
        exit(1)

    import importlib.resources
    from pathlib import Path
    from shutil import copytree

    destination = Path(argv[1]) / "static"

    with importlib.resources.path("pytaku", "__init__.py") as pytaku_path:
        copytree(pytaku_path.parent / "static", destination)
    print(f"Static files copied to {destination}")