summaryrefslogtreecommitdiffstats
path: root/cobbler/serializer.py
diff options
context:
space:
mode:
authorMichael DeHaan <mdehaan@redhat.com>2006-05-08 18:34:42 -0400
committerJim Meyering <jim@meyering.net>2006-05-08 18:34:42 -0400
commit804a564ac24ff22cd46583fa98d8140a8b10f476 (patch)
treefadba99af49b4da97be1a5b7ab7af42cb780db39 /cobbler/serializer.py
parentd4f71b4318fedf374844030095c6c8dd544f0e92 (diff)
downloadthird_party-cobbler-804a564ac24ff22cd46583fa98d8140a8b10f476.tar.gz
third_party-cobbler-804a564ac24ff22cd46583fa98d8140a8b10f476.tar.xz
third_party-cobbler-804a564ac24ff22cd46583fa98d8140a8b10f476.zip
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 :)
Diffstat (limited to 'cobbler/serializer.py')
-rw-r--r--cobbler/serializer.py17
1 files changed, 9 insertions, 8 deletions
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)