예제 #1
0
파일: utils.py 프로젝트: tristan/hydrant
def _get_parser():
    rgc = RemoveGraphicalClasses()
    rgc.remove("ptolemy.vergil.kernel.attributes.TextAttribute")
    MoMLParser.setMoMLFilters([rgc])
    parser = MoMLParser()
    parser.reset()
    return parser
예제 #2
0
파일: utils.py 프로젝트: tristan/hydrant
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)
예제 #3
0
파일: utils.py 프로젝트: tristan/hydrant
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)
예제 #4
0
파일: proxy.py 프로젝트: tristan/hydrant
    def from_moml(self, moml, filters=[]):
        """ Attempts to create a model from a string containing MoML
        code.

        Keyword attributes:
        moml -- the MoML string
        filters -- a list of MoMLFilter objects
        """

        # apply the RemoveGraphicalClasses MoMLFilter
        # but remove the TextAttribute class from the filter
        # such that annotations don't get removed from the model
        rgc = RemoveGraphicalClasses()
        rgc.remove('ptolemy.vergil.kernel.attributes.TextAttribute')
        rgc.remove('ptolemy.actor.lib.gui.Display')
        rgc.remove('ptolemy.actor.lib.gui.TimedPlotter')

        # create a new list for the filters, and use 
        # MoMLParser.setMoMLFilters with the new list. setMoMLFitlers is
        # used because the MoML filters object inside MoMLParser is
        # static, the only filtering on addMoMLFilter is memory address
        # filtering, and the filters specific to hydrant are only used
        # when executing a workflow, and no removeMoMLFilter object is
        # present. This is simply the easiest way to ensure nothing
        # goes wrong.
        f = [rgc]
        # add backwards compatibility filters 
        f.extend(BackwardCompatibility().allFilters())
        f.extend(filters)
        MoMLParser.setMoMLFilters(f)

        messages = utils.check_moml_dependencies(moml)

        # If a list is returned by validateMoML an error has occured 
        # during validation, and we shouldn't continue.
        if messages is []:
            raise Exception('VALIDATION ERRORS')

        parser = MoMLParser()
        parser.reset()
        try:
            self.proxied_entity = parser.parse(moml)
        except java.lang.ExceptionInInitializerError, e:
            e.printStackTrace()
            raise