diff options
author | Michael DeHaan <mdehaan@mdehaan.rdu.redhat.com> | 2007-06-12 16:24:06 -0400 |
---|---|---|
committer | Michael DeHaan <mdehaan@mdehaan.rdu.redhat.com> | 2007-06-12 16:24:06 -0400 |
commit | fcbbaf14ae639c45c59275300b59106a753339c7 (patch) | |
tree | 3448d83dd996fd6b42d6e0bd1b824a57f749acc9 | |
parent | 0b8502cd2209b809ed8b98d8bab0086e169c4a0f (diff) | |
download | cobbler-fcbbaf14ae639c45c59275300b59106a753339c7.tar.gz cobbler-fcbbaf14ae639c45c59275300b59106a753339c7.tar.xz cobbler-fcbbaf14ae639c45c59275300b59106a753339c7.zip |
Generalizes tree listing to allow for inheritance and arbitrary nesting
-rwxr-xr-x | cobbler/cobbler.py | 29 | ||||
-rw-r--r-- | cobbler/item.py | 2 | ||||
-rw-r--r-- | cobbler/item_distro.py | 2 | ||||
-rw-r--r-- | cobbler/item_profile.py | 2 | ||||
-rw-r--r-- | cobbler/item_repo.py | 2 | ||||
-rw-r--r-- | cobbler/item_system.py | 2 |
6 files changed, 24 insertions, 15 deletions
diff --git a/cobbler/cobbler.py b/cobbler/cobbler.py index e999d2d4..7d88ccbd 100755 --- a/cobbler/cobbler.py +++ b/cobbler/cobbler.py @@ -173,21 +173,20 @@ class BootCLI: # LISTING FUNCTIONS def list(self,args): - # FIXME: inefficient - for d in self.api.distros(): - str = _("distribution : %(distro)s") % { "distro" : d.name } - print str - for p in self.api.profiles(): - if p.distro == d.name: - str = _(" profile : %(profile)s") % { "profile" : p.name } - print str - for s in self.api.systems(): - if s.profile == p.name: - str = _(" system : %(system)s") % { "system" : s.name } - print str - for r in self.api.repos(): - str = _("repo : %(repo)s") % { "repo" : r.name } - print str + collection = self.api.distros() + self.__tree(collection,0) + self.__tree(self.api.repos(),0) + + def __tree(self,collection,level): + for item in collection: + print _("%(indent)s%(type)s %(name)s") % { + "indent" : " " * level, + "type" : item.TYPE_NAME, + "name" : item.name + } + kids = item.get_children() + if kids is not None and len(kids) > 0: + self.__tree(kids,level+1) def __list_names(self, collection): names = [ x.name for x in collection] diff --git a/cobbler/item.py b/cobbler/item.py index b1ad2d1c..52ab9b94 100644 --- a/cobbler/item.py +++ b/cobbler/item.py @@ -20,6 +20,8 @@ from rhpl.translate import _, N_, textdomain, utf8 class Item(serializable.Serializable): + TYPE_NAME = "generic" + def __init__(self,config): """ Constructor. Requires a back reference to the Config management object. diff --git a/cobbler/item_distro.py b/cobbler/item_distro.py index 85742d66..e804cb90 100644 --- a/cobbler/item_distro.py +++ b/cobbler/item_distro.py @@ -24,6 +24,8 @@ from rhpl.translate import _, N_, textdomain, utf8 class Distro(item.Item): + TYPE_NAME = _("distro") + def clear(self): """ Reset this object. diff --git a/cobbler/item_profile.py b/cobbler/item_profile.py index 491e346a..09358b00 100644 --- a/cobbler/item_profile.py +++ b/cobbler/item_profile.py @@ -20,6 +20,8 @@ from rhpl.translate import _, N_, textdomain, utf8 class Profile(item.Item): + TYPE_NAME = _("profile") + def make_clone(self): ds = self.to_datastruct() cloned = Profile(self.config) diff --git a/cobbler/item_repo.py b/cobbler/item_repo.py index 585771d4..b7832644 100644 --- a/cobbler/item_repo.py +++ b/cobbler/item_repo.py @@ -19,6 +19,8 @@ from rhpl.translate import _, N_, textdomain, utf8 class Repo(item.Item): + ITEM_NAME = _("repo") + def make_clone(self): ds = self.to_datastruct() cloned = Repo(self.config) diff --git a/cobbler/item_system.py b/cobbler/item_system.py index baaf2fb3..c2242caa 100644 --- a/cobbler/item_system.py +++ b/cobbler/item_system.py @@ -20,6 +20,8 @@ from rhpl.translate import _, N_, textdomain, utf8 class System(item.Item): + TYPE_NAME = _("system") + def make_clone(self): ds = self.to_datastruct() cloned = System(self.config) |