From 96231e3f7f758d810d74f9f6e0b71e627ff3dcbc Mon Sep 17 00:00:00 2001 From: grossmj Date: Fri, 11 Apr 2014 14:48:30 -0600 Subject: [PATCH] More specific path checks (file vs directory). --- gns3server/handlers/file_upload_handler.py | 2 +- gns3server/modules/dynamips/__init__.py | 6 +++--- gns3server/modules/dynamips/hypervisor_manager.py | 2 +- gns3server/modules/iou/__init__.py | 8 ++++---- gns3server/modules/iou/iou_device.py | 8 ++++---- gns3server/server.py | 2 +- gns3server/version.py | 2 +- tests/dynamips/conftest.py | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/gns3server/handlers/file_upload_handler.py b/gns3server/handlers/file_upload_handler.py index ab9100e2..93f5b031 100644 --- a/gns3server/handlers/file_upload_handler.py +++ b/gns3server/handlers/file_upload_handler.py @@ -45,7 +45,7 @@ class FileUploadHandler(tornado.web.RequestHandler): # default projects directory is "~/Documents/GNS3/images" self._upload_dir = os.path.expandvars(os.path.expanduser(server_config.get("upload_directory", "~/Documents/GNS3/images"))) - if not os.path.exists(self._upload_dir): + if not os.path.isdir(self._upload_dir): try: os.makedirs(self._upload_dir) log.info("upload directory '{}' created".format(self._upload_dir)) diff --git a/gns3server/modules/dynamips/__init__.py b/gns3server/modules/dynamips/__init__.py index aead3a3a..6ca93bed 100644 --- a/gns3server/modules/dynamips/__init__.py +++ b/gns3server/modules/dynamips/__init__.py @@ -198,14 +198,14 @@ class Dynamips(IModule): """ # check if Dynamips path exists - if not os.path.exists(self._dynamips): + if not os.path.isfile(self._dynamips): raise DynamipsError("Dynamips executable {} doesn't exist".format(self._dynamips)) # check if Dynamips is executable if not os.access(self._dynamips, os.X_OK): raise DynamipsError("Dynamips {} is not executable".format(self._dynamips)) - if not os.path.exists(self._working_dir): + if not os.path.isdir(self._working_dir): try: os.makedirs(self._working_dir) except OSError as e: @@ -407,7 +407,7 @@ class Dynamips(IModule): config = "!\n" + config.replace("\r", "") config = config.replace('%h', router.name) config_dir = os.path.join(router.hypervisor.working_dir, "configs") - if not os.path.exists(config_dir): + if not os.path.isdir(config_dir): try: os.makedirs(config_dir) except OSError as e: diff --git a/gns3server/modules/dynamips/hypervisor_manager.py b/gns3server/modules/dynamips/hypervisor_manager.py index 50369358..6e78700d 100644 --- a/gns3server/modules/dynamips/hypervisor_manager.py +++ b/gns3server/modules/dynamips/hypervisor_manager.py @@ -455,7 +455,7 @@ class HypervisorManager(object): port = self.allocate_tcp_port() # working_dir = os.path.join(self._working_dir, "instance-{}".format(port)) -# if not os.path.exists(working_dir): +# if not os.path.isdir(working_dir): # try: # os.makedirs(working_dir) # except OSError as e: diff --git a/gns3server/modules/iou/__init__.py b/gns3server/modules/iou/__init__.py index 9c398c10..a3afbbb9 100644 --- a/gns3server/modules/iou/__init__.py +++ b/gns3server/modules/iou/__init__.py @@ -54,9 +54,9 @@ class IOU(IModule): config = Config.instance() iou_config = config.get_section_config(name.upper()) self._iouyap = iou_config.get("iouyap") - if not self._iouyap or not os.path.exists(self._iouyap): + if not self._iouyap or not os.path.isfile(self._iouyap): iouyap_in_cwd = os.path.join(os.getcwd(), "iouyap") - if os.path.exists(iouyap_in_cwd): + if os.path.isfile(iouyap_in_cwd): self._iouyap = iouyap_in_cwd else: # look for iouyap if none is defined or accessible @@ -153,7 +153,7 @@ class IOU(IModule): self._current_console_port = self._console_start_port_range self._current_udp_port = self._udp_start_port_range - if self._iourc and os.path.exists(self._iourc): + if self._iourc and os.path.isfile(self._iourc): try: log.info("deleting iourc file {}".format(self._iourc)) os.remove(self._iourc) @@ -246,7 +246,7 @@ class IOU(IModule): iou_path = request["path"] try: - if not os.path.exists(self._working_dir): + if not os.path.isdir(self._working_dir): try: os.makedirs(self._working_dir) except OSError as e: diff --git a/gns3server/modules/iou/iou_device.py b/gns3server/modules/iou/iou_device.py index 14c64628..31cb98e9 100644 --- a/gns3server/modules/iou/iou_device.py +++ b/gns3server/modules/iou/iou_device.py @@ -246,7 +246,7 @@ class IOUDevice(object): # create our own working directory working_dir = os.path.join(working_dir, "device-{}".format(self._id)) - if not os.path.exists(working_dir): + if not os.path.isdir(working_dir): try: os.makedirs(working_dir) except OSError as e: @@ -413,13 +413,13 @@ class IOUDevice(object): if not self.is_running(): - if not os.path.exists(self._path): + if not os.path.isfile(self._path): raise IOUError("IOU '{}' is not accessible".format(self._path)) - if not self._iourc or not os.path.exists(self._iourc): + if not self._iourc or not os.path.isfile(self._iourc): raise IOUError("A iourc file is necessary to start IOU") - if not self._iouyap or not os.path.exists(self._iouyap): + if not self._iouyap or not os.path.isfile(self._iouyap): raise IOUError("iouyap is necessary to start IOU") self._create_netmap_config() diff --git a/gns3server/server.py b/gns3server/server.py index 3759c02f..baa85542 100644 --- a/gns3server/server.py +++ b/gns3server/server.py @@ -77,7 +77,7 @@ class Server(object): self._projects_dir = os.path.expandvars(os.path.expanduser(server_config.get("projects_directory", "~/Documents/GNS3/projects"))) self._temp_dir = server_config.get("temporary_directory", tempfile.gettempdir()) - if not os.path.exists(self._projects_dir): + if not os.path.isdir(self._projects_dir): try: os.makedirs(self._projects_dir) log.info("projects directory '{}' created".format(self._projects_dir)) diff --git a/gns3server/version.py b/gns3server/version.py index ab96612e..2a08f611 100644 --- a/gns3server/version.py +++ b/gns3server/version.py @@ -23,5 +23,5 @@ # or negative for a release candidate or beta (after the base version # number has been incremented) -__version__ = "1.0a2.dev2" +__version__ = "1.0a2.dev3" __version_info__ = (1, 0, 0, -99) diff --git a/tests/dynamips/conftest.py b/tests/dynamips/conftest.py index ff4e2225..fce9f54b 100644 --- a/tests/dynamips/conftest.py +++ b/tests/dynamips/conftest.py @@ -25,6 +25,6 @@ def image(request): cwd = os.path.dirname(os.path.abspath(__file__)) image_path = os.path.join(cwd, "c3725.image") - if not os.path.exists(image_path): + if not os.path.isfile(image_path): return None return image_path