More specific path checks (file vs directory).

pull/11/head
grossmj 10 years ago
parent 8020c2e99c
commit 96231e3f7f

@ -45,7 +45,7 @@ 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.exists(self._upload_dir): 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))

@ -198,14 +198,14 @@ class Dynamips(IModule):
""" """
# check if Dynamips path exists # 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)) raise DynamipsError("Dynamips executable {} doesn't exist".format(self._dynamips))
# check if Dynamips is executable # check if Dynamips is executable
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.exists(self._working_dir): if not os.path.isdir(self._working_dir):
try: try:
os.makedirs(self._working_dir) os.makedirs(self._working_dir)
except OSError as e: except OSError as e:
@ -407,7 +407,7 @@ 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.exists(config_dir): if not os.path.isdir(config_dir):
try: try:
os.makedirs(config_dir) os.makedirs(config_dir)
except OSError as e: except OSError as e:

@ -455,7 +455,7 @@ class HypervisorManager(object):
port = self.allocate_tcp_port() port = self.allocate_tcp_port()
# working_dir = os.path.join(self._working_dir, "instance-{}".format(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: # try:
# os.makedirs(working_dir) # os.makedirs(working_dir)
# except OSError as e: # except OSError as e:

@ -54,9 +54,9 @@ class IOU(IModule):
config = Config.instance() config = Config.instance()
iou_config = config.get_section_config(name.upper()) iou_config = config.get_section_config(name.upper())
self._iouyap = iou_config.get("iouyap") 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") 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 self._iouyap = iouyap_in_cwd
else: else:
# look for iouyap if none is defined or accessible # 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_console_port = self._console_start_port_range
self._current_udp_port = self._udp_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: try:
log.info("deleting iourc file {}".format(self._iourc)) log.info("deleting iourc file {}".format(self._iourc))
os.remove(self._iourc) os.remove(self._iourc)
@ -246,7 +246,7 @@ class IOU(IModule):
iou_path = request["path"] iou_path = request["path"]
try: try:
if not os.path.exists(self._working_dir): if not os.path.isdir(self._working_dir):
try: try:
os.makedirs(self._working_dir) os.makedirs(self._working_dir)
except OSError as e: except OSError as e:

@ -246,7 +246,7 @@ 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.exists(working_dir): if not os.path.isdir(working_dir):
try: try:
os.makedirs(working_dir) os.makedirs(working_dir)
except OSError as e: except OSError as e:
@ -413,13 +413,13 @@ class IOUDevice(object):
if not self.is_running(): 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)) 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") 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") raise IOUError("iouyap is necessary to start IOU")
self._create_netmap_config() self._create_netmap_config()

@ -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._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.exists(self._projects_dir): 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))

@ -23,5 +23,5 @@
# or negative for a release candidate or beta (after the base version # or negative for a release candidate or beta (after the base version
# number has been incremented) # number has been incremented)
__version__ = "1.0a2.dev2" __version__ = "1.0a2.dev3"
__version_info__ = (1, 0, 0, -99) __version_info__ = (1, 0, 0, -99)

@ -25,6 +25,6 @@ def image(request):
cwd = os.path.dirname(os.path.abspath(__file__)) cwd = os.path.dirname(os.path.abspath(__file__))
image_path = os.path.join(cwd, "c3725.image") 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 None
return image_path return image_path

Loading…
Cancel
Save