Merge pull request #397 from ehlers/master

Make installation of imagemagick optional
This commit is contained in:
Jeremy Grossmann 2019-01-14 11:03:25 +07:00 committed by GitHub
commit 8bea5f2710
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 2 deletions

View File

@ -49,7 +49,8 @@ Check appliance files
python check.py python check.py
python3 check_urls.py python3 check_urls.py
You need to install `imagemagick` before running check.py. If `imagemagick` is installed, it will be used to check the symbol properties.
Otherwise an (experimental) internal function will do that.
Create a new appliance Create a new appliance
----------------------- -----------------------

View File

@ -19,6 +19,8 @@ import os
import jsonschema import jsonschema
import json import json
import sys import sys
import re
import shutil
import subprocess import subprocess
@ -97,12 +99,45 @@ def check_packer(packer):
json.load(f) json.load(f)
unit2px = {'cm': 35.43307, 'mm': 3.543307, 'in': 90.0,
'pc': 15.0, 'pt': 1.25, 'px': 1.0}
def svg_get_height(filename):
with open(filename, 'r') as image_file:
image_data = image_file.read()
match = re.search('<svg[^>]*\sheight="([^"]+)"', image_data)
if not match:
print("{}: can't determine the image height".format(filename))
sys.exit(1)
height = match.group(1)
unit = height[-2:]
if unit in unit2px:
factor = unit2px[unit]
height = height[:-2]
else:
factor = 1.0
try:
height = round(float(height) * factor)
except ValueError:
print("{}: can't determine the image height".format(filename))
sys.exit(1)
return height
use_imagemagick = shutil.which("identify")
def check_symbol(symbol): def check_symbol(symbol):
licence_file = os.path.join('symbols', symbol.replace('.svg', '.txt')) licence_file = os.path.join('symbols', symbol.replace('.svg', '.txt'))
if not os.path.exists(licence_file): if not os.path.exists(licence_file):
print("Missing licence {} for {}".format(licence_file, symbol)) print("Missing licence {} for {}".format(licence_file, symbol))
sys.exit(1) sys.exit(1)
height = int(subprocess.check_output(['identify', '-format', '%h', os.path.join('symbols', symbol)], shell=False)) if use_imagemagick:
height = int(subprocess.check_output(['identify', '-format', '%h', os.path.join('symbols', symbol)], shell=False))
else:
height = svg_get_height(os.path.join('symbols', symbol))
if height > 70: if height > 70:
print("Symbol height of {} is too big {} > 70".format(symbol, height)) print("Symbol height of {} is too big {} > 70".format(symbol, height))
sys.exit(1) sys.exit(1)