summaryrefslogtreecommitdiffstats
path: root/cobbler/collection.py
diff options
context:
space:
mode:
authorMichael DeHaan <mdehaan@redhat.com>2006-05-05 18:30:44 -0400
committerJim Meyering <jim@meyering.net>2006-05-05 18:30:44 -0400
commitc1aea64f02ae55d47c18269895717af99839ed0e (patch)
treebe13cc5c96d135cd8a08fd0794507650a55ad35b /cobbler/collection.py
parent3e38df5996d007b4eedc65c4b357502f3e03b604 (diff)
downloadthird_party-cobbler-c1aea64f02ae55d47c18269895717af99839ed0e.tar.gz
third_party-cobbler-c1aea64f02ae55d47c18269895717af99839ed0e.tar.xz
third_party-cobbler-c1aea64f02ae55d47c18269895717af99839ed0e.zip
Interim commit during refactoring. Pretty broken as a result of some cleanup but it will get straightened out very soon. The main thing I'm doing here is to remove backreferences from the object tree and make the API simpler, so that folks using the API screw up less. This means making the CLI code simpler as well. The serializer has also been overhauled so it's not as much bolted on, although I have some fixing to do to make it work entirely correctly. Wanted to check all of this in case someone decided to patch something else, making diffing really complex in the interim. I'd recommend not patching anything else to this code as I'm not close to done, really.
Diffstat (limited to 'cobbler/collection.py')
-rw-r--r--cobbler/collection.py33
1 files changed, 28 insertions, 5 deletions
diff --git a/cobbler/collection.py b/cobbler/collection.py
index 708bb98..c02d10c 100644
--- a/cobbler/collection.py
+++ b/cobbler/collection.py
@@ -1,11 +1,13 @@
import serializable
+import utils
+import msg
"""
Base class for any serializable lists of things...
"""
class Collection(serializable.Serializable):
- def class_container(self):
+ def factory_produce(self):
raise exceptions.NotImplementedError
def filename(self):
@@ -16,10 +18,13 @@ class Collection(serializable.Serializable):
Constructor.
"""
self.config = config
+ self.debug = 1
self.clear()
-
+
def clear(self):
+ if self.debug:
+ print "Collection::clear"
self.listing = {}
def find(self,name):
@@ -27,6 +32,8 @@ class Collection(serializable.Serializable):
Return anything named 'name' in the collection, else return None if
no objects can be found.
"""
+ if self.debug:
+ print "Collection::find(%s)" % name
if name in self.listing.keys():
return self.listing[name]
return None
@@ -36,12 +43,20 @@ class Collection(serializable.Serializable):
"""
Serialize the collection
"""
+ if self.debug:
+ print "Collection::to_datastruct"
datastruct = [x.to_datastruct() for x in self.listing.values()]
+ return datastruct
def from_datastruct(self,datastruct):
- container = self.class_container()
+ if self.debug:
+ print "Collection::from_datastruct(%s)" % datastruct
+ if datastruct is None:
+ print "DEBUG: from_datastruct -> None, skipping"
+ return
+ print "DEBUG: from_datastruct: %s" % datastruct
for x in datastruct:
- item = container(x,self.config)
+ item = self.factory_produce(self.config)
self.add(item)
def add(self,ref):
@@ -51,6 +66,8 @@ class Collection(serializable.Serializable):
object specified by ref deems itself invalid (and therefore
won't be added to the collection).
"""
+ if self.debug:
+ print "Collection::add(%s)" % ref
if ref is None or not ref.is_valid():
if utils.last_error() is None or utils.last_error() == "":
utils.set_error("bad_param")
@@ -65,16 +82,20 @@ class Collection(serializable.Serializable):
for reading by humans or parsing from scripts. Actually scripts
would be better off reading the YAML in the config files directly.
"""
+ if self.debug:
+ print "Collection::printable"
values = map(lambda(a): a.printable(), sorted(self.listing.values()))
if len(values) > 0:
return "\n\n".join(values)
else:
- return m("empty_list")
+ return msg.m("empty_list")
def __iter__(self):
"""
Iterator for the collection. Allows list comprehensions, etc
"""
+ if self.debug:
+ print "Collection::__iter__"
for a in self.listing.values():
yield a
@@ -82,5 +103,7 @@ class Collection(serializable.Serializable):
"""
Returns size of the collection
"""
+ if self.debug:
+ print "Collection::__len__"
return len(self.listing.values())