mirror of
https://github.com/greflm13/StaticGalleryBuilder.git
synced 2026-02-05 02:59:27 +00:00
better handling of imagemagick subprocess
This commit is contained in:
2
.github/workflows/build-release.yml
vendored
2
.github/workflows/build-release.yml
vendored
@@ -12,7 +12,7 @@ jobs:
|
|||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: pip install -r requirements.txt
|
run: pip install -r requirements.txt
|
||||||
- name: Build Package
|
- name: Build Package
|
||||||
run: pyinstaller builder.py modules/*.py -n StaticGalleryBuilder -F --add-data files:files --add-data templates:templates --add-data .version:.
|
run: pyinstaller builder.py modules/*.py -n StaticGalleryBuilder-$(cat .version)-linux -F --add-data files:files --add-data templates:templates --add-data .version:.
|
||||||
- name: Release
|
- name: Release
|
||||||
uses: softprops/action-gh-release@v2
|
uses: softprops/action-gh-release@v2
|
||||||
if: startsWith(github.ref, 'refs/tags/')
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
|||||||
@@ -157,6 +157,14 @@
|
|||||||
"label": "Delete Lockfile",
|
"label": "Delete Lockfile",
|
||||||
"problemMatcher": [],
|
"problemMatcher": [],
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
|
"presentation": {
|
||||||
|
"echo": false,
|
||||||
|
"reveal": "never",
|
||||||
|
"focus": false,
|
||||||
|
"panel": "shared",
|
||||||
|
"showReuseMessage": false,
|
||||||
|
"clear": true
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"command": "rm -f /home/user/woek/Pictures/.lock",
|
"command": "rm -f /home/user/woek/Pictures/.lock",
|
||||||
@@ -164,7 +172,53 @@
|
|||||||
"label": "Delete Lockfile 2",
|
"label": "Delete Lockfile 2",
|
||||||
"problemMatcher": [],
|
"problemMatcher": [],
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
|
"presentation": {
|
||||||
|
"echo": false,
|
||||||
|
"reveal": "never",
|
||||||
|
"focus": false,
|
||||||
|
"panel": "shared",
|
||||||
|
"showReuseMessage": false,
|
||||||
|
"clear": true
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"command": "pyinstaller builder.py modules/*.py -n StaticGalleryBuilder-$(cat .version)-linux -F --add-data files:files --add-data templates:templates --add-data .version:.",
|
||||||
|
"isBackground": false,
|
||||||
|
"label": "Build",
|
||||||
|
"problemMatcher": [],
|
||||||
|
"type": "shell",
|
||||||
|
"presentation": {
|
||||||
|
"echo": true,
|
||||||
|
"reveal": "always",
|
||||||
|
"focus": false,
|
||||||
|
"panel": "shared",
|
||||||
|
"showReuseMessage": false,
|
||||||
|
"clear": false
|
||||||
|
},
|
||||||
|
"group": {
|
||||||
|
"kind": "build",
|
||||||
|
"isDefault": true
|
||||||
|
},
|
||||||
|
"dependsOn": [
|
||||||
|
"Clean"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "rm -rf build dist",
|
||||||
|
"isBackground": true,
|
||||||
|
"label": "Clean",
|
||||||
|
"problemMatcher": [],
|
||||||
|
"type": "shell",
|
||||||
|
"presentation": {
|
||||||
|
"echo": true,
|
||||||
|
"reveal": "never",
|
||||||
|
"focus": false,
|
||||||
|
"panel": "shared",
|
||||||
|
"showReuseMessage": false,
|
||||||
|
"clear": true
|
||||||
|
},
|
||||||
|
"group": "build"
|
||||||
|
}
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
from typing import List, Dict
|
from typing import List, Dict
|
||||||
|
from subprocess import Popen, PIPE
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from jinja2 import Environment, FileSystemLoader
|
from jinja2 import Environment, FileSystemLoader
|
||||||
|
|
||||||
@@ -92,10 +93,23 @@ def generate_favicon(iconspath: str, root_directory: str) -> None:
|
|||||||
"""
|
"""
|
||||||
favicon = os.path.join(root_directory, ".static", "favicon.ico")
|
favicon = os.path.join(root_directory, ".static", "favicon.ico")
|
||||||
logger.info("generating favicon with imagemagick", extra={"iconspath": iconspath, "favicon": favicon})
|
logger.info("generating favicon with imagemagick", extra={"iconspath": iconspath, "favicon": favicon})
|
||||||
command = f'magick {os.path.join(iconspath, "icon.png")} -define icon:auto-resize=16,32,48,64,72,96,144,192 {favicon}'
|
_env = dict(os.environ)
|
||||||
|
lp_key = "LD_LIBRARY_PATH"
|
||||||
|
lp_orig = _env.get(lp_key + "_ORIG")
|
||||||
|
if lp_orig is not None:
|
||||||
|
_env[lp_key] = lp_orig
|
||||||
|
else:
|
||||||
|
_env.pop(lp_key, None)
|
||||||
if not shutil.which("magick"):
|
if not shutil.which("magick"):
|
||||||
command = f'convert {os.path.join(iconspath, "icon.png")} -define icon:auto-resize=16,32,48,64,72,96,144,192 {favicon}'
|
magick = shutil.which("convert")
|
||||||
os.system(command)
|
else:
|
||||||
|
magick = shutil.which("magick")
|
||||||
|
command = [magick, os.path.join(iconspath, "icon.png"), "-define", "icon:auto-resize=16,32,48,64,72,96,144,192", favicon]
|
||||||
|
with Popen(command, stdin=PIPE, stdout=PIPE, stderr=PIPE, env=_env, errors="ignore") as p:
|
||||||
|
out, err = p.communicate()
|
||||||
|
if p.returncode != 0:
|
||||||
|
logger.error("error generating favicon: %s", err, extra={"command": command, "out": out, "err": err})
|
||||||
|
logger.info("favicon generated successfully", extra={"command": command, "out": out, "err": err})
|
||||||
|
|
||||||
|
|
||||||
def icons(_args: Args) -> None:
|
def icons(_args: Args) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user