From be5d543f20ee24a6c4ef4e7082285691fb194c6b Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Tue, 27 Sep 2016 17:05:03 +0200 Subject: [PATCH] Fix some bugs on windows --- gns3server/controller/topology.py | 1 - gns3server/utils/__init__.py | 8 ++++---- tests/compute/test_manager.py | 2 +- tests/test_topologies.py | 7 ++++++- tests/test_utils.py | 4 +++- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/gns3server/controller/topology.py b/gns3server/controller/topology.py index dfe537c0..982418cb 100644 --- a/gns3server/controller/topology.py +++ b/gns3server/controller/topology.py @@ -472,7 +472,6 @@ def _convert_snapshots(topo_dir): for root, dirs, files in os.walk(snapshot_dir): for file in files: myzip.write(os.path.join(root, file), os.path.relpath(os.path.join(root, file), snapshot_dir), compress_type=zipfile.ZIP_DEFLATED) - shutil.copy(snapshot_arc, "/tmp/test.zip") shutil.rmtree(old_snapshots_dir) diff --git a/gns3server/utils/__init__.py b/gns3server/utils/__init__.py index 06b56d0d..e8e0a297 100644 --- a/gns3server/utils/__init__.py +++ b/gns3server/utils/__init__.py @@ -17,17 +17,17 @@ import re +import os import textwrap -import posixpath - +import pathlib def force_unix_path(path): """ :param path: Path to convert """ - path = path.replace("\\", "/") - return posixpath.normpath(path) + p = pathlib.Path(os.path.normpath(path)) + return p.as_posix() def macaddress_to_int(mac_address): diff --git a/tests/compute/test_manager.py b/tests/compute/test_manager.py index 5121ba10..eb88aa7e 100644 --- a/tests/compute/test_manager.py +++ b/tests/compute/test_manager.py @@ -136,7 +136,7 @@ def test_get_abs_image_additional_image_paths(qemu, tmpdir): with patch("gns3server.config.Config.get_section_config", return_value={ "images_path": str(tmpdir / "images1"), - "additional_images_path": "/tmp/null24564:{}".format(tmpdir / "images2"), + "additional_images_path": "/tmp/null24564:{}".format(str(tmpdir / "images2")), "local": False}): assert qemu.get_abs_image_path("test1.bin") == path1 assert qemu.get_abs_image_path("test2.bin") == path2 diff --git a/tests/test_topologies.py b/tests/test_topologies.py index 7a1186eb..b3ffebbc 100644 --- a/tests/test_topologies.py +++ b/tests/test_topologies.py @@ -77,8 +77,13 @@ def test_convert(directory, tmpdir): file_path = os.path.join(work_directory, directory, file) assert os.path.exists(file_path), "{} is missing".format(os.path.join(directory, file)) + # For gns3project we check if size are not too much differents + if file_path.endswith(".gns3project"): + size = os.stat(file_path).st_size + other_size = os.stat(os.path.join(os.path.join(root, file))).st_size + assert size in range(other_size - 100, other_size + 100), "File {} is different".format(os.path.join(directory, file)) # For non .gns3 file we check if the file are the same - if not file_path.endswith(".gns3"): + elif not file_path.endswith(".gns3"): assert os.stat(file_path).st_size == os.stat(os.path.join(os.path.join(root, file))).st_size, "File {} is different".format(os.path.join(directory, file)) # Check if we don't have unexpected file in work directory diff --git a/tests/test_utils.py b/tests/test_utils.py index eb25aeb4..c188c044 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . - +import sys from gns3server.utils import * @@ -23,6 +23,8 @@ def test_force_unix_path(): assert force_unix_path("a/b") == "a/b" assert force_unix_path("a\\b") == "a/b" assert force_unix_path("a\\b\\..\\c") == "a/c" + if sys.platform.startswith("win"): + assert force_unix_path("C:\Temp") == "C:/Temp" def test_macaddress_to_int():