Rename all EnvironmentError to OSError.

Change version number to 1.0a2-dev1.
Check only on Python >= 3.3.
pull/11/head
grossmj 10 years ago
parent 20597e29df
commit f4dd096a8b

@ -49,7 +49,7 @@ class FileUploadHandler(tornado.web.RequestHandler):
try:
os.makedirs(self._upload_dir)
log.info("upload directory '{}' created".format(self._upload_dir))
except EnvironmentError as e:
except OSError as e:
log.error("could not create the upload directory {}: {}".format(self._upload_dir, e))
tornado.websocket.WebSocketHandler.__init__(self, application, request)

@ -16,6 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import datetime
import sys
import multiprocessing
@ -44,12 +45,15 @@ def main():
print("GNS3 server version {}".format(__version__))
print("Copyright (c) 2007-{} GNS3 Technologies Inc.".format(current_year))
# we only support Python 2 version >= 2.7 and Python 3 version >= 3.3
if sys.version_info < (2, 7):
raise RuntimeError("Python 2.7 or higher is required")
elif sys.version_info[0] == 3 and sys.version_info < (3, 3):
# we only support Python 3 version >= 3.3
if sys.version_info < (3, 3):
raise RuntimeError("Python 3.3 or higher is required")
print("Running with Python {major}.{minor}.{micro} and has PID {pid}".format(major=sys.version_info[0],
minor=sys.version_info[1],
micro=sys.version_info[2],
pid=os.getpid()))
try:
tornado.options.parse_command_line()
except (tornado.options.Error, ValueError):

@ -20,6 +20,7 @@ Base class (interface) for modules
"""
import sys
import traceback
import gns3server.jsonrpc as jsonrpc
import multiprocessing
import zmq
@ -230,7 +231,12 @@ class IModule(multiprocessing.Process):
self.modules[self.name][destination](self, params)
except Exception as e:
log.error("uncaught exception {type}".format(type=type(e)), exc_info=1)
self.send_custom_error("uncaught exception {type}: {string}".format(type=type(e), string=str(e)))
exc_type, exc_value, exc_tb = sys.exc_info()
lines = traceback.format_exception(exc_type, exc_value, exc_tb)
tb = "\n" . join(lines)
self.send_custom_error("uncaught exception {type}: {string}\n{tb}".format(type=type(e),
string=str(e),
tb=tb))
def destinations(self):
"""

@ -208,7 +208,7 @@ class Dynamips(IModule):
if not os.path.exists(self._working_dir):
try:
os.makedirs(self._working_dir)
except EnvironmentError as e:
except OSError as e:
raise DynamipsError("Could not create working directory {}".format(e))
# check if the working directory is writable
@ -410,14 +410,14 @@ class Dynamips(IModule):
if not os.path.exists(config_dir):
try:
os.makedirs(config_dir)
except EnvironmentError as e:
except OSError as e:
raise DynamipsError("Could not create configs directory: {}".format(e))
config_path = os.path.join(config_dir, config_filename)
try:
with open(config_path, "w") as f:
log.info("saving startup-config to {}".format(config_path))
f.write(config)
except EnvironmentError as e:
except OSError as e:
raise DynamipsError("Could not save the configuration {}: {}".format(config_path, e))
return "configs" + os.sep + os.path.basename(config_path)

@ -467,7 +467,7 @@ class VM(object):
with open(config_path, "w") as f:
log.info("saving startup-config to {}".format(router.startup_config))
f.write(config)
except EnvironmentError as e:
except OSError as e:
raise DynamipsError("Could not save the startup configuration {}: {}".format(config_path, e))
if private_config_base64:
@ -478,7 +478,7 @@ class VM(object):
with open(config_path, "w") as f:
log.info("saving private-config to {}".format(router.private_config))
f.write(config)
except EnvironmentError as e:
except OSError as e:
raise DynamipsError("Could not save the private configuration {}: {}".format(config_path, e))
except DynamipsError as e:

@ -211,7 +211,7 @@ class Hypervisor(DynamipsHypervisor):
cwd=self._working_dir)
log.info("Dynamips started PID={}".format(self._process.pid))
self._started = True
except EnvironmentError as e:
except OSError as e:
log.error("could not start Dynamips: {}".format(e))
raise DynamipsError("could not start Dynamips: {}".format(e))
@ -247,7 +247,7 @@ class Hypervisor(DynamipsHypervisor):
try:
with open(self._stdout_file) as file:
output = file.read()
except EnvironmentError as e:
except OSError as e:
log.warn("could not read {}: {}".format(self._stdout_file, e))
return output

