Download
download
¶
Defines helpers to download the upstream sources used in the
Build Pipeline, and the pre-built
kotobase database
Fetches raw upstream source files and saves them in the raw per-user cache
directory (See The cofig Module)
Downloads are written to a temporary .part file and moved into place only on
succes, so an interrupted run never leaves a truncated file that a later run
would mistake for a complete download
Except for the kotobase databases which are decompressed as they are downloaded, files are downloaded in their compressed form and left untouched
Supported Sources
-
Plain Direct URL To Asset File
-
GitHub Release Asset, Resolved From The Latest Release Of A Repo
download(source, *, force=False, session=None)
¶
Downloads a single upstream source into the per-user cache raw directory
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Source
|
The source to download |
required |
force
|
bool
|
When True, re download even if the file already exists |
False
|
session
|
Session | None
|
Optional shared session, a new one is created when omitted |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
The path of the downloaded file |
download_all(keys=None, *, force=False, include_optional=True, session=None)
¶
Downloads a set of upstream sources listed in the
SOURCES dictionary
Optional sources that fail to download are skipped with a warning rather than aborting the whole run. A failure of a required source is raised
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
keys
|
list[str] | None
|
Source keys to download, or None for every
source in |
None
|
force
|
bool
|
When True, re download even if files already exist |
False
|
include_optional
|
bool
|
When False, optional sources are skipped |
True
|
session
|
Session | None
|
Optional shared session, a new one is created when omitted |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Path]
|
A mapping of source keys to their downloaded file path, with optional sources that failed left out |
Raises:
| Type | Description |
|---|---|
HTTPError
|
If a required source fails to download |
pull_audio(*, tag=None, force=False)
¶
Download and decompress the optional audio pack database
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag
|
str | None
|
Release tag to pull from, or None for the latest |
None
|
force
|
bool
|
When True, download even if the audio pack already exists |
False
|
Returns:
| Type | Description |
|---|---|
Path
|
The path of the decompressed audio pack |
Raises:
| Type | Description |
|---|---|
FileExistsError
|
If the audio pack already exists and |
pull_db(*, tag=None, force=False)
¶
Downloada and decompresses the prebuilt core database
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag
|
str | None
|
Release tag to pull from, or None for the latest |
None
|
force
|
bool
|
When True, download even if the database already exists |
False
|
Returns:
| Type | Description |
|---|---|
Path
|
The path of the decompressed database |
Raises:
| Type | Description |
|---|---|
FileExistsError
|
If the database already exists and |
resolve_upstream_source(source, session)
¶
Resolves an upstream source to a concrete filename and download URL
Resolution
-
Direct sources names resolve to the final path segment of their URL
-
GitHub release sources are resolved against the latest release, selecting the asset by exact name or by regular expression pattern
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Source
|
The source to resolve |
required |
session
|
Session
|
Session used for any GitHub API lookup |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, str]
|
A tuple of the local filename to save under and the URL to fetch |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the source has neither a URL nor a GitHub repository |
RuntimeError
|
If a matching GitHub release asset cannot be found |