Vreman, Peter - Acision wrote:
Dynamic method creation can be used to create the methods for the cobbler nouns. A single loop can create all the wrappers:
Adding the following code to api.__init__ will create all the find_xxxx() methods:
for what in
['distro','profile','system','repo','image','network']:
codestr=''' def find_%s(self, name=None, return_list=False,
no_errors=False, **kargs):
return self._config.%ss().find(name=name,
return_list=return_list, no_errors=no_errors, **kargs)
''' % (what,what) d={} exec codestr.strip() in d setattr(self.__class__, 'find_%s' % what, d['find_%s' % what])
Regards,
Peter
Clever, breaks pydoc though... I'd prefer not to include such magic when possible.
It wasn't remote.py that involves so much boilerplate per se, but it's also the CLI module, the new object classes, the web application pages, etc.
Remote.py is rather tame in terms of complexity compared to those.
Longer term (we're talking maybe like 2.0), I'd like to be able to have object classes be able to inject their own CLI options and remote.py handling code somehow, so there will be less places to go to edit things related to any particular construct. When we do this, it won't be via eval, but more of some sort of basic registration kind of system where we tell api.py what object types it is managing.
This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.
cobbler-devel mailing list cobbler-devel@lists.fedorahosted.org https://fedorahosted.org/mailman/listinfo/cobbler-devel