From 804a564ac24ff22cd46583fa98d8140a8b10f476 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Mon, 8 May 2006 18:34:42 -0400 Subject: Adding exception handling to remove the problem of propogating error codes all the way up the stack. Still not quite super-consistant, but getting there. Util functions still return true/false since they just ask questions, but API functions will throw errors to ensure they are being dealt with. Main CLI class needs to take advantage of this fact and become simpler. Tests are already modified to detect new exceptions with one exception :) --- cobbler/serializer.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'cobbler/serializer.py') diff --git a/cobbler/serializer.py b/cobbler/serializer.py index a63cd6e..bc46125 100644 --- a/cobbler/serializer.py +++ b/cobbler/serializer.py @@ -4,6 +4,7 @@ import syck # PySyck 0.61 or greater, not syck-python 0.55 import errno import os +import cexceptions import utils def serialize(obj): @@ -16,17 +17,17 @@ def serialize(obj): try: fd = open(filename,"w+") except IOError, ioe: - basename = os.path.basename(filename) - if not os.path.exists(basename): + dirname = os.path.dirname(filename) + if not os.path.exists(dirname): try: - os.makedirs(basename) - except: - raise CobblerException("need_perms", basename) - return False + os.makedirs(dirname) + # evidentally this doesn't throw exceptions. + except OSError, ose: + raise cexceptions.CobblerException("need_perms", os.path.dirname(dirname)) try: fd = open(filename,"w+") - except: - raise CobblerException("need_perms", filename) + except IOError, ioe3: + raise cexceptions.CobblerException("need_perms", filename) return False datastruct = obj.to_datastruct() encoded = syck.dump(datastruct) -- cgit