def get_types_by_method(plural, method, expendNestedTypes=False, groupOptions=False): """INTERNAL: return a list of types that implement given method and context/s of this types.""" sing_types = {} if method: for decorator in TypeHelper.getKnownDecoratorsTypes(): dct = getattr(brokers, decorator).__dict__ if dct.has_key(method): if decorator.endswith('s'): cls_name = TypeHelper.getDecoratorType( TypeHelper.to_singular(decorator)) if cls_name: MethodHelper.get_method_params( brokers, cls_name, '__init__', sing_types, expendNestedTypes, groupOptions) if plural: sing_types_plural = {} for k in sing_types.keys(): sing_types_plural[TypeHelper.to_plural(k)] = sing_types[k] return sing_types_plural return sing_types
def get_types_containing_method(method, expendNestedTypes=False, groupOptions=False): """return a list of types by method including context in which this method available.""" types = {} for decorator in TypeHelper.getKnownDecoratorsTypes(): if not decorator.endswith('s'): dct = getattr(brokers, decorator).__dict__ if dct and len(dct) > 0 and dct.has_key(method): MethodHelper.get_method_params(brokers, decorator, '__init__', types, expendNestedTypes=expendNestedTypes, groupOptions=groupOptions) return types
def execute_method(self, resource, method_name, opts={}): """executes given method with specified opts.""" if hasattr(resource, method_name): method = getattr(resource, method_name) method_args = OrderedDict().fromkeys(MethodHelper.getMethodArgs(brokers, method.im_class.__name__, method_name, drop_self=True)) if method_args: for arg in method_args.keys(): param_type = ParseHelper.getXmlType(arg) if param_type: method_args[arg] = self.update_object_data(param_type.factory(), opts) elif opts.has_key('--' + arg): method_args[arg] = opts['--' + arg] else: # TODO: throw error if param is mandatory pass try: result = method(**method_args) except AttributeError: self.error(Messages.Error.UNSUPPORTED_ATTRIBUTE) else: result = method() return result else: self.error('no such action "%s"' % method_name)
def execute_method(self, resource, method_name, opts={}): """executes given method with specified opts.""" if hasattr(resource, method_name): method = getattr(resource, method_name) method_args = OrderedDict().fromkeys( MethodHelper.getMethodArgs(brokers, method.im_class.__name__, method_name, drop_self=True)) if method_args: for arg in method_args.keys(): param_type = ParseHelper.getXmlType(arg) if param_type: method_args[arg] = self.update_object_data( param_type.factory(), opts) elif opts.has_key('--' + arg): method_args[arg] = opts['--' + arg] else: # TODO: throw error if param is mandatory pass try: result = method(**method_args) except AttributeError: self.error(Messages.Error.UNSUPPORTED_ATTRIBUTE) else: result = method() return result else: self.error('no such action "%s"' % method_name)
def get_actionable_types(expendNestedTypes=False, groupOptions=False): """INTERNAL: return a list of actionable types.""" types = {} exceptions = ['delete', 'update'] for decorator in TypeHelper.getKnownDecoratorsTypes(): if not decorator.endswith('s'): dct = getattr(brokers, decorator).__dict__ if dct and len(dct) > 0: for method in dct: if method not in exceptions and not method.startswith('_'): MethodHelper.get_method_params(brokers, decorator, '__init__', types, expendNestedTypes=expendNestedTypes, groupOptions=groupOptions) break return types
def get_options(self, method, resource, sub_resource=None, as_params_collection=False, context_variants=[]): """Return a list of options for typ/action.""" method_ref = None connection = self.check_connection() if isinstance(resource, type('')): if not sub_resource: if resource and hasattr(connection, TypeHelper.to_plural(resource)) and \ type(getattr(connection, TypeHelper.to_plural(resource))).__dict__.has_key(method): method_ref = getattr( getattr(connection, TypeHelper.to_plural(resource)), method) else: if hasattr(sub_resource, TypeHelper.to_plural(resource)) and \ type(getattr(sub_resource, TypeHelper.to_plural(resource))).__dict__.has_key(method): method_ref = getattr( getattr(sub_resource, TypeHelper.to_plural(resource)), method) elif hasattr(sub_resource, TypeHelper.to_plural(resource)) and \ hasattr(brokers, TypeHelper.to_singular(type(getattr(sub_resource, TypeHelper.to_plural(resource))).__name__)) and \ hasattr(getattr(brokers, TypeHelper.to_singular(type(getattr(sub_resource, TypeHelper.to_plural(resource))).__name__)), method): method_ref = getattr( getattr( brokers, TypeHelper.to_singular( type( getattr(sub_resource, TypeHelper.to_plural( resource))).__name__)), method) if not method_ref: err_str = Messages.Error.NO_SUCH_CONTEXT if context_variants: err_str = err_str + ( Messages.Info.POSSIBALE_ARGUMENTS_COMBINATIONS % str(context_variants)) self.error(err_str % resource) elif isinstance(resource, brokers.Base): if hasattr(resource, method): method_ref = getattr(resource, method) elif hasattr(brokers, TypeHelper.to_plural(type(resource).__name__)) and \ hasattr(getattr(brokers, TypeHelper.to_plural(type(resource).__name__)), method): method_ref = getattr( getattr(brokers, TypeHelper.to_plural(type(resource).__name__)), method) return MethodHelper.get_arguments_documentation( method_ref, as_params_collection)
def get_types_containing_method(method, expendNestedTypes=False, groupOptions=False): """return a list of types by method including context in which this method available.""" types = {} for decorator in TypeHelper.getKnownDecoratorsTypes(): if not decorator.endswith('s'): dct = getattr(brokers, decorator).__dict__ if dct and len(dct) > 0 and dct.has_key(method): MethodHelper.get_method_params( brokers, decorator, '__init__', types, expendNestedTypes=expendNestedTypes, groupOptions=groupOptions) return types
def __add_resource_specific_options(self, obj, specific_options, line, key=None): obj_coll_type = TypeHelper.getDecoratorType(TypeHelper.to_plural(obj)) if obj_coll_type: if hasattr(brokers, obj_coll_type): obj_coll = getattr(brokers, obj_coll_type) if obj_coll and hasattr(obj_coll, ShowCmdShell.ALIAS): method_args = MethodHelper.get_documented_arguments(method_ref=getattr(obj_coll, ShowCmdShell.ALIAS), as_params_collection=True, spilt_or=True) if method_args: specific_options[obj if key == None else key] = method_args
def __add_resource_specific_options(self, obj, specific_options, line, key=None): obj_type = TypeHelper.getDecoratorType(TypeHelper.to_singular(obj)) if obj_type and hasattr(brokers, obj_type): obj_typ_ref = getattr(brokers, obj_type) if obj_typ_ref and hasattr(obj_typ_ref, RemoveCmdShell.ALIAS): method_args = MethodHelper.get_documented_arguments( method_ref=getattr(obj_typ_ref, RemoveCmdShell.ALIAS), as_params_collection=True, spilt_or=True ) if method_args: specific_options[key if key is not None else obj] = method_args
def __add_resource_specific_options(self, obj, specific_options, line, key=None): obj_coll_type = TypeHelper.getDecoratorType(TypeHelper.to_plural(obj)) if obj_coll_type: if hasattr(brokers, obj_coll_type): obj_coll = getattr(brokers, obj_coll_type) if obj_coll and hasattr(obj_coll, AddCmdShell.NAME): method_args = MethodHelper.get_documented_arguments(method_ref=getattr(obj_coll, AddCmdShell.NAME), as_params_collection=True, spilt_or=True) if method_args: specific_options[obj if key == None else key] = method_args
def get_actionable_types(expendNestedTypes=False, groupOptions=False): """INTERNAL: return a list of actionable types.""" types = {} exceptions = ['delete', 'update'] for decorator in TypeHelper.getKnownDecoratorsTypes(): if not decorator.endswith('s'): dct = getattr(brokers, decorator).__dict__ if dct and len(dct) > 0: for method in dct: if method not in exceptions and not method.startswith( '_'): MethodHelper.get_method_params( brokers, decorator, '__init__', types, expendNestedTypes=expendNestedTypes, groupOptions=groupOptions) break return types
def __add_resource_specific_options(self, obj, specific_options, line, key=None): typ = TypeHelper.getDecoratorType(obj) if typ: plur_obj = TypeHelper.to_plural(typ) if hasattr(brokers, plur_obj): method_args = MethodHelper.getMethodArgs(brokers, plur_obj, ListCmdShell.NAME, True, True, True) if method_args: specific_options[obj if key == None else key] = method_args
def __add_resource_specific_options(self, obj, specific_options, line, key=None): typ = TypeHelper.getDecoratorType(obj) if typ: plur_obj = TypeHelper.to_plural(typ) if hasattr(brokers, plur_obj): method_args = MethodHelper.getMethodArgs( brokers, plur_obj, ListCmdShell.NAME, True, True, True) if method_args: specific_options[obj if key == None else key] = method_args
def get_types_by_method(plural, method, expendNestedTypes=False, groupOptions=False): """INTERNAL: return a list of types that implement given method and context/s of this types.""" sing_types = {} if method: for decorator in TypeHelper.getKnownDecoratorsTypes(): dct = getattr(brokers, decorator).__dict__ if dct.has_key(method): if decorator.endswith('s'): cls_name = TypeHelper.getDecoratorType(TypeHelper.to_singular(decorator)) if cls_name: MethodHelper.get_method_params(brokers, cls_name, '__init__', sing_types, expendNestedTypes, groupOptions) if plural: sing_types_plural = {} for k in sing_types.keys(): sing_types_plural[TypeHelper.to_plural(k)] = sing_types[k] return sing_types_plural return sing_types
def __add_resource_specific_options(self, obj, specific_options, line, key=None): obj_type = TypeHelper.getDecoratorType(TypeHelper.to_singular(obj)) if obj_type and hasattr(brokers, obj_type): obj_typ_ref = getattr(brokers, obj_type) if obj_typ_ref and hasattr(obj_typ_ref, UpdateCmdShell.NAME): method_args = MethodHelper.get_documented_arguments( method_ref=getattr(obj_typ_ref, UpdateCmdShell.NAME), as_params_collection=True, spilt_or=True) if method_args: specific_options[ key if key is not None else obj] = method_args
def get_options(self, method, resource, sub_resource=None, as_params_collection=False, context_variants=[]): """Return a list of options for typ/action.""" method_ref = None connection = self.check_connection() if isinstance(resource, type('')): if not sub_resource: if resource and hasattr(connection, TypeHelper.to_plural(resource)) and \ type(getattr(connection, TypeHelper.to_plural(resource))).__dict__.has_key(method): method_ref = getattr(getattr(connection, TypeHelper.to_plural(resource)), method) else: if hasattr(sub_resource, TypeHelper.to_plural(resource)) and \ type(getattr(sub_resource, TypeHelper.to_plural(resource))).__dict__.has_key(method): method_ref = getattr(getattr(sub_resource, TypeHelper.to_plural(resource)), method) elif hasattr(sub_resource, TypeHelper.to_plural(resource)) and \ hasattr(brokers, TypeHelper.to_singular(type(getattr(sub_resource, TypeHelper.to_plural(resource))).__name__)) and \ hasattr(getattr(brokers, TypeHelper.to_singular(type(getattr(sub_resource, TypeHelper.to_plural(resource))).__name__)), method): method_ref = getattr(getattr(brokers, TypeHelper.to_singular(type(getattr(sub_resource, TypeHelper.to_plural(resource))).__name__)), method) if not method_ref: err_str = Messages.Error.NO_SUCH_CONTEXT if context_variants: err_str = err_str + (Messages.Info.POSSIBALE_ARGUMENTS_COMBINATIONS % str(context_variants)) self.error(err_str % resource) elif isinstance(resource, brokers.Base): if hasattr(resource, method): method_ref = getattr(resource, method) elif hasattr(brokers, TypeHelper.to_plural(type(resource).__name__)) and \ hasattr(getattr(brokers, TypeHelper.to_plural(type(resource).__name__)), method): method_ref = getattr(getattr(brokers, TypeHelper.to_plural(type(resource).__name__)), method) return MethodHelper.get_arguments_documentation(method_ref, as_params_collection)
def __add_resource_specific_options(self, obj, specific_options, line, key=None): obj_coll_type = TypeHelper.getDecoratorType(TypeHelper.to_plural(obj)) if obj_coll_type: if hasattr(brokers, obj_coll_type): obj_coll = getattr(brokers, obj_coll_type) if obj_coll and hasattr(obj_coll, ShowCmdShell.ALIAS): method_args = MethodHelper.get_documented_arguments( method_ref=getattr(obj_coll, ShowCmdShell.ALIAS), as_params_collection=True, spilt_or=True) if method_args: method_args = [ x for x in method_args if x not in ['id', 'name'] ] specific_options[obj if key == None else key] = method_args
def _get_action_methods(self, obj): """INTERNAL: return a list of type actions.""" return MethodHelper.get_object_methods(obj, exceptions=['delete', 'update'])