示例#1
0
文件: text.py 项目: ekohl/rhevm-api
 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
示例#2
0
 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
示例#3
0
 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
示例#4
0
 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