def addMoMLFilters(filters): """ checks each filter to make sure it's not already been added and only adds new filters if they haven't """ current_filters = MoMLParser.getMoMLFilters() or [] fcs = [f.__class__ for f in current_filters] for f in filters: if f.__class__ not in fcs: MoMLParser.addMoMLFilter(f)
def check_moml_dependencies(moml): """ Checks all the classes in a MoML file by importing each one along with it's entire class heirarchy checking for any missing classes or libraries. Returns a list of any errors found. """ messages = [] classnames = getAllClassesInMoML(moml) # run the MoML filters over the class list momlfilters = MoMLParser.getMoMLFilters() or [] for filter in momlfilters: _classnames = [] for c in classnames: fn = filter.filterAttributeValue(None, None, "", c) if fn != None: _classnames.append(fn) classnames = _classnames # check each of the classes for errors for classname in classnames: try: # get a list of the package heirarchy for the class k_list = classname.split(".")[1:] # get the base package klass = __import__(classname) # check if the imported object is a javapackage, rather than a class, # and if so loop thru the package heirarchy to find the class while isinstance(klass, PyJavaPackage): klass = getattr(klass, k_list[0]) k_list = k_list[1:] # once we have the class itself, check it's class heirarchy for errors errors = checkClassHeirachy(klass) if errors is not None: # print 'NEW ERROR MESSAGE: %s' % errors messages.append({"type": "ERROR", "message": errors}) except ImportError, e: error = {"type": "ERROR", "message": e} messages.append(error)