def _get_fields(self, typ, flag, scope=None): info = schema.type_info(typ) assert info is not None override = self.context.settings.get("fields.%s" % info[2]) if override is None: override = self.context.settings.get("fields") if override is None: fields = metadata.get_fields(typ, flag, scope) else: override = override.split(",") fields = metadata.get_fields(typ, "") fields = filter(lambda f: f.name in override, fields) return fields
def update_object(self, obj, options, scope=None): """Create a new binding type of type `typ', and set its attributes with values from `options'.""" fields = metadata.get_fields(type(obj), 'U', scope) for field in fields: key = '--%s' % field.name if key in options: field.set(obj, options[key], self.context) return obj
def create_object(self, typ, options, scope=None): """Create a new object of type `typ' based on the command-line options in `options'.""" obj = schema.new(typ) fields = metadata.get_fields(typ, 'C', scope) for field in fields: key = '--%s' % field.name if key in options: field.set(obj, options[key], self.context) return obj
def get_options(self, typ, flag, scope=None): """Return a list of options for typ/action.""" fields = metadata.get_fields(typ, flag, scope=scope) options = [ '--%-20s %s' % (field.name, field.description) for field in fields ] return options