Fix small errors like unhandled exceptions etc.

This commit is contained in:
grossmj committed 2018-09-11 15:06:01 +02:00
1 parent 0aa9ab53d1
commit 17d657c919
12 files changed
+37 -26

No files matched your search

+2 -4
View File
@@ -66,9 +66,7 @@ class Controller:
def load_appliances(self):
self._appliance_templates = {}
for directory, builtin in (
(get_resource('appliances'), True,), (self.appliances_path(), False,)
):
for directory, builtin in ((get_resource('appliances'), True,), (self.appliances_path(), False,)):
if directory and os.path.isdir(directory):
for file in os.listdir(directory):
if not file.endswith('.gns3a') and not file.endswith('.gns3appliance'):
@@ -200,7 +198,7 @@ class Controller:
for c in computes:
try:
yield from self.add_compute(**c)
except (aiohttp.web.HTTPConflict, KeyError):
except (aiohttp.web.HTTPError, KeyError):
pass # Skip not available servers at loading
yield from self.load_projects()
try:
+1 -1
View File
@@ -175,7 +175,7 @@ class Node:
if not os.path.isabs(path):
path = os.path.join(self.project.controller.configs_path(), path)
try:
with open(path) as f:
with open(path, encoding="utf-8") as f:
return f.read()
except OSError:
return None
+1 -1
View File
@@ -843,7 +843,7 @@ class Project:
link = yield from self.add_link(link_id=link_data["link_id"])
if "filters" in link_data:
yield from link.update_filters(link_data["filters"])
for node_link in link_data["nodes"]:
for node_link in link_data.get("nodes", []):
node = self.get_node(node_link["node_id"])
port = node.get_port(node_link["adapter_number"], node_link["port_number"])
if port is None:
+14 -5
View File
@@ -22,6 +22,9 @@ from ..utils.get_resource import get_resource
from ..utils.picture import get_size
from ..config import Config
import logging
log = logging.getLogger(__name__)
class Symbols:
"""
@@ -72,19 +75,25 @@ class Symbols:
def symbols_path(self):
directory = os.path.expanduser(Config.instance().get_section_config("Server").get("symbols_path", "~/GNS3/symbols"))
if directory:
os.makedirs(directory, exist_ok=True)
try:
os.makedirs(directory, exist_ok=True)
except OSError as e:
log.error("Could not create symbol directory '{}': {}".format(directory, e))
return None
return directory
def get_path(self, symbol_id):
try:
return self._symbols_path[symbol_id]
# Symbol not found refresh cache
# Symbol not found, let's refresh the cache
except KeyError:
self.list()
try:
self.list()
return self._symbols_path[symbol_id]
except KeyError:
return self._symbols_path[":/symbols/computer.svg"]
except (OSError, KeyError):
log.warning("Could not retrieve symbol '{}'".format(symbol_id))
symbols_path = self._symbols_path
return symbols_path[":/symbols/computer.svg"]
def get_size(self, symbol_id):
try:
+4 -4
View File
@@ -409,7 +409,7 @@ def _convert_1_3_later(topo, topo_path):
symbol = old_node.get("symbol", ":/symbols/computer.svg")
old_node["ports"] = _create_cloud(node, old_node, symbol)
else:
raise NotImplementedError("Conversion of {} is not supported".format(old_node["type"]))
raise aiohttp.web.HTTPConflict(text="Conversion of {} is not supported".format(old_node["type"]))
for prop in old_node.get("properties", {}):
if prop not in ["console", "name", "console_type", "console_host", "use_ubridge"]:
@@ -608,13 +608,13 @@ def _create_cloud(node, old_node, icon):
elif old_port["name"].startswith("nio_nat"):
continue
else:
raise NotImplementedError("The conversion of cloud with {} is not supported".format(old_port["name"]))
raise aiohttp.web.HTTPConflict(text="The conversion of cloud with {} is not supported".format(old_port["name"]))
if port_type == "udp":
try:
_, lport, rhost, rport = old_port["name"].split(":")
except ValueError:
raise NotImplementedError("UDP tunnel using IPV6 is not supported in cloud")
raise aiohttp.web.HTTPConflict(text="UDP tunnel using IPV6 is not supported in cloud")
port = {
"name": "UDP tunnel {}".format(len(ports) + 1),
"port_number": len(ports) + 1,
@@ -645,7 +645,7 @@ def _convert_snapshots(topo_dir):
old_snapshots_dir = os.path.join(topo_dir, "project-files", "snapshots")
if os.path.exists(old_snapshots_dir):
new_snapshots_dir = os.path.join(topo_dir, "snapshots")
os.makedirs(new_snapshots_dir)
os.makedirs(new_snapshots_dir, exist_ok=True)
for snapshot in os.listdir(old_snapshots_dir):
snapshot_dir = os.path.join(old_snapshots_dir, snapshot)