Metadata-Version: 2.5
Name: geler-CERTIC
Version: 0.7.0
Summary: Help convert dynamic webistes to static ones.
Author-email: Mickaël Desfrênes <mickael.desfrenes@unicaen.fr>
Maintainer-email: Mickaël Desfrênes <mickael.desfrenes@unicaen.fr>
License: CECILL-C
License-File: LICENSE.txt
Requires-Python: <4.0,>=3.10
Requires-Dist: argh>=0.31.3
Requires-Dist: beautifulsoup4>=4.15.0
Requires-Dist: certifi>=2026.10.23
Requires-Dist: cssutils>=2.15.0
Requires-Dist: idna>=3.15
Requires-Dist: requests>=2.34.2
Requires-Dist: soupsieve<3,>=2.9
Requires-Dist: urllib3>=2.8.0
Description-Content-Type: text/markdown

# Geler

Help convert dynamic websites to static ones.

## Install 

Requires Python 3.10 or newer.

=> dans un venv

    pip install geler-CERTIC

=> de manière isolée et indépendante (mais disponible globalement)

    pipx install geler-CERTIC

## Usage

As a library in your own program:

    import geler

    def main():
        freezer = geler.Freezer(
            "https://acme.tld/",
            "/save/to/path/",
            thread_pool_size=10,
            http_get_timeout=30,
            skip_extensions=[".mp4", ".mp3"],
        )
        freezer.freeze()

        for err in freezer.http_errors:
            print(f'{err.get("status_code")}: {err.get("url")}')

    if __name__ == "__main__":
        main()

The main guard is required in scripts because link patching starts worker
processes using `spawn`. Run library code from an importable Python script;
interactive shells and notebooks do not support this process-pool setup.

As a CLI tool:

    $> geler --help
    usage: geler [-h] [-t THREAD_POOL_SIZE] [--http-get-timeout HTTP_GET_TIMEOUT] [-s SKIP_EXTENSIONS] [-v] start-from-url save-to-path
    
    positional arguments:
      start-from-url        -
      save-to-path          -
    
    optional arguments:
      -h, --help            show this help message and exit
      -t THREAD_POOL_SIZE, --thread-pool-size THREAD_POOL_SIZE
                            1
      --http-get-timeout HTTP_GET_TIMEOUT
                            30
      -s SKIP_EXTENSIONS, --skip-extensions SKIP_EXTENSIONS
                            -
      -v, --verbose         False


Thread pool size (`--thread-pool-size`) defaults to 1. Increase the number to have multiple downloads in parallel.

HTML/CSS/JavaScript parsing uses 10 processes by default while HTTP downloads
remain threaded. Set `--parse-process-pool-size` to change the process count;
use `0` to parse in download threads. For example:

    geler --thread-pool-size 10 https://acme.tld/ /path/to/local/dir

The library default is `Freezer(..., parse_process_pool_size=10)`. Process
workers return normalized content and discovered URLs. The parent process
validates and schedules URLs, writes files, and updates the checkpoint. At most
twice the parsing worker count of response bodies can be queued or parsing;
download threads wait for a slot before buffering another text response. Binary
files bypass the parsing pool. Workers start only when a text response arrives,
including during a dry run. The parsing pool shuts down before final patching,
so the two process pools do not run together.

Callbacks stay in the parent process. An HTML `callback_before_save` still
receives an editable BeautifulSoup tree; with process parsing, rebuilding that
tree in the parent adds overhead. This also applies to the CLI's verbose save
callback. Parser failures are checkpointed as failed downloads and retried by
`--resume`; changing parsing worker counts does not invalidate a checkpoint.
On interruption, queued parses are cancelled and running parses are drained;
uncommitted results remain pending for resume.

Process parsing helps when parsing consumes substantial CPU time; it adds
startup and data-transfer overhead for smaller sites. See the
[download/parsing benchmark](benchmarks/download_parsing.md) for measured results.

After downloading, link patching uses a separate process pool with up to 10
workers, capped by the CPU count and number of files. Each process receives the
URL mapping once. `callback_after_patch` runs in the calling process, once per
completed file, in completion order. Worker errors propagate to the caller.
Dry runs do not start patch worker processes.

See the [synthetic patching benchmark](benchmarks/README.md) for reproducible
measurements, including process-startup overhead on small workloads.

HTTP get timeout (`--http-get-timeout`) default to 30s. This includes the time needed to download the file. Increase the number to increase the timeout, or set it to 0 for no timeout.

List of skipped  (`--skip-extensions`) is a comma-separated list of extensions that won't be downloaded.

Verbose mode (`--verbose`) will show downloaded URLs, a `patch <path>` trace
after each file is patched, and HTTP errors.

Every non-dry run stores its crawl progress in `.geler-state.sqlite3` inside the
destination directory. If a crawl is interrupted, resume it with the same URL,
destination, and skipped extensions:

    geler --resume https://acme.tld/ /path/to/local/dir

Resume retries interrupted and failed downloads, skips files that were completed,
and patches links again when the crawl finishes. Patch writes use a temporary
`.part` file and atomic replacement, so interrupted writes leave the downloaded
file intact; resume removes stale temporary files. Ctrl+C during patching cancels
pending jobs and waits for active patch workers before returning.
A run without `--resume` starts a
new checkpoint. Geler refuses to resume if the root URL or skipped extensions do
not match the checkpoint. Dry runs do not create checkpoints and cannot be resumed.

Complete example:

    geler --http-get-timeout 30 --thread-pool-size 10 --skip-extension ".mp4,.zip" https://acme.tld/ /path/to/local/dir

## Why ?

For [MaX](https://git.unicaen.fr/pdn-certic/MaX) and associated tools, 
we needed a lightweight, portable, pure Python solution to convert 
small dynamic websites to static ones.

## Alternatives

This tool has a narrow scope, on purpose. Please turn to these solutions if you need more:

- [wget](https://www.gnu.org/software/wget/)
- [pywebcopy](https://pypi.org/project/pywebcopy/)
- [HTTrack](https://www.httrack.com)

## Known Limitations

- only works with HTTP GET
- does not submit forms (even with GET method)
- only considers URLs in `src`, `href`, or URL-like JavaScript string literals in `onclick` attributes
- only considers URLs with `http` or `https` schemes
- only downloads what is in the same [netloc](https://docs.python.org/3/library/urllib.parse.html) (same domain, same port) as the start URL
- patches URLs in `*.html`, `*.css` and JavaScript module imports in `*.js` files, but does not parse arbitrary JS URL construction patterns
- does not throttle requests
- does not respect `robots.txt` or `<meta name="robots" content="noindex">` or any other robot directives.
