def __init__(self, conf_obj): kv_view = generic_text_views.KeyValueView(dict_sep=": ", before_dict='') super(ConfigModel, self).__init__(text_view=kv_view) def opt_title(optname, co): return co._opts[optname]['opt'].name def opt_value(opt_obj, value): if opt_obj['opt'].secret: return '***' else: return value self['default'] = dict( (opt_title(optname, conf_obj), opt_value(conf_obj._opts[optname], conf_obj[optname])) for optname in conf_obj._opts) groups = {} for groupname in conf_obj._groups: group_obj = conf_obj._groups[groupname] curr_group_opts = dict((opt_title(optname, group_obj), opt_value(group_obj._opts[optname], conf_obj[groupname][optname])) for optname in group_obj._opts) groups[group_obj.name] = curr_group_opts self.update(groups)
def __init__(self, vendor, product, version): super(PackageModel, self).__init__(text_view=generic_text_views.KeyValueView()) self['vendor'] = vendor self['product'] = product self['version'] = version
def __init__(self, *args, **kwargs): self.views = { 'text': textviews.KeyValueView(), 'json': jsonviews.KeyValueView(), 'xml': xmlviews.KeyValueView() } newargs = copy.copy(kwargs) for k in kwargs: if k.endswith('_view'): self.views[k[:-5]] = kwargs[k] del newargs[k] super(ModelWithDefaultViews, self).__init__(*args, **newargs)