From cafdb2522bcfd3f098e5d816b37690b93182b652 Mon Sep 17 00:00:00 2001 From: grossmj Date: Sun, 29 Sep 2024 19:42:06 +0700 Subject: [PATCH] Add / update docstrings --- gns3server/controller/project.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/gns3server/controller/project.py b/gns3server/controller/project.py index 44099d9e..3c5c5229 100644 --- a/gns3server/controller/project.py +++ b/gns3server/controller/project.py @@ -1040,14 +1040,16 @@ class Project: """ Duplicate a project - It's the save as feature of the 1.X. It's implemented on top of the - export / import features. It will generate a gns3p and reimport it. - It's a little slower but we have only one implementation to maintain. + Implemented on top of the export / import features. It will generate a gns3p and reimport it. + + NEW: fast duplication is used if possible (when there are no remote computes). + If not, the project is exported and reimported as explained above. :param name: Name of the new project. A new one will be generated in case of conflicts :param location: Parent directory of the new project :param reset_mac_addresses: Reset MAC addresses for the new project """ + # If the project was not open we open it temporary previous_status = self._status if self._status == "closed": @@ -1254,10 +1256,20 @@ class Project: return "".format(self._name, self._id) async def _fast_duplication(self, name=None, location=None, reset_mac_addresses=True): + """ + Fast duplication of a project. + + Copy the project files directly rather than in an import-export fashion. + + :param name: Name of the new project. A new one will be generated in case of conflicts + :param location: Parent directory of the new project + :param reset_mac_addresses: Reset MAC addresses for the new project + """ + # remote replication is not supported with remote computes for compute in self.computes: if compute.id != "local": - log.warning("Fast duplication is not support with remote compute: '{}'".format(compute.id)) + log.warning("Fast duplication is not supported with remote compute: '{}'".format(compute.id)) return None # work dir p_work = pathlib.Path(location or self.path).parent.absolute() @@ -1308,4 +1320,4 @@ class Project: os.remove(new_project_path.joinpath('{}.gns3'.format(self.name))) project = await self.controller.load_project(dot_gns3_path, load=False) log.info("Project '{}' fast duplicated in {:.4f} seconds".format(project.name, time.time() - t0)) - return project \ No newline at end of file + return project