@staticmethod
    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 (__HOLE__, 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)
dataset/ETHPy150Open VisTrails/VisTrails/vistrails/core/db/locator.py/FileLocator.from_link_file