Example #1
0
# VisTrails does funny stuff with unittest/unittest2, be sure to load that
# after vistrails
import unittest

# reinitializing arguments and options so VisTrails does not try parsing them
sys.argv = sys.argv[:1]
vistrails.gui.application.VistrailsApplicationSingleton.use_event_filter = \
        False

root_directory = os.path.realpath(vistrails_root_directory())

###############################################################################
# Testing Examples

EXAMPLES_PATH = vistrails_examples_directory()
#dictionary of examples that will be run with the workflows that will be ignored
VT_EXAMPLES = {
    'EMBOSS_webservices.vt': ["ProphetOutput"],
    'KEGGPathway.vt': [],
    'KEGG_SearchEntities_webservice.vt': [],
    'KEGG_webservices.vt': [],
    'brain_vistrail.vt': [],
    'chebi_webservice.vt': [],
    'head.vt': [],
    'infovis.vt': [],
    'noaa_webservices.vt': [],
    'offscreen.vt': [],
    'plot.vt': [],
    'spx.vt': [],
    'structure_or_id_webservice.vt': [],
Example #2
0
# VisTrails does funny stuff with unittest/unittest2, be sure to load that
# after vistrails
import unittest

# reinitializing arguments and options so VisTrails does not try parsing them
sys.argv = sys.argv[:1]
vistrails.gui.application.VistrailsApplicationSingleton.use_event_filter = \
        False


root_directory = os.path.realpath(vistrails_root_directory())

###############################################################################
# Testing Examples

EXAMPLES_PATH = vistrails_examples_directory()
#dictionary of examples that will be run with the workflows that will be ignored
VT_EXAMPLES = { 'EMBOSS_webservices.vt': ["ProphetOutput"],
                'KEGGPathway.vt': [],
                'KEGG_SearchEntities_webservice.vt': [],
                'KEGG_webservices.vt': [],
                'brain_vistrail.vt': [],
                'chebi_webservice.vt': [],
                'head.vt': [],
                'infovis.vt': [],
                'noaa_webservices.vt': [],
                'offscreen.vt': [],
                'plot.vt': [],
                'spx.vt': [],
                'structure_or_id_webservice.vt': [],
                'terminator.vt': ["Isosurface Script"],
Example #3
0
    def from_link_file(filename):
        """from_link_file(filename: str) -> DBLocator
        This will parse a '.vtl' file and  will create a DBLocator. .vtl files
        are vistrail link files and they are used to point vistrails to open
        vistrails from the database on the web. """
        def convert_from_str(value, type):
            def bool_conv(x):
                s = str(x).upper()
                if s == 'TRUE':
                    return True
                if s == 'FALSE':
                    return False

            if value is not None:
                if type == 'str':
                    return str(value)
                elif value.strip() != '':
                    if type == 'long':
                        return long(value)
                    elif type == 'float':
                        return float(value)
                    elif type == 'int':
                        return int(value)
                    elif type == 'bool':
                        return bool_conv(value)
                    elif type == 'base64':
                        return base64.b64decode(value)
            return None

        def guess_extension_from_contents(contents):
            if contents.startswith("<vistrail"):
                return ".xml"
            else:
                return ".vt"

        tree = ElementTree.parse(filename)
        node = tree.getroot()
        if node.tag != 'vtlink':
            return None
        #read attributes
        data = node.get('host', None)
        host = convert_from_str(data, 'str')
        data = node.get('port', None)
        port = convert_from_str(data, 'int')
        data = node.get('database', None)
        database = convert_from_str(data, 'str')
        data = node.get('vtid')
        vt_id = convert_from_str(data, 'int')
        data = node.get('version')
        version = convert_from_str(data, 'str')
        data = node.get('tag')
        tag = convert_from_str(data, 'str')
        data = node.get('execute')
        execute = convert_from_str(data, 'bool')
        data = node.get('showSpreadsheetOnly')
        showSpreadsheetOnly = convert_from_str(data, 'bool')
        data = node.get('url', None)
        url = convert_from_str(data, 'str')
        data = node.get('vtcontent', None)
        vtcontent = convert_from_str(data, 'base64')
        data = node.get('filename', None)
        vtname = convert_from_str(data, 'str')
        data = node.get('forceDB', None)
        forceDB = convert_from_str(data, 'bool')
        data = node.get('mashuptrail', None)
        mashuptrail = convert_from_str(data, 'str')
        data = node.get('mashupVersion', None)
        mashupVersion = convert_from_str(data, 'int')
        data = node.get('parameterExploration', None)
        parameterExploration = convert_from_str(data, 'int')

        #if execute is False, we will show the builder too
        if showSpreadsheetOnly and not execute:
            showSpreadsheetOnly = False
        try:
            version = int(version)
        except (ValueError, TypeError):
            pass

        if tag is None:
            tag = ''

        ## execute and showSpreadsheetOnly should be written to the current
        ## configuration
        config = get_vistrails_configuration()
        config.execute = execute
        config.showWindow = not showSpreadsheetOnly
        if not forceDB:
            if vtcontent is not None:
                if url is not None:
                    basename = url.split('/')[-1]
                    base, ext = os.path.splitext(basename)
                    dirname = os.path.dirname(filename)
                    fname = os.path.join(dirname, basename)
                else:
                    basename = os.path.basename(filename)
                    base, ext = os.path.splitext(basename)
                    ext = guess_extension_from_contents(vtcontent)
                    dirname = os.path.dirname(filename)
                    fname = os.path.join(dirname, "%s%s" % (base, ext))
                create_file = True
                if os.path.exists(fname):  #file was extracted before
                    create_file = False
                    oldf = open(fname)
                    oldcontents = oldf.read()
                    if oldcontents != vtcontent:
                        import vistrails.gui.extras.core.db.locator as db_gui
                        (overwrite, newname) = \
                                 db_gui.ask_to_overwrite_file(None, 'vistrail')
                        create_file = True
                        if newname:
                            fname = newname
                        elif overwrite == False:
                            i = 1
                            while os.path.exists(fname):
                                newbase = "%s_%s%s" % (base, i, ext)
                                fname = os.path.join(dirname, newbase)
                                i += 1

                if create_file:
                    f = open(fname, 'wb')
                    f.write(vtcontent)
                    f.close()
                return FileLocator(fname,
                                   version_node=version,
                                   version_tag=tag,
                                   mashuptrail=mashuptrail,
                                   mashupVersion=mashupVersion,
                                   parameterExploration=parameterExploration)
        if host is not None:
            user = ""
            passwd = ""

            return DBLocator(host,
                             port,
                             database,
                             user,
                             passwd,
                             None,
                             obj_id=vt_id,
                             obj_type='vistrail',
                             connection_id=None,
                             version_node=version,
                             version_tag=tag,
                             mashuptrail=mashuptrail,
                             mashupVersion=mashupVersion,
                             parameterExploration=parameterExploration)
        elif vtname is not None:
            if os.path.dirname(vtname) == '':
                #check if file exists in the same directory as the .vtl file
                dirname = os.path.dirname(filename)
                newvtname = os.path.join(dirname, vtname)
                if os.path.exists(newvtname):
                    vtname = newvtname
            #check for magic strings
            if "@examples" in vtname:
                vtname = vtname.replace("@examples",
                                        vistrails_examples_directory())
            return FileLocator(vtname,
                               version_node=version,
                               version_tag=tag,
                               mashuptrail=mashuptrail,
                               mashupVersion=mashupVersion,
                               parameterExploration=parameterExploration)
Example #4
0
    def from_link_file(filename):
        """from_link_file(filename: str) -> DBLocator
        This will parse a '.vtl' file and  will create a DBLocator. .vtl files
        are vistrail link files and they are used to point vistrails to open
        vistrails from the database on the web. """
        def convert_from_str(value,type):
            def bool_conv(x):
                s = str(x).upper()
                if s == 'TRUE':
                    return True
                if s == 'FALSE':
                    return False
            
            if value is not None:
                if type == 'str':
                    return str(value)
                elif value.strip() != '':
                    if type == 'long':
                        return long(value)
                    elif type == 'float':
                        return float(value)
                    elif type == 'int':
                        return int(value)
                    elif type == 'bool':
                        return bool_conv(value)
                    elif type == 'base64':
                        return base64.b64decode(value)
            return None
        
        def guess_extension_from_contents(contents):
            if contents.startswith("<vistrail"):
                return ".xml"
            else:
                return ".vt"
            
        tree = ElementTree.parse(filename)
        node = tree.getroot()
        if node.tag != 'vtlink':
            return None
        #read attributes
        data = node.get('host', None)
        host = convert_from_str(data, 'str')
        data = node.get('port', None)
        port = convert_from_str(data,'int')
        data = node.get('database', None)
        database = convert_from_str(data,'str')
        data = node.get('vtid')
        vt_id = convert_from_str(data, 'int')
        data = node.get('version')
        version = convert_from_str(data, 'str')
        data = node.get('tag')
        tag = convert_from_str(data, 'str')
        data = node.get('execute')
        execute = convert_from_str(data, 'bool')
        data = node.get('showSpreadsheetOnly')
        showSpreadsheetOnly = convert_from_str(data, 'bool')
        data = node.get('url', None)
        url = convert_from_str(data,'str')
        data = node.get('vtcontent', None)
        vtcontent = convert_from_str(data,'base64')
        data = node.get('filename', None)
        vtname = convert_from_str(data, 'str')
        data = node.get('forceDB',None)
        forceDB = convert_from_str(data,'bool')
        data = node.get('mashuptrail', None)
        mashuptrail = convert_from_str(data, 'str')
        data = node.get('mashupVersion', None)
        mashupVersion = convert_from_str(data, 'int')
        data = node.get('parameterExploration', None)
        parameterExploration = convert_from_str(data, 'int')
        
        #if execute is False, we will show the builder too
        if showSpreadsheetOnly and not execute:
            showSpreadsheetOnly = False
        try:
            version = int(version)
        except (ValueError, TypeError):
            pass

        if tag is None:
            tag = ''
            
        ## execute and showSpreadsheetOnly should be written to the current
        ## configuration
        config = get_vistrails_configuration()
        config.execute = execute
        config.showWindow = not showSpreadsheetOnly
        if not forceDB:
            if vtcontent is not None:
                if url is not None:
                    basename = url.split('/')[-1]
                    base,ext = os.path.splitext(basename)
                    dirname = os.path.dirname(filename)
                    fname = os.path.join(dirname,basename)
                else:
                    basename = os.path.basename(filename)
                    base,ext = os.path.splitext(basename)
                    ext = guess_extension_from_contents(vtcontent)
                    dirname = os.path.dirname(filename)
                    fname = os.path.join(dirname,"%s%s"%(base,ext))
                create_file = True
                if os.path.exists(fname): #file was extracted before
                    create_file = False
                    oldf = open(fname)
                    oldcontents = oldf.read()
                    if oldcontents != vtcontent:
                        import vistrails.gui.extras.core.db.locator as db_gui
                        (overwrite, newname) = \
                                 db_gui.ask_to_overwrite_file(None, 'vistrail')
                        create_file = True
                        if newname:
                            fname = newname
                        elif overwrite == False:
                            i=1
                            while os.path.exists(fname):
                                newbase = "%s_%s%s" % (base, i, ext)
                                fname = os.path.join(dirname,newbase)
                                i+=1
                        
                if create_file:
                    f = open(fname,'wb')
                    f.write(vtcontent)
                    f.close()
                return FileLocator(fname, version_node=version, version_tag=tag,
                                   mashuptrail=mashuptrail,
                                   mashupVersion=mashupVersion,
                                   parameterExploration=parameterExploration)
        if host is not None:
            user = ""
            passwd = ""
            
            return DBLocator(host, port, database,
                             user, passwd, None, obj_id=vt_id,
                             obj_type='vistrail',connection_id=None,
                             version_node=version, version_tag=tag,
                             mashuptrail=mashuptrail,
                             mashupVersion=mashupVersion,
                             parameterExploration=parameterExploration)
        elif vtname is not None:
            if os.path.dirname(vtname) == '':
                #check if file exists in the same directory as the .vtl file
                dirname = os.path.dirname(filename)
                newvtname = os.path.join(dirname,vtname)
                if os.path.exists(newvtname):
                    vtname = newvtname
            #check for magic strings
            if "@examples" in vtname:
                vtname=vtname.replace("@examples", vistrails_examples_directory())
            return FileLocator(vtname, version_node=version, version_tag=tag,
                               mashuptrail=mashuptrail,
                               mashupVersion=mashupVersion,
                               parameterExploration=parameterExploration)
    def from_link_file(filename):
        """from_link_file(filename: str) -> DBLocator
        This will parse a '.vtl' file and  will create a DBLocator. .vtl files
        are vistrail link files and they are used to point vistrails to open
        vistrails from the database on the web. """

        def convert_from_str(value, type):
            def bool_conv(x):
                s = str(x).upper()
                if s == "TRUE":
                    return True
                if s == "FALSE":
                    return False

            if value is not None:
                if type == "str":
                    return str(value)
                elif value.strip() != "":
                    if type == "long":
                        return long(value)
                    elif type == "float":
                        return float(value)
                    elif type == "int":
                        return int(value)
                    elif type == "bool":
                        return bool_conv(value)
                    elif type == "base64":
                        return base64.b64decode(value)
            return None

        def guess_extension_from_contents(contents):
            if contents.startswith("<vistrail"):
                return ".xml"
            else:
                return ".vt"

        tree = ElementTree.parse(filename)
        node = tree.getroot()
        if node.tag != "vtlink":
            return None
        # read attributes
        data = node.get("host", None)
        host = convert_from_str(data, "str")
        data = node.get("port", None)
        port = convert_from_str(data, "int")
        data = node.get("database", None)
        database = convert_from_str(data, "str")
        data = node.get("vtid")
        vt_id = convert_from_str(data, "int")
        data = node.get("version")
        version = convert_from_str(data, "str")
        data = node.get("tag")
        tag = convert_from_str(data, "str")
        data = node.get("execute")
        execute = convert_from_str(data, "bool")
        data = node.get("showSpreadsheetOnly")
        showSpreadsheetOnly = convert_from_str(data, "bool")
        data = node.get("url", None)
        url = convert_from_str(data, "str")
        data = node.get("vtcontent", None)
        vtcontent = convert_from_str(data, "base64")
        data = node.get("filename", None)
        vtname = convert_from_str(data, "str")
        data = node.get("forceDB", None)
        forceDB = convert_from_str(data, "bool")
        data = node.get("mashuptrail", None)
        mashuptrail = convert_from_str(data, "str")
        data = node.get("mashupVersion", None)
        mashupVersion = convert_from_str(data, "int")
        data = node.get("parameterExploration", None)
        parameterExploration = convert_from_str(data, "int")

        # if execute is False, we will show the builder too
        if showSpreadsheetOnly and not execute:
            showSpreadsheetOnly = False
        try:
            version = int(version)
        except:
            pass

        if tag is None:
            tag = ""

        ## execute and showSpreadsheetOnly should be written to the current
        ## configuration
        config = get_vistrails_configuration()
        config.executeWorkflows = execute
        config.showSpreadsheetOnly = showSpreadsheetOnly
        if not forceDB:
            if vtcontent is not None:
                if url is not None:
                    basename = url.split("/")[-1]
                    base, ext = os.path.splitext(basename)
                    dirname = os.path.dirname(filename)
                    fname = os.path.join(dirname, basename)
                else:
                    basename = os.path.basename(filename)
                    base, ext = os.path.splitext(basename)
                    ext = guess_extension_from_contents(vtcontent)
                    dirname = os.path.dirname(filename)
                    fname = os.path.join(dirname, "%s%s" % (base, ext))
                create_file = True
                if os.path.exists(fname):  # file was extracted before
                    create_file = False
                    oldf = open(fname)
                    oldcontents = oldf.read()
                    if oldcontents != vtcontent:
                        import vistrails.gui.extras.core.db.locator as db_gui

                        (overwrite, newname) = db_gui.ask_to_overwrite_file(None, "vistrail")
                        create_file = True
                        if newname:
                            fname = newname
                        elif overwrite == False:
                            i = 1
                            while os.path.exists(fname):
                                newbase = "%s_%s%s" % (base, i, ext)
                                fname = os.path.join(dirname, newbase)
                                i += 1

                if create_file:
                    f = open(fname, "wb")
                    f.write(vtcontent)
                    f.close()
                return FileLocator(
                    fname,
                    version_node=version,
                    version_tag=tag,
                    mashuptrail=mashuptrail,
                    mashupVersion=mashupVersion,
                    parameterExploration=parameterExploration,
                )
        if host is not None:
            user = ""
            passwd = ""

            return DBLocator(
                host,
                port,
                database,
                user,
                passwd,
                None,
                obj_id=vt_id,
                obj_type="vistrail",
                connection_id=None,
                version_node=version,
                version_tag=tag,
                mashuptrail=mashuptrail,
                mashupVersion=mashupVersion,
                parameterExploration=parameterExploration,
            )
        elif vtname is not None:
            if os.path.dirname(vtname) == "":
                # check if file exists in the same directory as the .vtl file
                dirname = os.path.dirname(filename)
                newvtname = os.path.join(dirname, vtname)
                if os.path.exists(newvtname):
                    vtname = newvtname
            # check for magic strings
            if "@examples" in vtname:
                vtname = vtname.replace("@examples", vistrails_examples_directory())
            return FileLocator(
                vtname,
                version_node=version,
                version_tag=tag,
                mashuptrail=mashuptrail,
                mashupVersion=mashupVersion,
                parameterExploration=parameterExploration,
            )
Example #6
0
def record_vistrail(what, vistrail):
    """Record info about a vistrail we used.
    """
    if not usage_report.recording:
        return

    from vistrails.core.vistrail.controller import VistrailController
    from vistrails.core.vistrail.pipeline import Pipeline
    from vistrails.core.vistrail.vistrail import Vistrail
    from vistrails.db.services.locator import XMLFileLocator

    if isinstance(vistrail, VistrailController):
        vistrail = vistrail.vistrail

    if what == 'save':
        # Don't report now, but mark it for reporting when it gets closed
        saved_vistrails[id(vistrail)] = vistrail
        return
    elif what == 'close':
        i = id(vistrail)
        if i in saved_vistrails:
            del saved_vistrails[i]
            what = 'saved_close'
        else:
            return

    if isinstance(vistrail, Vistrail):
        upgrade_from = set()
        upgrade_to = set()
        nb_notes = 0
        nb_paramexplorations = 0
        for annotation in vistrail.action_annotations:
            if annotation.key == Vistrail.UPGRADE_ANNOTATION:
                upgrade_from.add(annotation.action_id)
                upgrade_to.add(int(annotation.value))
            elif annotation.key == Vistrail.NOTES_ANNOTATION:
                nb_notes += 1
            elif annotation.key == Vistrail.PARAMEXP_ANNOTATION:
                nb_paramexplorations += 1
        nb_upgrades = len(upgrade_from - upgrade_to)
        if isinstance(vistrail.locator, XMLFileLocator):
            usage_report.note({'in_examples_dir':
                os.path.realpath(vistrail.locator._name).startswith(
                    os.path.realpath(vistrails_examples_directory()))})
        nb_modules = 0
        nb_groups = 0
        nb_abstractions = 0
        for action in vistrail.actions:
            if action.id in upgrade_to or action.description == "Upgrade":
                continue
            for operation in action.operations:
                if operation.vtType == 'add' or operation.vtType == 'change':
                    if operation.what == 'module':
                        nb_modules += 1
                        if operation.data.is_group():
                            nb_groups += 1
                        elif operation.data.is_abstraction():
                            nb_abstractions += 1
        usage_report.note(dict(use_vistrail=what,
                               nb_versions=len(vistrail.actionMap),
                               nb_tags=len(vistrail.get_tagMap()),
                               nb_notes=nb_notes,
                               nb_paramexplorations=nb_paramexplorations,
                               nb_upgrades=nb_upgrades,
                               nb_variables=len(vistrail.vistrail_variables),
                               nb_modules=nb_modules,
                               nb_groups=nb_groups,
                               nb_abstractions=nb_abstractions))
        for feature in features_for_vistrails.pop(id(vistrail), ()):
            usage_report.note({'feature_for_vistrail': feature})
    elif isinstance(vistrail, Pipeline):
        usage_report.note(dict(use_workflow=what,
                               nb_modules=len(vistrail.module_list)))
    else:
        raise TypeError