From 8ef46c0a47fc69244cbae36c005eb91512515daa Mon Sep 17 00:00:00 2001 From: Thomas Pointhuber Date: Sat, 30 Oct 2021 17:38:58 +0200 Subject: [PATCH] Add first theme package (solarized-dark) --- create_repository.py | 112 ++++++++++++++++++ packages.json | 37 +++++- repository.json | 9 +- solarized-dark/metadata.json | 29 +++++ .../theme-solarized-dark_v1.0_pcm.zip | Bin 0 -> 516 bytes 5 files changed, 181 insertions(+), 6 deletions(-) create mode 100644 create_repository.py create mode 100644 solarized-dark/metadata.json create mode 100644 solarized-dark/theme-solarized-dark_v1.0_pcm.zip diff --git a/create_repository.py b/create_repository.py new file mode 100644 index 0000000..fc5bd81 --- /dev/null +++ b/create_repository.py @@ -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() diff --git a/packages.json b/packages.json index 4f2684b..068523f 100644 --- a/packages.json +++ b/packages.json @@ -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 + } + ] + } ] -} +} \ No newline at end of file diff --git a/repository.json b/repository.json index 20ee2a3..abb567f 100644 --- a/repository.json +++ b/repository.json @@ -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" } -} - +} \ No newline at end of file diff --git a/solarized-dark/metadata.json b/solarized-dark/metadata.json new file mode 100644 index 0000000..4292e5c --- /dev/null +++ b/solarized-dark/metadata.json @@ -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" + }] +} diff --git a/solarized-dark/theme-solarized-dark_v1.0_pcm.zip b/solarized-dark/theme-solarized-dark_v1.0_pcm.zip new file mode 100644 index 0000000000000000000000000000000000000000..50fbcc240d10affdcb58fe8547f33aded84751a8 GIT binary patch literal 516 zcmWIWW@Zs#U|`^2_}0-MAnSfcBae}R!I_1DK?*3EoS&0lRIFc|pOaXWS(Tcio03?R zt(R4tpVvFtH?P@1p!K^gYtmJ(kVAjeV!yN5G8m;X<@Lz&ss&0veYbTXTafF8UeF|zF=2=xJrKAtG)WG(hu}$ zXEt2Ox$|b-{f%rx=+NUud>zT3=&_uYM;!key7N94Z(ZGVw#*ilM*IPOq^NZ5XP|R z(8-t-r6p!=b?mVkUV5)h-yCoZ3GSNf>*%!mj7RUDDDy8jy_X%o)*q5{%QI;6nY{vA zSOTv&O%1Wo>zorI^_Nka?+3q+#x_NDNAbM8I(_SyUz1iPczGpM70L6(ZV>!-v+1(* z^`b{b!aFt#wLa^yF*O#xYg`+B?&ZmIr;hx*WO9g6K&AQW$JbH}d-F0Kx}Khn4%cqm zww_gD*lR|VLpM|y}}~sTc!QoI)(smMkWzv-0=jADlk~m2%>PuT7Wkz8%PBs O5PAUVWx%**U;qFGdeV#l literal 0 HcmV?d00001