Add first theme package (solarized-dark)

This commit is contained in:
Thomas Pointhuber 2021-10-30 17:38:58 +02:00
parent d6890d8f56
commit 8ef46c0a47
5 changed files with 181 additions and 6 deletions

112
create_repository.py Normal file
View file

@ -0,0 +1,112 @@
#!/usr/bin/env python3
import datetime
import hashlib
import json
import zipfile
from pathlib import Path
from zipfile import ZipFile
ROOT_PATH = Path(__file__).resolve().parent
PACKAGES_JSON_PATH = ROOT_PATH / "packages.json"
REPOSITORY_JSON_PATH = ROOT_PATH / "repository.json"
METADATA_FILEAME = "metadata.json"
REPOSITORY_BASE_URI = "https://raw.githubusercontent.com/pointhi/kicad-color-schemes/master"
READ_SIZE = 65536
def sha256_of_file(path):
file_hash = hashlib.sha256()
with path.open("rb") as f:
data = f.read(READ_SIZE)
while data:
file_hash.update(data)
data = f.read(READ_SIZE)
return file_hash.hexdigest()
def create_pcm_from_color_scheme(path, resulting_file):
with ZipFile(resulting_file, 'w', compression=zipfile.ZIP_DEFLATED) as zip:
for json_file in path.glob("*.json"):
if json_file.name == METADATA_FILEAME:
continue
print(json_file)
zip.write(json_file, f"colors/{json_file.name}")
def create_and_get_pcm(path):
metadata_path = path / METADATA_FILEAME
if not metadata_path.exists():
return
with metadata_path.open("rb") as f:
metadata_json = json.load(f)
identifier = metadata_json["identifier"]
for metadata_version in metadata_json["versions"]:
version = metadata_version['version']
pkg_name = f"{identifier}_v{version}_pcm.zip"
pkg_path = path / pkg_name
if not pkg_path.exists():
# create new package as it does not exist yet (new version)
create_pcm_from_color_scheme(path, pkg_path)
# fill in package data
install_size = 0
with ZipFile(pkg_path, 'r') as zip:
for file in zip.filelist:
print(file.filename)
install_size += zip.getinfo(file.filename).file_size
metadata_version['download_sha256'] = sha256_of_file(pkg_path)
metadata_version['download_size'] = pkg_path.stat().st_size
metadata_version['download_url'] = f"{REPOSITORY_BASE_URI}/{path.name}/{pkg_name}"
metadata_version['install_size'] = install_size
return metadata_json
def write_packages_json(package_array):
packages_data = {"packages": package_array}
with PACKAGES_JSON_PATH.open("w", encoding="utf-8") as f:
json.dump(packages_data, f, indent=4)
def write_repository_json():
packages_json_sha256 = sha256_of_file(PACKAGES_JSON_PATH)
packages_json_update_timestamp = int(PACKAGES_JSON_PATH.stat().st_mtime)
packages_json_update_time_utc = datetime.datetime.fromtimestamp(packages_json_update_timestamp, tz=datetime.timezone.utc)
repository_data = {
"$schema": "https://gitlab.com/kicad/code/kicad/-/raw/master/kicad/pcm/schemas/pcm.v1.schema.json#/definitions/Repository",
"maintainer": {
"contact": {
"web": "https://github.com/pointhi/kicad-color-schemes/"
},
"name": "Thomas Pointhuber"
},
"name": "kicad-color-schemes repository by @pointhi",
"packages": {
"sha256": packages_json_sha256,
"update_time_utc": packages_json_update_time_utc.strftime("%Y-%m-%d %H:%M:%S"),
"update_timestamp": packages_json_update_timestamp,
"url": f"{REPOSITORY_BASE_URI}/packages.json"
}
}
with REPOSITORY_JSON_PATH.open("w", encoding="utf-8") as f:
json.dump(repository_data, f, indent=4)
schema = create_and_get_pcm(ROOT_PATH / "solarized-dark")
write_packages_json([schema])
write_repository_json()

View file

@ -1,4 +1,39 @@
{
"packages": [
{
"$schema": "https://gitlab.com/qu1ck/kicad/-/raw/pcm/kicad/pcm/schemas/pcm.v1.schema.json#",
"name": "solarized-dark theme",
"description": "solarized-dark color theme",
"description_full": "solarized-dark color theme",
"identifier": "theme-solarized-dark",
"type": "colortheme",
"author": {
"name": "Thomas Pointhuber",
"contact": {
"web": "https://github.com/pointhi/kicad-color-schemes/"
}
},
"maintainer": {
"name": "Thomas Pointhuber",
"contact": {
"web": "https://github.com/pointhi/kicad-color-schemes/"
}
},
"license": "CC0-1.0",
"resources": {
"Github": "https://github.com/pointhi/kicad-color-schemes"
},
"versions": [
{
"version": "1.0",
"status": "stable",
"kicad_version": "5.99",
"download_sha256": "ea0496aa0353e9b6e871c0057f1ead27b31738ed9d9dff2f28df766427e9e1ab",
"download_size": 516,
"download_url": "https://raw.githubusercontent.com/pointhi/kicad-color-schemes/master/solarized-dark/theme-solarized-dark_v1.0_pcm.zip",
"install_size": 1091
}
]
}
]
}
}

View file

@ -8,10 +8,9 @@
},
"name": "kicad-color-schemes repository by @pointhi",
"packages": {
"sha256": "a34335dda0557ee4c58b356c88ec4593117e51a28de7415c31c581334591bffa",
"update_time_utc": "2021-10-30 15:23:00",
"update_timestamp": 1635592980,
"sha256": "72f613fa99c990ca677e8c351e118b3c6db2a02e3ccc331ff835affe52de88fc",
"update_time_utc": "2021-10-30 15:38:14",
"update_timestamp": 1635608294,
"url": "https://raw.githubusercontent.com/pointhi/kicad-color-schemes/master/packages.json"
}
}
}

View file

@ -0,0 +1,29 @@
{
"$schema": "https://gitlab.com/qu1ck/kicad/-/raw/pcm/kicad/pcm/schemas/pcm.v1.schema.json#",
"name": "solarized-dark theme",
"description": "solarized-dark color theme",
"description_full": "solarized-dark color theme",
"identifier": "theme-solarized-dark",
"type": "colortheme",
"author": {
"name": "Thomas Pointhuber",
"contact": {
"web": "https://github.com/pointhi/kicad-color-schemes/"
}
},
"maintainer": {
"name": "Thomas Pointhuber",
"contact": {
"web": "https://github.com/pointhi/kicad-color-schemes/"
}
},
"license": "CC0-1.0",
"resources": {
"Github": "https://github.com/pointhi/kicad-color-schemes"
},
"versions": [{
"version": "1.0",
"status": "stable",
"kicad_version": "5.99"
}]
}

Binary file not shown.