diff options
author | Mihai Ibanescu <misa@redhat.com> | 2006-05-04 15:57:46 -0400 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2006-05-04 15:57:46 -0400 |
commit | 13f1e9b0f62cedc8aed257ec2faaafac3544e428 (patch) | |
tree | 23240456a4eef75fc37ad467f933204ce3beebe6 /cobbler/api.py | |
parent | c9ac1e44791f8f670672e0970df1e5c9dae1c334 (diff) | |
download | third_party-cobbler-13f1e9b0f62cedc8aed257ec2faaafac3544e428.tar.gz third_party-cobbler-13f1e9b0f62cedc8aed257ec2faaafac3544e428.tar.xz third_party-cobbler-13f1e9b0f62cedc8aed257ec2faaafac3544e428.zip |
Reducing duplication in the constructors
We define a top-level constructor in the base class and define an
_item_factory that is the class to be instantiated for each item.
The code as it is checked in now is broken because we reference the class
before we define it in the global scope; but wanted the checkins to be
separate, the next one will move all the Collection-related stuff after the
Item-related stuff (but the diff would have been difficult to read)
Diffstat (limited to 'cobbler/api.py')
-rw-r--r-- | cobbler/api.py | 42 |
1 files changed, 15 insertions, 27 deletions
diff --git a/cobbler/api.py b/cobbler/api.py index f2a18f8..e928643 100644 --- a/cobbler/api.py +++ b/cobbler/api.py @@ -131,7 +131,19 @@ class BootAPI: Base class for any serializable lists of things... """ class Collection: + _item_factory = None + def __init__(self, api, seed_data): + """ + Constructor. Requires an API reference. seed_data + is a hash of data to feed into the collection, that would + come from the config file in /var. + """ + self.api = api + self.listing = {} + if seed_data is not None: + for x in seed_data: + self.add(self._item_factory(self.api), x) def find(self,name): """ @@ -172,7 +184,6 @@ class Collection: for reading by humans or parsing from scripts. Actually scripts would be better off reading the YAML in the config files directly. """ - buf = "" values = map(lambda(a): a.printable(), sorted(self.listing.values())) if len(values) > 0: return "\n\n".join(values) @@ -208,18 +219,7 @@ A distro represents a network bootable matched set of kernels and initrd files """ class Distros(Collection): - - def __init__(self,api,seed_data): - """ - Constructor. Requires an API reference. seed_data - is a hash of data to feed into the collection, that would - come from the config file in /var. - """ - self.api = api - self.listing = {} - if seed_data is not None: - for x in seed_data: - self.add(Distro(self.api,x)) + _item_factory = Distro def remove(self,name): """ @@ -246,13 +246,7 @@ might represent a 'desktop' profile. For Xen, there are many additional options, with client-side defaults (not kept here). """ class Profiles(Collection): - - def __init__(self,api,seed_data): - self.api = api - self.listing = {} - if seed_data is not None: - for x in seed_data: - self.add(Profile(self.api,x)) + _item_factory = Profile def remove(self,name): """ @@ -276,13 +270,7 @@ Systems are hostnames/MACs/IP names and the associated profile they belong to. """ class Systems(Collection): - - def __init__(self,api,seed_data): - self.api = api - self.listing = {} - if seed_data is not None: - for x in seed_data: - self.add(System(self.api,x)) + _item_factory = System def remove(self,name): """ |