1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-28 11:18:11 +00:00

Use the FileExistsError exception.

This commit is contained in:
grossmj 2014-04-12 16:46:02 -06:00
parent a874b63e40
commit 872515fa78
6 changed files with 42 additions and 42 deletions

View File

@ -45,10 +45,11 @@ class FileUploadHandler(tornado.web.RequestHandler):
# default projects directory is "~/Documents/GNS3/images" # default projects directory is "~/Documents/GNS3/images"
self._upload_dir = os.path.expandvars(os.path.expanduser(server_config.get("upload_directory", "~/Documents/GNS3/images"))) self._upload_dir = os.path.expandvars(os.path.expanduser(server_config.get("upload_directory", "~/Documents/GNS3/images")))
if not os.path.isdir(self._upload_dir):
try: try:
os.makedirs(self._upload_dir) os.makedirs(self._upload_dir)
log.info("upload directory '{}' created".format(self._upload_dir)) log.info("upload directory '{}' created".format(self._upload_dir))
except FileExistsError:
pass
except OSError as e: except OSError as e:
log.error("could not create the upload directory {}: {}".format(self._upload_dir, e)) log.error("could not create the upload directory {}: {}".format(self._upload_dir, e))

View File

@ -205,9 +205,10 @@ class Dynamips(IModule):
if not os.access(self._dynamips, os.X_OK): if not os.access(self._dynamips, os.X_OK):
raise DynamipsError("Dynamips {} is not executable".format(self._dynamips)) raise DynamipsError("Dynamips {} is not executable".format(self._dynamips))
if not os.path.isdir(self._working_dir):
try: try:
os.makedirs(self._working_dir) os.makedirs(self._working_dir)
except FileExistsError:
pass
except OSError as e: except OSError as e:
raise DynamipsError("Could not create working directory {}".format(e)) raise DynamipsError("Could not create working directory {}".format(e))
@ -248,7 +249,7 @@ class Dynamips(IModule):
self._dynamips = request.pop("path") self._dynamips = request.pop("path")
if "working_dir" in request: if "working_dir" in request:
self._working_dir = request.pop("working_dir") self._working_dir = os.path.join(request.pop("working_dir"), "dynamips")
log.info("this server is local") log.info("this server is local")
else: else:
self._remote_server = True self._remote_server = True
@ -407,9 +408,10 @@ class Dynamips(IModule):
config = "!\n" + config.replace("\r", "") config = "!\n" + config.replace("\r", "")
config = config.replace('%h', router.name) config = config.replace('%h', router.name)
config_dir = os.path.join(router.hypervisor.working_dir, "configs") config_dir = os.path.join(router.hypervisor.working_dir, "configs")
if not os.path.isdir(config_dir):
try: try:
os.makedirs(config_dir) os.makedirs(config_dir)
except FileExistsError:
pass
except OSError as e: except OSError as e:
raise DynamipsError("Could not create configs directory: {}".format(e)) raise DynamipsError("Could not create configs directory: {}".format(e))
config_path = os.path.join(config_dir, config_filename) config_path = os.path.join(config_dir, config_filename)

View File

@ -461,13 +461,6 @@ class HypervisorManager(object):
""" """
port = self.allocate_tcp_port() port = self.allocate_tcp_port()
# working_dir = os.path.join(self._working_dir, "instance-{}".format(port))
# if not os.path.isdir(working_dir):
# try:
# os.makedirs(working_dir)
# except OSError as e:
# raise DynamipsError("{}".format(e))
hypervisor = Hypervisor(self._path, hypervisor = Hypervisor(self._path,
self._working_dir, self._working_dir,
self._host, self._host,

View File

@ -201,8 +201,9 @@ class IOU(IModule):
log.info("iouyap path set to {}".format(self._iouyap)) log.info("iouyap path set to {}".format(self._iouyap))
if "working_dir" in request: if "working_dir" in request:
if self._working_dir != request["working_dir"]: new_working_dir = os.path.join(request["working_dir"], "iou")
self._working_dir = request["working_dir"] if self._working_dir != new_working_dir:
self._working_dir = new_working_dir
log.info("this server is local with working directory path to {}".format(self._working_dir)) log.info("this server is local with working directory path to {}".format(self._working_dir))
for iou_id in self._iou_instances: for iou_id in self._iou_instances:
iou_instance = self._iou_instances[iou_id] iou_instance = self._iou_instances[iou_id]
@ -246,9 +247,10 @@ class IOU(IModule):
iou_path = request["path"] iou_path = request["path"]
try: try:
if not os.path.isdir(self._working_dir):
try: try:
os.makedirs(self._working_dir) os.makedirs(self._working_dir)
except FileExistsError:
pass
except OSError as e: except OSError as e:
raise IOUError("Could not create working directory {}".format(e)) raise IOUError("Could not create working directory {}".format(e))

View File

@ -246,9 +246,10 @@ class IOUDevice(object):
# create our own working directory # create our own working directory
working_dir = os.path.join(working_dir, "device-{}".format(self._id)) working_dir = os.path.join(working_dir, "device-{}".format(self._id))
if not os.path.isdir(working_dir):
try: try:
os.makedirs(working_dir) os.makedirs(working_dir)
except FileExistsError:
pass
except OSError as e: except OSError as e:
raise IOUError("Could not create working directory {}: {}".format(working_dir, e)) raise IOUError("Could not create working directory {}: {}".format(working_dir, e))

View File

@ -78,10 +78,11 @@ class Server(object):
self._projects_dir = os.path.expandvars(os.path.expanduser(server_config.get("projects_directory", "~/Documents/GNS3/projects"))) 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()) self._temp_dir = server_config.get("temporary_directory", tempfile.gettempdir())
if not os.path.isdir(self._projects_dir):
try: try:
os.makedirs(self._projects_dir) os.makedirs(self._projects_dir)
log.info("projects directory '{}' created".format(self._projects_dir)) log.info("projects directory '{}' created".format(self._projects_dir))
except FileExistsError:
pass
except OSError as e: except OSError as e:
log.error("could not create the projects directory {}: {}".format(self._projects_dir, e)) log.error("could not create the projects directory {}: {}".format(self._projects_dir, e))