From 78542eee4024442a4bfe87f02034f8c45ad3e7d8 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Thu, 21 May 2015 17:15:58 +0200 Subject: [PATCH] Support devices stored in sub directories --- devices/{ => qemu}/microcore-linux.json | 0 gns3repository/repository.py | 12 +++++++----- test/test_config.py | 6 +++--- test/test_repository.py | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) rename devices/{ => qemu}/microcore-linux.json (100%) diff --git a/devices/microcore-linux.json b/devices/qemu/microcore-linux.json similarity index 100% rename from devices/microcore-linux.json rename to devices/qemu/microcore-linux.json diff --git a/gns3repository/repository.py b/gns3repository/repository.py index b7cf7ee..6873aad 100644 --- a/gns3repository/repository.py +++ b/gns3repository/repository.py @@ -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 diff --git a/test/test_config.py b/test/test_config.py index 9255d17..b13dc74 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -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() diff --git a/test/test_repository.py b/test/test_repository.py index dca2971..19e7ce9 100644 --- a/test/test_repository.py +++ b/test/test_repository.py @@ -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()