Support devices stored in sub directories

This commit is contained in:
Julien Duponchelle 2015-05-21 17:15:58 +02:00
parent 10cd2861d3
commit 78542eee40
4 changed files with 11 additions and 9 deletions

View File

@ -37,11 +37,13 @@ class Repository:
#TODO: Manage open error
devices_path = self._get_devices_path()
for file in os.listdir(devices_path):
with open(os.path.join(devices_path, file)) as f:
config = json.load(f)
if self._image_match(image, config):
configurations.append(config)
for (dirpath, dirnames, filenames) in os.walk(devices_path):
for filename in filenames:
file = os.path.join(dirpath, filename)
with open(os.path.join(devices_path, file)) as f:
config = json.load(f)
if self._image_match(image, config):
configurations.append(config)
return configurations

View File

@ -76,7 +76,7 @@ def empty_config(tmpdir):
def test_add_image(empty_config, linux_microcore_img):
with open("devices/microcore-linux.json") as f:
with open("devices/qemu/microcore-linux.json") as f:
config = json.load(f)
image = Image(linux_microcore_img)
image.version = "3.4.1"
@ -107,7 +107,7 @@ def test_add_image(empty_config, linux_microcore_img):
def test_add_image_uniq(empty_config, linux_microcore_img):
with open("devices/microcore-linux.json") as f:
with open("devices/qemu/microcore-linux.json") as f:
config = json.load(f)
image = Image(linux_microcore_img)
image.version = "3.4.1"
@ -120,7 +120,7 @@ def test_add_image_uniq(empty_config, linux_microcore_img):
def test_save(empty_config, linux_microcore_img):
with open("devices/microcore-linux.json") as f:
with open("devices/qemu/microcore-linux.json") as f:
config = json.load(f)
empty_config.add_image(config)
empty_config.save()

View File

@ -25,7 +25,7 @@ from gns3repository.repository import Repository
def test_detect_image(linux_microcore_img):
with open("devices/microcore-linux.json") as f:
with open("devices/qemu/microcore-linux.json") as f:
config = json.load(f)
repository = Repository()