1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-01 04:38:12 +00:00

Support filename for project in the controller

This commit is contained in:
Julien Duponchelle 2016-06-16 16:57:54 +02:00
parent 411ca56b94
commit c66ef9d218
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
4 changed files with 17 additions and 14 deletions

View File

@ -217,9 +217,10 @@ class Controller:
topo_data.pop("revision")
topo_data.pop("type")
project = yield from self.add_project(path=os.path.dirname(path), status="closed", **topo_data)
project = yield from self.add_project(path=os.path.dirname(path), status="closed", filename=os.path.basename(path), **topo_data)
if load:
yield from project.open()
return project
@property
def projects(self):

View File

@ -43,7 +43,7 @@ class Project:
:param status: Status of the project (opened / closed)
"""
def __init__(self, name=None, project_id=None, path=None, controller=None, status="opened"):
def __init__(self, name=None, project_id=None, path=None, controller=None, status="opened", filename=None):
self._controller = controller
self._name = name
@ -60,6 +60,13 @@ class Project:
if path is None:
path = os.path.join(get_default_project_directory(), self._id)
self.path = path
if filename is None and name is None:
self._filename = "project.gns3"
elif filename is not None:
self._filename = filename
else:
self._filename = self.name + ".gns3"
self.reset()
def reset(self):
@ -322,14 +329,8 @@ class Project:
raise aiohttp.web.HTTPInternalServerError(text="Could not create project directory: {}".format(e))
return path
def _filename(self):
if self.name is None:
return "untitled.gns3"
else:
return self.name + ".gns3"
def _topology_file(self):
return os.path.join(self.path, self._filename())
return os.path.join(self.path, self._filename)
@asyncio.coroutine
def open(self):
@ -373,6 +374,6 @@ class Project:
"name": self._name,
"project_id": self._id,
"path": self._path,
"filename": self._filename(),
"filename": self._filename,
"status": self._status
}

View File

@ -188,7 +188,7 @@ def test_close(controller, async_run):
def test_load_project(controller, async_run, tmpdir):
data = {
"name": "Test",
"name": "Experience",
"project_id": "c8d07a5a-134f-4c3f-8599-e35eac85eb17",
"revision": 5,
"type": "topology",
@ -242,11 +242,12 @@ def test_load_project(controller, async_run, tmpdir):
controller._computes["my_remote"] = MagicMock()
with asyncio_patch("gns3server.controller.node.Node.create") as mock_node_create:
async_run(controller.load_project(str(tmpdir / "test.gns3")))
project = async_run(controller.load_project(str(tmpdir / "test.gns3")))
assert project._topology_file() == str(tmpdir / "test.gns3")
controller.add_compute.assert_called_with(compute_id='my_remote', host='127.0.0.1', name='My remote', port=3080, protocol='http')
project = controller.get_project('c8d07a5a-134f-4c3f-8599-e35eac85eb17')
assert project.name == "Test"
assert project.name == "Experience"
assert project.path == str(tmpdir)
link = project.get_link("c44331d2-2da4-490d-9aad-7f5c126ae271")
assert len(link.nodes) == 2

View File

@ -43,7 +43,7 @@ def test_affect_uuid():
def test_json(tmpdir):
p = Project()
assert p.__json__() == {"name": p.name, "project_id": p.id, "path": p.path, "status": "opened", "filename": "untitled.gns3"}
assert p.__json__() == {"name": p.name, "project_id": p.id, "path": p.path, "status": "opened", "filename": "project.gns3"}
def test_path(tmpdir):