import_design Script
scripts/import_design.py is the end-to-end command-line tool for ingesting a
GIF animation into the Lighting Rig Backend. It orchestrates three stages:
| Stage | Description |
|---|---|
| 1 – Process | Calls the packet processing pipeline to convert the GIF into RGB565 packet files, a 16 × 16 preview GIF, and a JSON metadata file. |
| 2 – Upload | Sends the preview GIF, encoded payload, and metadata file to the backend storage endpoint. |
| 3 – Register | POSTs a design record to /designs, then links each uploaded file as a design asset via /design-assets. |
Usage
python scripts/import_design.py --input path/to/animation.gif
Options
| Flag | Default | Description |
|---|---|---|
--input |
(required) | Path to a GIF file or a folder of GIFs. |
--output |
Input folder | Output folder for processed files. |
--backend-base-url |
http://127.0.0.1:8000 |
Backend base URL (overridden by BACKEND_BASE_URL env var). |
--packet-size |
120 |
Number of RGB565 hex values per packet. |
--chunk-size |
100 |
Number of packet files per chunk sub-folder. |
--design-type |
gif |
Design type label written to the database. |
--callsign |
(auto-generated) | Fixed six-character callsign. |
--creator |
(from metadata) | Creator name override. |
--description |
(from metadata) | Description override. |
Environment Variables
BACKEND_BASE_URL – overrides the default backend URL without needing to pass
--backend-base-url on every invocation.
API Reference
scripts.import_design
End-to-end import script for ingesting a GIF design into the backend.
This script drives the full pipeline from a raw GIF file (or folder of GIFs) through to a fully registered design record with associated storage assets:
- Process – calls
archive.process_packets.run_processingto convert each GIF into RGB565 packet files, a 16 × 16 preview GIF, and a JSON metadata file. - Upload – sends the preview GIF, encoded payload, and metadata file to the backend storage endpoint.
- Register – POSTs a design record to
/designs, then links each uploaded file as a design asset via/design-assets.
Typical usage::
python scripts/import_design.py --input path/to/animation.gif
See parse_args for the full list of command-line options.
build_payload(metadata, design_type, creator, description, callsign)
Assemble the JSON payload for the POST /designs endpoint.
Values supplied as arguments take precedence over those read from the metadata file, allowing the caller to override fields at import time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata
|
dict
|
Parsed content of the |
required |
design_type
|
str
|
Design type string (e.g. |
required |
creator
|
str | None
|
Optional creator name; falls back to the metadata value. |
required |
description
|
str | None
|
Optional description; falls back to the metadata value. |
required |
callsign
|
str | None
|
Optional fixed callsign; a random one is generated if
|
required |
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary suitable for serialising to JSON and posting to |
dict
|
|
Source code in scripts/import_design.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
create_design_record(designs_url, payload)
Post a design payload and return the status, response, and echoed payload.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
designs_url
|
str
|
Full URL of the |
required |
payload
|
dict
|
Design fields to register. |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, str, dict]
|
A three-tuple of |
Source code in scripts/import_design.py
208 209 210 211 212 213 214 215 216 217 218 219 | |
generate_callsign()
Generate a random six-character alphanumeric callsign.
Characters are drawn from uppercase ASCII letters and digits using the
secrets module, making each callsign cryptographically random.
Returns:
| Type | Description |
|---|---|
str
|
A six-character string such as |
Source code in scripts/import_design.py
45 46 47 48 49 50 51 52 53 54 | |
load_metadata(metadata_path)
Load and parse a JSON metadata file produced by the processing step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata_path
|
Path
|
Path to the |
required |
Returns:
| Type | Description |
|---|---|
dict
|
The parsed metadata as a dictionary. |
Source code in scripts/import_design.py
57 58 59 60 61 62 63 64 65 66 67 | |
parse_args()
Parse command-line arguments for the import script.
Returns:
| Type | Description |
|---|---|
Namespace
|
A populated :class: |
Namespace
|
|
Namespace
|
|
Source code in scripts/import_design.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
post_design(api_url, payload)
POST a design creation payload to the /designs endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_url
|
str
|
Full URL of the |
required |
payload
|
dict
|
Design fields as produced by :func: |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, str]
|
A two-tuple of |
Source code in scripts/import_design.py
133 134 135 136 137 138 139 140 141 142 143 | |
post_design_asset(api_url, payload)
POST a design asset record to the /design-assets endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_url
|
str
|
Full URL of the |
required |
payload
|
dict
|
Asset fields including |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, str]
|
A two-tuple of |
Source code in scripts/import_design.py
194 195 196 197 198 199 200 201 202 203 204 205 | |
post_json(url, payload)
Send a JSON POST request using only the standard library.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The full URL to POST to. |
required |
payload
|
dict
|
A JSON-serialisable dictionary to send as the request body. |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, str]
|
A two-tuple of |
Source code in scripts/import_design.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
upload_file_via_backend(backend_base_url, callsign, filename, file_path, content_type)
Upload a file to the backend storage endpoint.
Constructs a POST /storage/upload request, passing the callsign,
remote filename, and content type as query parameters and the raw file
bytes as the request body.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend_base_url
|
str
|
Base URL of the backend (e.g. |
required |
callsign
|
str
|
The design callsign used to namespace the upload. |
required |
filename
|
str
|
Remote filename to store the asset under. |
required |
file_path
|
Path
|
Local path of the file to upload. |
required |
content_type
|
str
|
MIME type of the file. |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, str]
|
A two-tuple of |
Source code in scripts/import_design.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |