summaryrefslogtreecommitdiffstats
path: root/cobbler/serializer.py
diff options
context:
space:
mode:
authorMichael DeHaan <mdehaan@mdehaan.rdu.redhat.com>2007-06-13 18:03:33 -0400
committerMichael DeHaan <mdehaan@mdehaan.rdu.redhat.com>2007-06-13 18:03:33 -0400
commit5eaa46b5af9e89c881645eab69abfa787a6f7e29 (patch)
tree643767edc11cc71b7f84180c63142610daa2938f /cobbler/serializer.py
parent53fb6c70d0a869de623e4e4b02d78e2a2b6b9f63 (diff)
downloadthird_party-cobbler-5eaa46b5af9e89c881645eab69abfa787a6f7e29.tar.gz
third_party-cobbler-5eaa46b5af9e89c881645eab69abfa787a6f7e29.tar.xz
third_party-cobbler-5eaa46b5af9e89c881645eab69abfa787a6f7e29.zip
Keep track of depth of cobbler objects such that a pseudo-topological sort
can be done at deserialization time. The result of this is that full graph listing information can be reconstructed at time of config loading (up and down links), while only having to store the up links. This preserves the existing config file format while allowing for arbitrary inheritance and a reasonable measure of hand-editability. If changing profile relationships by hand, the cached depth info may be wrong, so some way to automatically resolve this could potentially be doable, but it's such a distinct corner case that I don't deem it neccessary at this point.
Diffstat (limited to 'cobbler/serializer.py')
-rw-r--r--cobbler/serializer.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/cobbler/serializer.py b/cobbler/serializer.py
index 38a182d..39cb982 100644
--- a/cobbler/serializer.py
+++ b/cobbler/serializer.py
@@ -49,7 +49,7 @@ def serialize(obj):
fd.close()
return True
-def deserialize(obj):
+def deserialize(obj,topological=False):
"""
Populate an existing object with the contents of datastruct.
Object must "implement" Serializable. Returns True assuming
@@ -69,7 +69,21 @@ def deserialize(obj):
data = fd.read()
datastruct = yaml.load(data).next() # first record
fd.close()
+
+ if topological:
+ # in order to build the graph links from the flat list, sort by the
+ # depth of items in the graph. If an object doesn't have a depth, sort it as
+ # if the depth were 0. It will be assigned a proper depth at serialization
+ # time. This is a bit cleaner implementation wise than a topological sort,
+ # though that would make a shiny upgrade.
+ datastruct.sort(cmp=__depth_cmp)
obj.from_datastruct(datastruct)
return True
+def __depth_cmp(item1, item2):
+ if not item1.has_key("depth"):
+ return 1
+ if not item2.has_key("depth"):
+ return -1
+ return cmp(item1["depth"],item2["depth"])