107 lines
3.5 KiB
Python
107 lines
3.5 KiB
Python
#!/usr/bin/env python3
|
|
# coding=utf-8
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
# Copyright (C) 2026 Alex
|
|
"""
|
|
Builds the zip to publish on inkscape.org (Extensions category).
|
|
|
|
python package.py # dist/dog_bandana-<version>.zip + .md5
|
|
python package.py --sign # also dist/dog_bandana-<version>.sig (GnuPG)
|
|
|
|
Follows https://inkscape.gitlab.io/extensions/documentation/authors/submit.html:
|
|
one zip for every platform, files at the root of the archive, nothing
|
|
downloaded at run time. numpy and lxml are shipped with Inkscape and are not
|
|
bundled. The version comes from dog_bandana_core.__version__.
|
|
|
|
Before writing the archive, checks that the shipped Python files parse with
|
|
the Python 3.8 grammar, and that the compiled translations and the dialog
|
|
image are present.
|
|
"""
|
|
|
|
import ast
|
|
import glob
|
|
import hashlib
|
|
import os
|
|
import re
|
|
import subprocess
|
|
import sys
|
|
import zipfile
|
|
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
DIST = os.path.join(HERE, "dist")
|
|
NAME = "dog_bandana"
|
|
PYTHON_FILES = ["dog_bandana.py", "dog_bandana_core.py"]
|
|
FILES = ["dog_bandana.inx"] + PYTHON_FILES + [
|
|
"images/parameters_en.png", "LICENSE", "README.en.md"]
|
|
|
|
|
|
def version():
|
|
with open(os.path.join(HERE, "dog_bandana_core.py"), encoding="utf-8") as handle:
|
|
match = re.search(r'^__version__ = "([^"]+)"', handle.read(), re.M)
|
|
if not match:
|
|
sys.exit("__version__ not found in dog_bandana_core.py")
|
|
return match.group(1)
|
|
|
|
|
|
def shipped_files():
|
|
"""Relative paths of the files that go into the archive."""
|
|
locales = sorted(os.path.relpath(path, HERE).replace(os.sep, "/") for path in
|
|
glob.glob(os.path.join(HERE, "locale", "*", "LC_MESSAGES", "*.mo")))
|
|
if not locales:
|
|
sys.exit("No compiled translation: run python i18n.py first")
|
|
files = FILES + locales
|
|
missing = [name for name in files if not os.path.isfile(os.path.join(HERE, name))]
|
|
if missing:
|
|
sys.exit("Missing files: {}".format(", ".join(missing)))
|
|
return files
|
|
|
|
|
|
def check_python38():
|
|
"""The submission rules require Python 3.8 or later."""
|
|
for name in PYTHON_FILES:
|
|
with open(os.path.join(HERE, name), encoding="utf-8") as handle:
|
|
try:
|
|
ast.parse(handle.read(), name, feature_version=(3, 8))
|
|
except SyntaxError as error:
|
|
sys.exit("{} is not Python 3.8 compatible: {}".format(name, error))
|
|
|
|
|
|
def build():
|
|
check_python38()
|
|
files = shipped_files()
|
|
os.makedirs(DIST, exist_ok=True)
|
|
archive = os.path.join(DIST, "{}-{}.zip".format(NAME, version()))
|
|
with zipfile.ZipFile(archive, "w", zipfile.ZIP_DEFLATED) as zipped:
|
|
for name in files:
|
|
zipped.write(os.path.join(HERE, name), name)
|
|
with open(archive, "rb") as handle:
|
|
digest = hashlib.md5(handle.read()).hexdigest()
|
|
with open(archive + ".md5", "w", encoding="ascii", newline="\n") as handle:
|
|
handle.write("{} {}\n".format(digest, os.path.basename(archive)))
|
|
print(archive)
|
|
for name in files:
|
|
print(" " + name)
|
|
print("md5 " + digest)
|
|
return archive
|
|
|
|
|
|
def sign(archive):
|
|
"""Detached GnuPG signature, with the key registered on inkscape.org."""
|
|
signature = os.path.splitext(archive)[0] + ".sig"
|
|
if os.path.exists(signature):
|
|
os.remove(signature)
|
|
subprocess.run(["gpg", "--output", signature, "--detach-sign", "--sign", archive],
|
|
check=True)
|
|
print(signature)
|
|
|
|
|
|
def main(argv):
|
|
archive = build()
|
|
if "--sign" in argv:
|
|
sign(archive)
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main(sys.argv[1:]))
|