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,7 +37,9 @@ class Repository:
#TODO: Manage open error #TODO: Manage open error
devices_path = self._get_devices_path() devices_path = self._get_devices_path()
for file in os.listdir(devices_path): 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: with open(os.path.join(devices_path, file)) as f:
config = json.load(f) config = json.load(f)
if self._image_match(image, config): if self._image_match(image, config):

View File

@ -76,7 +76,7 @@ def empty_config(tmpdir):
def test_add_image(empty_config, linux_microcore_img): 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) config = json.load(f)
image = Image(linux_microcore_img) image = Image(linux_microcore_img)
image.version = "3.4.1" 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): 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) config = json.load(f)
image = Image(linux_microcore_img) image = Image(linux_microcore_img)
image.version = "3.4.1" 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): 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) config = json.load(f)
empty_config.add_image(config) empty_config.add_image(config)
empty_config.save() empty_config.save()

View File

@ -25,7 +25,7 @@ from gns3repository.repository import Repository
def test_detect_image(linux_microcore_img): 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) config = json.load(f)
repository = Repository() repository = Repository()