@ -456,7 +456,7 @@ class HypervisorManager(object):
# if not os.path.exists(working_dir):
# try:
# os.makedirs(working_dir)
# except EnvironmentError as e:
# except OSError as e:
# raise DynamipsError("{}".format(e))
hypervisor = Hypervisor(self._path,

@ -87,8 +87,8 @@ class IOU(IModule):
self._iourc = ""
# check every 5 seconds
self._iou_callback = self.add_periodic_callback(self._check_iou_is_alive, 5000)
self._iou_callback.start()
#self._iou_callback = self.add_periodic_callback(self._check_iou_is_alive, 5000)
#self._iou_callback.start()
def stop(self):
"""
@ -154,7 +154,7 @@ class IOU(IModule):
try:
log.info("deleting iourc file {}".format(self._iourc))
os.remove(self._iourc)
except EnvironmentError as e:
except OSError as e:
log.warn("could not delete iourc file {}: {}".format(self._iourc, e))
log.info("IOU module has been reset")
@ -189,7 +189,7 @@ class IOU(IModule):
log.info("saving iourc file content to {}".format(f.name))
f.write(base64iourc)
self._iourc = f.name
except EnvironmentError as e:
except OSError as e:
raise IOUError("Could not save iourc file to {}: {}".format(f.name, e))
if "iouyap" in request and request["iouyap"]:
@ -244,7 +244,7 @@ class IOU(IModule):
if not os.path.exists(self._working_dir):
try:
os.makedirs(self._working_dir)
except EnvironmentError as e:
except OSError as e:
raise IOUError("Could not create working directory {}".format(e))
iou_instance = IOUDevice(iou_path, self._working_dir, host=self._default_host, name=name)
@ -333,7 +333,7 @@ class IOU(IModule):
with open(config_path, "w") as f:
log.info("saving startup-config to {}".format(config_path))
f.write(config)
except EnvironmentError as e:
except OSError as e:
raise IOUError("Could not save the configuration {}: {}".format(config_path, e))
request["startup_config"] = os.path.basename(config_path)
if "startup_config" in request:
@ -544,7 +544,7 @@ class IOU(IModule):
IFF_NO_PI = 0x1000
try:
tun = os.open("/dev/net/tun", os.O_RDWR)
except EnvironmentError as e:
except OSError as e:
raise IOUError("Could not open /dev/net/tun: {}".format(e))
ifr = struct.pack("16sH", tap_device.encode("utf-8"), IFF_TAP | IFF_NO_PI)
try:

@ -249,7 +249,7 @@ class IOUDevice(object):
if not os.path.exists(working_dir):
try:
os.makedirs(working_dir)
except EnvironmentError as e:
except OSError as e:
raise IOUError("Could not create working directory {}: {}".format(working_dir, e))
self._working_dir = working_dir
@ -348,7 +348,7 @@ class IOUDevice(object):
config.write(config_file)
log.info("IOU {name} [id={id}]: iouyap.ini updated".format(name=self._name,
id=self._id))
except EnvironmentError as e:
except OSError as e:
raise IOUError("Could not create {}: {}".format(iouyap_ini, e))
def _create_netmap_config(self):
@ -367,7 +367,7 @@ class IOUDevice(object):
iou_id=self._id))
log.info("IOU {name} [id={id}]: NETMAP file created".format(name=self._name,
id=self._id))
except EnvironmentError as e:
except OSError as e:
raise IOUError("Could not create {}: {}".format(netmap_path, e))
def _start_ioucon(self):
@ -401,7 +401,7 @@ class IOUDevice(object):
cwd=self._working_dir)
log.info("iouyap started PID={}".format(self._iouyap_process.pid))
except EnvironmentError as e:
except OSError as e:
log.error("could not start iouyap: {}".format(e))
raise IOUError("Could not start iouyap: {}".format(e))
@ -434,7 +434,7 @@ class IOUDevice(object):
env=env)
log.info("IOU instance {} started PID={}".format(self._id, self._process.pid))
self._started = True
except EnvironmentError as e:
except OSError as e:
log.error("could not start IOU: {}".format(e))
raise IOUError("could not start IOU: {}".format(e))
@ -493,7 +493,7 @@ class IOUDevice(object):
try:
with open(self._iou_stdout_file) as file:
output = file.read()
except EnvironmentError as e:
except OSError as e:
log.warn("could not read {}: {}".format(self._iou_stdout_file, e))
return output
@ -508,7 +508,7 @@ class IOUDevice(object):
try:
with open(self._iouyap_stdout_file) as file:
output = file.read()
except EnvironmentError as e:
except OSError as e:
log.warn("could not read {}: {}".format(self._iouyap_stdout_file, e))
return output

@ -78,7 +78,7 @@ class Server(object):
try:
os.makedirs(self._projects_dir)
log.info("projects directory '{}' created".format(self._projects_dir))
except EnvironmentError as e:
except OSError as e:
log.error("could not create the projects directory {}: {}".format(self._projects_dir, e))
def load_modules(self):

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

Loading…
Cancel
Save