mirror of
https://github.com/GNS3/gns3-registry.git
synced 2024-12-24 15:06:43 +00:00
Merge pull request #397 from ehlers/master
Make installation of imagemagick optional
This commit is contained in:
commit
8bea5f2710
@ -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
|
||||||
-----------------------
|
-----------------------
|
||||||
|
37
check.py
37
check.py
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user