git » autoupdaters.git » main » tree

[main] / kicad-api.py

#!/usr/bin/env python3

from urllib.request import urlopen, Request
import ssl
import os
import sys
import json
from subprocess import run,DEVNULL,STDOUT
from autoupdater_helpers import *

os.chdir("/sources/base-pkgbuilds/kicad")

cabundle = "/etc/pki/tls/certs/ca-bundle.crt"
ctx = ssl.create_default_context(cafile=cabundle)
url = "https://downloads.kicad.org/api/v1/update"

prev_ver = pkgbuild_ver()
update_check_obj = {
    'platform': "windows",
    'arch': "amd64",
    'current_version': prev_ver,
    'lang': 'en_GB',
    'last_check': ""
}

# testing
#update_check_obj["current_version"] = "8.0.0"

update_check_s = json.dumps(update_check_obj)
headers = {
'User-Agent': "curl/8.5.0-DEV",
'Accept': "application/json",
'Content-Type': "application/json",
'charset': 'utf-8'
}

req = Request(url,headers=headers)
with urlopen(req, data=update_check_s.encode('utf-8'), context=ctx) as f:
    d = f.read(20480)
    if len(d) == 0:
        print("Empty reply - update not necessary")
        sys.exit(0)
    verinfo = json.loads(d)
    ver = verinfo['version']

print("KiCad version:", ver)


if ver == prev_ver:
    print("Update not necessary")
    sys.exit(0)

print("uhh")
sys.exit(0)

pkgbuild_new_ver(ver)

os.chdir("../kicad-library")

pkgbuild_new_ver(ver)

os.chdir("..")

print(f"Updating {prev_ver} to {ver}")
run(["./mpkg.sh", "kicad"], check=True)
run(["./mpkg.sh", "kicad-library"], check=True)