Escape space in appliances urls

Fix #89
This commit is contained in:
Julien Duponchelle 2016-02-03 11:26:36 +01:00
parent bbad1deebb
commit 8eb92b3ade
No known key found for this signature in database
GPG Key ID: F1E2485547D4595D
5 changed files with 18 additions and 4 deletions

View File

@ -35,7 +35,7 @@
"md5sum": "f1d2c25b6990f99bd05b433ab603bdb4", "md5sum": "f1d2c25b6990f99bd05b433ab603bdb4",
"filesize": 197120, "filesize": 197120,
"download_url": "https://sourceforge.net/projects/gns-3/files/Empty%20Qemu%20disk/", "download_url": "https://sourceforge.net/projects/gns-3/files/Empty%20Qemu%20disk/",
"direct_download_url": "http://downloads.sourceforge.net/project/gns-3/Empty Qemu disk/empty8G.qcow2" "direct_download_url": "http://downloads.sourceforge.net/project/gns-3/Empty%20Qemu%20disk/empty8G.qcow2"
} }
], ],
"versions": [ "versions": [

View File

@ -60,7 +60,7 @@
"md5sum": "f1d2c25b6990f99bd05b433ab603bdb4", "md5sum": "f1d2c25b6990f99bd05b433ab603bdb4",
"filesize": 197120, "filesize": 197120,
"download_url": "https://sourceforge.net/projects/gns-3/files/Empty%20Qemu%20disk/", "download_url": "https://sourceforge.net/projects/gns-3/files/Empty%20Qemu%20disk/",
"direct_download_url": "http://downloads.sourceforge.net/project/gns-3/Empty Qemu disk/empty8G.qcow2" "direct_download_url": "http://downloads.sourceforge.net/project/gns-3/Empty%20Qemu%20disk/empty8G.qcow2"
} }
], ],
"versions": [ "versions": [

View File

@ -35,7 +35,7 @@
"md5sum": "f1d2c25b6990f99bd05b433ab603bdb4", "md5sum": "f1d2c25b6990f99bd05b433ab603bdb4",
"filesize": 197120, "filesize": 197120,
"download_url": "https://sourceforge.net/projects/gns-3/files/Empty%20Qemu%20disk/", "download_url": "https://sourceforge.net/projects/gns-3/files/Empty%20Qemu%20disk/",
"direct_download_url": "http://downloads.sourceforge.net/project/gns-3/Empty Qemu disk/empty8G.qcow2" "direct_download_url": "http://downloads.sourceforge.net/project/gns-3/Empty%20Qemu%20disk/empty8G.qcow2"
} }
], ],
"versions": [ "versions": [

View File

@ -46,7 +46,7 @@
"md5sum": "f1d2c25b6990f99bd05b433ab603bdb4", "md5sum": "f1d2c25b6990f99bd05b433ab603bdb4",
"filesize": 197120, "filesize": 197120,
"download_url": "https://sourceforge.net/projects/gns-3/files/Empty%20Qemu%20disk/", "download_url": "https://sourceforge.net/projects/gns-3/files/Empty%20Qemu%20disk/",
"direct_download_url": "http://downloads.sourceforge.net/project/gns-3/Empty Qemu disk/empty8G.qcow2" "direct_download_url": "http://downloads.sourceforge.net/project/gns-3/Empty%20Qemu%20disk/empty8G.qcow2"
} }
], ],
"versions": [ "versions": [

View File

@ -22,8 +22,19 @@ Prettify all appliances JSON
import glob import glob
import json import json
import jsonschema import jsonschema
import urllib
from collections import OrderedDict from collections import OrderedDict
def clean_urls(obj):
"""
All url key are properly escaped
"""
for key in obj.keys():
if key.endswith("_url"):
if not "%" in obj[key]:
obj[key] = obj[key].replace(' ', '%20')
def sort_key_using_schema(schema, key): def sort_key_using_schema(schema, key):
""" """
Sort by position of a key in the JSON Sort by position of a key in the JSON
@ -41,12 +52,15 @@ for appliance in glob.glob('appliances/*.gns3a'):
config = json.load(f) config = json.load(f)
config = OrderedDict(sorted(config.items(), key=lambda t: sort_key_using_schema(schema, t[0]))) config = OrderedDict(sorted(config.items(), key=lambda t: sort_key_using_schema(schema, t[0])))
clean_urls(config)
for key,val in config.items(): for key,val in config.items():
if isinstance(val, dict): if isinstance(val, dict):
config[key] = OrderedDict(sorted(val.items(), key=lambda t: sort_key_using_schema(schema['properties'][key], t[0]))) config[key] = OrderedDict(sorted(val.items(), key=lambda t: sort_key_using_schema(schema['properties'][key], t[0])))
images = [] images = []
for image in config['images']: for image in config['images']:
clean_urls(image)
images.append(OrderedDict(sorted(image.items(), key=lambda t: sort_key_using_schema(schema['properties']['images']['items'], t[0])))) images.append(OrderedDict(sorted(image.items(), key=lambda t: sort_key_using_schema(schema['properties']['images']['items'], t[0]))))
images = sorted(images, key=lambda t: t['version'], reverse=True) images = sorted(images, key=lambda t: t['version'], reverse=True)
config['images'] = images config['images'] = images