Beispiel #1
0
 def clear_clicked(self, checked=False):
     thumbnail_dir = system.get_vistrails_directory("thumbs.cacheDir")
     res = show_question('VisTrails', ("All files in %s will be removed. "
                                       "Are you sure? " % thumbnail_dir),
                         buttons=[YES_BUTTON, NO_BUTTON],
                         default=NO_BUTTON)
     if res == YES_BUTTON:
         ThumbnailCache.getInstance().clear()
Beispiel #2
0
 def destroy(self):
     """ destroy() -> None
     Finalize all packages to, such as, get rid of temp files
     
     """
     if hasattr(self, 'package_manager'):
         self.package_manager.finalize_packages()
     Collection.clearInstance()
     ThumbnailCache.clearInstance()
Beispiel #3
0
 def clear_clicked(self, checked=False):
     thumbnail_dir = system.get_vistrails_directory("thumbs.cacheDir")
     res = show_question('VisTrails',
                         ("All files in %s will be removed. "
                          "Are you sure? " % thumbnail_dir),
                         buttons = [YES_BUTTON,NO_BUTTON],
                         default = NO_BUTTON)
     if res == YES_BUTTON:
         ThumbnailCache.getInstance().clear()
Beispiel #4
0
 def destroy(self):
     """ destroy() -> None
     Finalize all packages to, such as, get rid of temp files
     
     """
     if hasattr(self, 'package_manager'):
         self.package_manager.finalize_packages()
     Collection.clearInstance()
     ThumbnailCache.clearInstance()
Beispiel #5
0
 def save_as(self, save_bundle, version=None):
     save_bundle = _ZIPFileLocator.save(self, save_bundle, True, version)
     for obj in save_bundle.get_db_objs():
         klass = self.get_convert_klass(obj.vtType)
         klass.convert(obj)
         obj.locator = self
     # Need to update thumbnail cache since files have moved
     ThumbnailCache.getInstance().add_entries_from_files(save_bundle.thumbnails)
     return save_bundle
 def save_as(self, save_bundle, version=None):
     save_bundle = _ZIPFileLocator.save(self, save_bundle, True, version)
     for obj in save_bundle.get_db_objs():
         klass = self.get_convert_klass(obj.vtType)
         klass.convert(obj)
         obj.locator = self
     # Need to update thumbnail cache since files have moved
     ThumbnailCache.getInstance().add_entries_from_files(
         save_bundle.thumbnails)
     return save_bundle
Beispiel #7
0
    def setupVersion(self, node, action, tag, description):
        """ setupPort(node: DotNode,
                      action: DBAction,
                      tag: str,
                      description: str) -> None
        Update the version dimensions and id
        
        """
        # Lauro:
        # what was this hacking??? the coordinates inside
        # the input "node" should come to this point ready. This is
        # not the point to do layout calculations (e.g. -node.p.y/2)

        # Carlos:
        # This is not layout as much as dealing with the way Qt
        # specifies rectangles. Besides, moving this back here reduces
        # code duplication, and allows customized behavior for
        # subclasses.

        rect = QtCore.QRectF(node.p.x - node.width / 2.0,
                             node.p.y - node.height / 2.0, node.width,
                             node.height)
        validLabel = True
        if tag is None:
            label = ''
            validLabel = False
        else:
            label = tag

        self.id = node.id
        self.label = label
        if description is None:
            self.descriptionLabel = ''
        else:
            self.descriptionLabel = description
        if validLabel:
            textToDraw = self.label
        else:
            textToDraw = self.descriptionLabel

        if (ThumbnailCache.getInstance().conf.mouseHover and action
                and action.thumbnail is not None):
            fname = ThumbnailCache.getInstance().get_abs_name_entry(
                action.thumbnail)
            self.setToolTip('<img src="%s" height="128" border="1"/>' % fname)
        else:
            self.setToolTip('')
        self.text.changed(node.p.x, node.p.y, textToDraw, validLabel)
        self.setRect(rect)
Beispiel #8
0
    def setupVersion(self, node, action, tag, description):
        """ setupPort(node: DotNode,
                      action: DBAction,
                      tag: str,
                      description: str) -> None
        Update the version dimensions and id
        
        """
        # Lauro:
        # what was this hacking??? the coordinates inside
        # the input "node" should come to this point ready. This is
        # not the point to do layout calculations (e.g. -node.p.y/2)

        # Carlos:
        # This is not layout as much as dealing with the way Qt
        # specifies rectangles. Besides, moving this back here reduces
        # code duplication, and allows customized behavior for
        # subclasses.

        rect = QtCore.QRectF(node.p.x-node.width/2.0,
                             node.p.y-node.height/2.0,
                             node.width,
                             node.height)
        validLabel = True
        if tag is None:
            label = ''
            validLabel=False
        else:
            label = tag

        self.id = node.id
        self.label = label
        if description is None:
            self.descriptionLabel = ''
        else:
            self.descriptionLabel = description
        if validLabel:
            textToDraw=self.label
        else:
            textToDraw=self.descriptionLabel

        if (ThumbnailCache.getInstance().conf.mouseHover and
            action and action.thumbnail is not None):
            fname = ThumbnailCache.getInstance().get_abs_name_entry(action.thumbnail)
            self.setToolTip('<img src="%s" height="128" border="1"/>'%fname)
        else:
            self.setToolTip('')    
        self.text.changed(node.p.x, node.p.y, textToDraw, validLabel)
        self.setRect(rect)
Beispiel #9
0
 def add_mashup_entities_from_mashuptrail(self, mashuptrail):
     added_entry_keys = set()
     inv_tag_map = {}
     tagMap = mashuptrail.getTagMap()
     tags = tagMap.keys()
     if len(tags) > 0:
         tags.sort()
         for tag in tags:
             version_id = tagMap[tag]
             inv_tag_map[version_id] = tag
             action = mashuptrail.actionMap[version_id]
             mashup = mashuptrail.getMashup(version_id)
             mashup.name = tag
             #make sure we identify a mashup by its version
             mashup.id = action.id
             entity_key = (mashuptrail.id, version_id)
             self.mshp_entity_map[entity_key] = \
                self.create_mashup_entity(mashuptrail.id, mashup, action)
             added_entry_keys.add(entity_key)
             # get thumbnail for the workflow it points
             thumb_version = mashuptrail.vtVersion
             thumbnail = self.vistrail.get_thumbnail(thumb_version)
             if thumbnail is not None:
                 cache = ThumbnailCache.getInstance()
                 path = cache.get_abs_name_entry(thumbnail)
                 if path:
                     entity = ThumbnailEntity(path)
                     mshp_entity = self.mshp_entity_map[entity_key]
                     mshp_entity.children.append(entity)
                     entity.parent = mshp_entity
     return inv_tag_map
Beispiel #10
0
 def add_mashup_entity(self, mashuptrail, version_id, tag=None):
     if not hasattr(self.vistrail, 'mashups'):
         return
     if mashuptrail not in self.vistrail.mashups:
         return
     action = mashuptrail.actionMap[version_id]
     mashup = mashuptrail.getMashup(version_id)
     if tag:
         mashup.name = tag
     mashup.id = action.id
     entity_key = (mashuptrail.id, version_id)
     self.mshp_entity_map[entity_key] = \
                self.create_mashup_entity(mashuptrail.id, mashup, action)
     # get thumbnail for the workflow it points
     thumb_version = mashuptrail.vtVersion
     thumbnail = self.vistrail.get_thumbnail(thumb_version)
     if thumbnail is not None:
         cache = ThumbnailCache.getInstance()
         path = cache.get_abs_name_entry(thumbnail)
         if path:
             entity = ThumbnailEntity(path)
             mshp_entity = self.mshp_entity_map[entity_key]
             mshp_entity.children.append(entity)
             entity.parent = mshp_entity
     return self.mshp_entity_map[entity_key]
Beispiel #11
0
    def updateVersion(self, versionNumber):
        """ updateVersion(versionNumber: int) -> None

        """
        if self.controller:
            vistrail = self.controller.vistrail
            if versionNumber in vistrail.actionMap.keys():
                # Follow upgrades forward to find a thumbnail
                thumb_ver = self.controller.vistrail.search_upgrade_versions(
                        versionNumber,
                        lambda vt, v, bv: v if vt.has_thumbnail(v) else None)
                if thumb_ver is not None:
                    action = vistrail.actionMap[thumb_ver]
                    if vistrail.has_thumbnail(action.id):
                        cache = ThumbnailCache.getInstance()
                        fname = cache.get_abs_name_entry(
                            vistrail.get_thumbnail(action.id))
                        if fname is not None:
                            pixmap = QtGui.QPixmap(fname)
                            self.thumbs.setPixmap(pixmap)
                            self.thumbs.adjustSize()
                        self.thumbs.setFrameShape(QtGui.QFrame.StyledPanel)
                        return

        self.thumbs.setPixmap(QtGui.QPixmap())
        self.thumbs.setFrameShape(QtGui.QFrame.NoFrame)
    def save_vistrail(self, locator_class,
                      vistrailView=None,
                      force_choose_locator=False):
        """

        force_choose_locator=True triggers 'save as' behavior
        """
        global bobo

        if not vistrailView:
            vistrailView = self.currentWidget()
        vistrailView.flush_changes()
        if vistrailView:
            gui_get = locator_class.save_from_gui
            # get a locator to write to
            if force_choose_locator:
                locator = gui_get(self, Vistrail.vtType,
                                  vistrailView.controller.locator)
            else:
                locator = (vistrailView.controller.locator or
                           gui_get(self, Vistrail.vtType,
                                   vistrailView.controller.locator))
            if locator == untitled_locator():
                locator = gui_get(self, Vistrail.vtType,
                                  vistrailView.controller.locator)
            # if couldn't get one, ignore the request
            if not locator:
                return False
            # update collection
            vistrailView.controller.flush_delayed_actions()
            try:
                vistrailView.controller.write_vistrail(locator)
            except Exception, e:
                debug.critical('An error has occurred', str(e))
                raise
                return False
            try:
                thumb_cache = ThumbnailCache.getInstance()
                vistrailView.controller.vistrail.thumbnails = \
                    vistrailView.controller.find_thumbnails(
                        tags_only=thumb_cache.conf.tagsOnly)
                vistrailView.controller.vistrail.abstractions = \
                    vistrailView.controller.find_abstractions(
                        vistrailView.controller.vistrail, True)

                collection = Collection.getInstance()
                url = locator.to_url()
                # create index if not exist
                entity = collection.fromUrl(url)
                if entity:
                    # find parent vistrail
                    while entity.parent:
                        entity = entity.parent 
                else:
                    entity = collection.updateVistrail(url, vistrailView.controller.vistrail)
                # add to relevant workspace categories
                collection.add_to_workspace(entity)
                collection.commit()
            except Exception, e:
                debug.critical('Failed to index vistrail', str(e))
Beispiel #13
0
 def save_as(self, save_bundle, version=None):
     save_bundle = _DBLocator.save(self, save_bundle, True, version)
     for obj in save_bundle.get_db_objs():
         klass = self.get_convert_klass(obj.vtType)
         klass.convert(obj)
         obj.locator = self
     # Need to copy images into thumbnail cache directory so references
     # won't become invalid if they are in a temp dir that gets destroyed
     # when the previous locator is closed
     import shutil
     thumb_cache = ThumbnailCache.getInstance()
     thumb_cache_dir = thumb_cache.get_directory()
     new_thumbnails = []
     for thumbnail in save_bundle.thumbnails:
         if os.path.dirname(thumbnail) == thumb_cache_dir:
             new_thumbnails.append(thumbnail)
         else:
             cachedir_thumbnail = os.path.join(thumb_cache_dir,
                                               os.path.basename(thumbnail))
             try:
                 shutil.copyfile(thumbnail, cachedir_thumbnail)
                 new_thumbnails.append(cachedir_thumbnail)
             except Exception, e:
                 debug.critical(
                     "copying %s -> %s failed" %
                     (thumbnail, cachedir_thumbnail), e)
Beispiel #14
0
    def add_workflow_entity(self, version_id):
        if version_id not in self.vistrail.actionMap:
            return
        action = self.vistrail.actionMap[version_id]
        tag = None
        if self.vistrail.has_tag(version_id):
            tag = self.vistrail.get_tag(version_id)
        try:
            workflow = self.vistrail.getPipeline(version_id)
        except:
            import traceback
            debug.critical("Failed to construct pipeline '%s'" % 
                               (tag if tag else version_id),
                           traceback.format_exc())
            workflow = self.vistrail.getPipeline(0)
        if tag:
            workflow.name = tag
        # if workflow already exists, we want to update it...
        # spin through self.children and look for matching
        # workflow entity?
        # self.children.append(WorkflowEntity(workflow))
        self.wf_entity_map[version_id] = \
            self.create_workflow_entity(workflow, action)

        # get thumbnail
        thumbnail = self.vistrail.get_thumbnail(version_id)
        if thumbnail is not None:
            cache = ThumbnailCache.getInstance()
            path = cache.get_abs_name_entry(thumbnail)
            if path:
                entity = ThumbnailEntity(path)
                self.wf_entity_map[action.id].children.append(entity)
                entity.parent = self.wf_entity_map[action.id]
        return self.wf_entity_map[version_id]
Beispiel #15
0
 def save_as(self, save_bundle, version=None):
     save_bundle = _DBLocator.save(self, save_bundle, True, version)
     for obj in save_bundle.get_db_objs():
         klass = self.get_convert_klass(obj.vtType)
         klass.convert(obj)
         obj.locator = self
     # Need to copy images into thumbnail cache directory so references
     # won't become invalid if they are in a temp dir that gets destroyed
     # when the previous locator is closed
     import shutil
     thumb_cache = ThumbnailCache.getInstance()
     thumb_cache_dir = thumb_cache.get_directory()
     new_thumbnails = []
     for thumbnail in save_bundle.thumbnails:
         if os.path.dirname(thumbnail) == thumb_cache_dir:
             new_thumbnails.append(thumbnail)
         else:
             cachedir_thumbnail = os.path.join(thumb_cache_dir, os.path.basename(thumbnail))
             try:
                 shutil.copyfile(thumbnail, cachedir_thumbnail)
                 new_thumbnails.append(cachedir_thumbnail)
             except Exception, e:
                 debug.critical("copying %s -> %s failed" % (
                                thumbnail, cachedir_thumbnail),
                                e)
Beispiel #16
0
 def add_mashup_entity(self, mashuptrail, version_id, tag=None):
     if not hasattr(self.vistrail, 'mashups'):
         return
     if mashuptrail not in self.vistrail.mashups:
         return
     action = mashuptrail.actionMap[version_id]
     mashup = mashuptrail.getMashup(version_id)
     if tag:
         mashup.name = tag
     mashup.id = action.id
     entity_key = (mashuptrail.id,version_id)
     self.mshp_entity_map[entity_key] = \
                self.create_mashup_entity(mashuptrail.id, mashup, action)
     # get thumbnail for the workflow it points
     thumb_version = mashuptrail.vtVersion
     thumbnail = self.vistrail.get_thumbnail(thumb_version)
     if thumbnail is not None:
         cache = ThumbnailCache.getInstance()
         path = cache.get_abs_name_entry(thumbnail)
         if path:
             entity = ThumbnailEntity(path)
             mshp_entity = self.mshp_entity_map[entity_key]
             mshp_entity.children.append(entity)
             entity.parent = mshp_entity
     return self.mshp_entity_map[entity_key]
Beispiel #17
0
 def add_mashup_entities_from_mashuptrail(self, mashuptrail):
     added_entry_keys = set()
     inv_tag_map = {}
     tagMap = mashuptrail.getTagMap()
     tags = tagMap.keys()
     if len(tags) > 0:
         tags.sort()
         for tag in tags:
             version_id = tagMap[tag]
             inv_tag_map[version_id] = tag
             action = mashuptrail.actionMap[version_id]
             mashup = mashuptrail.getMashup(version_id)
             mashup.name = tag
             #make sure we identify a mashup by its version
             mashup.id = action.id
             entity_key = (mashuptrail.id,version_id)
             self.mshp_entity_map[entity_key] = \
                self.create_mashup_entity(mashuptrail.id, mashup, action)
             added_entry_keys.add(entity_key)
             # get thumbnail for the workflow it points
             thumb_version = mashuptrail.vtVersion
             thumbnail = self.vistrail.get_thumbnail(thumb_version)
             if thumbnail is not None:
                 cache = ThumbnailCache.getInstance()
                 path = cache.get_abs_name_entry(thumbnail)
                 if path:
                     entity = ThumbnailEntity(path)
                     mshp_entity = self.mshp_entity_map[entity_key]
                     mshp_entity.children.append(entity)
                     entity.parent = mshp_entity
     return inv_tag_map
Beispiel #18
0
    def updateVersion(self, versionNumber):
        """ updateVersion(versionNumber: int) -> None

        """
        if self.controller:
            vistrail = self.controller.vistrail
            if versionNumber in vistrail.actionMap.keys():
                # Follow upgrades forward to find a thumbnail
                thumb_ver = self.controller.vistrail.search_upgrade_versions(
                    versionNumber, lambda vt, v, bv: v
                    if vt.has_thumbnail(v) else None)
                if thumb_ver is not None:
                    action = vistrail.actionMap[thumb_ver]
                    if vistrail.has_thumbnail(action.id):
                        cache = ThumbnailCache.getInstance()
                        fname = cache.get_abs_name_entry(
                            vistrail.get_thumbnail(action.id))
                        if fname is not None:
                            pixmap = QtGui.QPixmap(fname)
                            self.thumbs.setPixmap(pixmap)
                            self.thumbs.adjustSize()
                        self.thumbs.setFrameShape(QtGui.QFrame.StyledPanel)
                        return

        self.thumbs.setPixmap(QtGui.QPixmap())
        self.thumbs.setFrameShape(QtGui.QFrame.NoFrame)
Beispiel #19
0
    def __init__(self, parent, persistent_config, temp_config):
        """
        QThumbnailConfiguration(parent: QWidget, 
        configuration_object: ConfigurationObject) -> None

        """
        QtGui.QWidget.__init__(self, parent)
        self._configuration = None
        self._temp_configuration = None
        self._cache = ThumbnailCache.getInstance()
        self.create_widgets()
        self.update_state(persistent_config, temp_config)
        self.connect_signals()
Beispiel #20
0
 def update(self, thumbnail):
     self.thumbnail = thumbnail
     if self.thumbnail is not None:
         # store in cache if not already there
         cache = ThumbnailCache.getInstance()
         cache._copy_thumbnails([thumbnail])
         self.name = os.path.basename(thumbnail)
         statinfo = os.stat(self.thumbnail)
         self.user = statinfo[stat.ST_UID]
         self.size = statinfo[stat.ST_SIZE]
         time = datetime(*localtime(statinfo[stat.ST_MTIME])[:6])
         self.mod_time = time
         self.create_time = time
         self.description = ""
         self.url = 'test'
         self.was_updated = True
Beispiel #21
0
 def load(self, klass=None):
     from vistrails.core.vistrail.vistrail import Vistrail
     if klass is None:
         klass = Vistrail
     save_bundle = _DBLocator.load(self, klass.vtType, ThumbnailCache.getInstance().get_directory())
     if klass.vtType == DBWorkflow.vtType:
         wf = save_bundle
         klass = self.get_convert_klass(wf.vtType)
         klass.convert(wf)
         wf.locator = self
         return wf
     for obj in save_bundle.get_db_objs():
         klass = self.get_convert_klass(obj.vtType)
         klass.convert(obj)
         obj.locator = self
     return save_bundle
Beispiel #22
0
 def update(self, thumbnail):
     self.thumbnail = thumbnail
     if self.thumbnail is not None:
         # store in cache if not already there
         cache = ThumbnailCache.getInstance()
         cache._copy_thumbnails([thumbnail])
         self.name = os.path.basename(thumbnail)
         statinfo = os.stat(self.thumbnail)
         self.user = statinfo[stat.ST_UID]
         self.size = statinfo[stat.ST_SIZE]
         time = datetime(*localtime(statinfo[stat.ST_MTIME])[:6])
         self.mod_time = time
         self.create_time = time
         self.description = ""
         self.url = "test"
         self.was_updated = True
Beispiel #23
0
 def add_parameter_exploration_entity(self, pe):
     if not hasattr(self.vistrail, 'parameter_explorations'):
         return
     self.pe_entity_map[pe.name] = \
                self.create_parameter_exploration_entity(pe)
     # get thumbnail for the workflow it points
     thumbnail = self.vistrail.get_thumbnail(pe.action_id)
     if thumbnail is not None:
         cache = ThumbnailCache.getInstance()
         path = cache.get_abs_name_entry(thumbnail)
         if path:
             entity = ThumbnailEntity(path)
             pe_entity = self.pe_entity_map[pe.name]
             pe_entity.children.append(entity)
             entity.parent = self
     return self.pe_entity_map[pe.name]
Beispiel #24
0
 def add_parameter_exploration_entity(self, pe):
     if not hasattr(self.vistrail, 'parameter_explorations'):
         return
     self.pe_entity_map[pe.name] = \
                self.create_parameter_exploration_entity(pe)
     # get thumbnail for the workflow it points
     thumbnail = self.vistrail.get_thumbnail(pe.action_id)
     if thumbnail is not None:
         cache = ThumbnailCache.getInstance()
         path = cache.get_abs_name_entry(thumbnail)
         if path:
             entity = ThumbnailEntity(path)
             pe_entity = self.pe_entity_map[pe.name]
             pe_entity.children.append(entity)
             entity.parent = self
     return self.pe_entity_map[pe.name]
Beispiel #25
0
 def load(self, klass=None):
     from vistrails.core.vistrail.vistrail import Vistrail
     if klass is None:
         klass = Vistrail
     save_bundle = _DBLocator.load(
         self, klass.vtType,
         ThumbnailCache.getInstance().get_directory())
     if klass.vtType == DBWorkflow.vtType:
         wf = save_bundle
         klass = self.get_convert_klass(wf.vtType)
         klass.convert(wf)
         wf.locator = self
         return wf
     for obj in save_bundle.get_db_objs():
         klass = self.get_convert_klass(obj.vtType)
         klass.convert(obj)
         obj.locator = self
     return save_bundle
Beispiel #26
0
    def open_vistrail(self, locator=None, version=None, is_abstraction=False):
        if isinstance(locator, basestring):
            locator = BaseLocator.from_url(locator)
        elif locator is None:
            locator = UntitledLocator()

        controller = self.ensure_vistrail(locator)
        if controller is None:
            # vistrail is not already open
            try:
                loaded_objs = vistrails.core.db.io.load_vistrail(
                    locator, is_abstraction)
                controller = self.add_vistrail(loaded_objs[0], locator,
                                               *loaded_objs[1:])
                if locator.is_untitled():
                    return controller
                controller.is_abstraction = is_abstraction
                thumb_cache = ThumbnailCache.getInstance()
                controller.vistrail.thumbnails = controller.find_thumbnails(
                    tags_only=thumb_cache.conf.tagsOnly)
                controller.vistrail.abstractions = controller.find_abstractions(
                    controller.vistrail, True)
                controller.vistrail.mashups = controller._mashups
                collection = Collection.getInstance()
                url = locator.to_url()
                entity = collection.updateVistrail(url, controller.vistrail)
                # add to relevant workspace categories
                if not controller.is_abstraction:
                    collection.add_to_workspace(entity)
                collection.commit()
            except VistrailsDBException as e:
                debug.unexpected_exception(e)
                debug.critical("Exception from the database: %s" % e,
                               debug.format_exc())
                return None

        version = self.convert_version(version)
        if version is None:
            controller.select_latest_version()
            version = controller.current_version
        self.select_version(version)
        return controller
Beispiel #27
0
    def open_vistrail(self, locator=None, version=None, is_abstraction=False):
        if isinstance(locator, basestring):
            locator = BaseLocator.from_url(locator)
        elif locator is None:
            locator = UntitledLocator()

        controller = self.ensure_vistrail(locator)
        if controller is None:
            # vistrail is not already open
            try:
                loaded_objs = vistrails.core.db.io.load_vistrail(locator, is_abstraction)
                controller = self.add_vistrail(loaded_objs[0], locator, 
                                               *loaded_objs[1:])
                if locator.is_untitled():
                    return controller
                controller.is_abstraction = is_abstraction
                thumb_cache = ThumbnailCache.getInstance()
                controller.vistrail.thumbnails = controller.find_thumbnails(
                    tags_only=thumb_cache.conf.tagsOnly)
                controller.vistrail.abstractions = controller.find_abstractions(
                    controller.vistrail, True)
                controller.vistrail.mashups = controller._mashups
                collection = Collection.getInstance()
                url = locator.to_url()
                entity = collection.updateVistrail(url, controller.vistrail)
                # add to relevant workspace categories
                if not controller.is_abstraction:
                    collection.add_to_workspace(entity)
                collection.commit()
            except VistrailsDBException as e:
                debug.unexpected_exception(e)
                debug.critical("Exception from the database: %s" % e,
                               debug.format_exc())
                return None

        version = self.convert_version(version)
        if version is None:
            controller.select_latest_version()
            version = controller.current_version
        self.select_version(version)
        return controller
Beispiel #28
0
    def updateVersion(self, versionNumber):
        """ updateVersion(versionNumber: int) -> None

        """
        if self.controller:
            vistrail = self.controller.vistrail
            if versionNumber in vistrail.actionMap.keys():
                action = vistrail.actionMap[versionNumber]
                if action and vistrail.has_thumbnail(action.id):
                    cache = ThumbnailCache.getInstance()
                    fname = cache.get_abs_name_entry(
                        vistrail.get_thumbnail(action.id))
                    if fname is not None:
                        pixmap = QtGui.QPixmap(fname)
                        self.thumbs.setPixmap(pixmap)
                        self.thumbs.adjustSize()
                    self.thumbs.setFrameShape(QtGui.QFrame.StyledPanel)
                    return
                
        self.thumbs.setPixmap(QtGui.QPixmap())
        self.thumbs.setFrameShape(QtGui.QFrame.NoFrame)
Beispiel #29
0
    def open_vistrail(self, locator=None, version=None, is_abstraction=False):
        if isinstance(locator, basestring):
            locator = BaseLocator.from_url(locator)
        elif locator is None:
            locator = UntitledLocator()

        controller = self.ensure_vistrail(locator)
        if controller is None:
            # vistrail is not already open
            try:
                loaded_objs = vistrails.core.db.io.load_vistrail(locator, False)
                controller = self.add_vistrail(loaded_objs[0], locator, 
                                               *loaded_objs[1:])
                if locator.is_untitled():
                    return True
                controller.is_abstraction = is_abstraction
                thumb_cache = ThumbnailCache.getInstance()
                controller.vistrail.thumbnails = controller.find_thumbnails(
                    tags_only=thumb_cache.conf.tagsOnly)
                controller.vistrail.abstractions = controller.find_abstractions(
                    controller.vistrail, True)
                controller.vistrail.mashups = controller._mashups
                collection = Collection.getInstance()
                url = locator.to_url()
                entity = collection.updateVistrail(url, controller.vistrail)
                # add to relevant workspace categories
                if not controller.is_abstraction:
                    collection.add_to_workspace(entity)
                collection.commit()
            except VistrailsDBException, e:
                import traceback
                debug.critical("Exception from the database",
                               traceback.format_exc())
                return None
            except Exception, e:
                #debug.critical('An error has occurred', e)
                #print "An error has occurred", str(e)
                raise
Beispiel #30
0
class VistrailEntity(Entity):
    type_id = 1

    def __init__(self, vistrail=None):
        Entity.__init__(self)
        self.id = None
        self.wf_entity_map = {}
        self.mshp_entity_map = {}
        self.pe_entity_map = {}
        self.wf_exec_entity_map = {}
        self._vt_tag_map = {}
        self._mshp_tag_map = {}
        # self._last_wf_exec_id = None
        self.reload(vistrail)

    @staticmethod
    def create(*args):
        entity = VistrailEntity()
        entity.load(*args)
        return entity

    def create_workflow_entity(self, workflow, action):
        entity = WorkflowEntity(workflow)
        self.children.append(entity)
        entity.parent = self
        if self.vistrail.has_notes(action.id):
            plain_notes = extract_text(self.vistrail.get_notes(action.id))
            entity.description = plain_notes
        else:
            entity.description = ''
        entity.user = action.user
        entity.mod_time = action.db_date
        entity.create_time = action.db_date
        locator = BaseLocator.from_url(self.url)
        locator.kwargs['version_node'] = action.id
        entity.url = locator.to_url()
        return entity

    def create_mashup_entity(self, trail_id, mashup, action):
        entity = MashupEntity(mashup)
        self.children.append(entity)
        entity.parent = self
        vt_version = mashup.version
        if self.vistrail.has_notes(vt_version):
            plain_notes = extract_text(self.vistrail.get_notes(vt_version))
            entity.description = plain_notes
        else:
            entity.description = ''
        entity.user = action.user
        entity.mod_time = action.db_date
        entity.create_time = action.db_date
        locator = BaseLocator.from_url(self.url)
        locator.kwargs['mashuptrail'] = trail_id
        locator.kwargs['mashup'] = action.id
        entity.url = locator.to_url()
        return entity

    def create_parameter_exploration_entity(self, pe):
        entity = ParameterExplorationEntity(pe)
        self.children.append(entity)
        entity.parent = self
        entity.name = pe.name
        if pe.name:
            entity.name = pe.name
        else:
            # find logical name using vistrail tag
            entity.name = "Latest for " + \
                          self.vistrail.get_pipeline_name(pe.action_id)
        locator = BaseLocator.from_url(self.url)
        locator.kwargs['parameterExploration'] = pe.id
        entity.url = locator.to_url()
        return entity

    def create_wf_exec_entity(self, wf_exec, wf_entity):
        entity = WorkflowExecEntity(wf_exec)
        wf_entity.children.append(entity)
        entity.parent = wf_entity
        locator = BaseLocator.from_url(self.url)
        locator.kwargs['workflow_exec'] = entity.name
        entity.url = locator.to_url()
        return entity

    def get_vistrail_info(self, vistrail=None):
        if vistrail is None:
            vistrail = self.vistrail
        name = None
        if vistrail.locator:
            name = vistrail.locator.short_name
        if name is None:
            if vistrail.db_name:
                name = vistrail.db_name
            else:
                name = u"untitled"

        size = vistrail.get_version_count()
        if size < 1:
            # empty vistrail
            user = vistrails.core.system.current_user()
            mod_time = vistrails.core.system.current_time()
            create_time = vistrails.core.system.current_time()
        else:
            latestVersionId = vistrail.get_latest_version()
            latestVersion = vistrail.actionMap[latestVersionId]
            user = latestVersion.user
            mod_time = latestVersion.db_date
            # FIXME: relies on 1 being the first version...
            firstVersion = vistrail.actionMap[1] \
                if 1 in vistrail.actionMap else latestVersion
            create_time = firstVersion.db_date
        url = vistrail.locator.to_url() if vistrail.locator else "untitled:"
        return (name, size, user, mod_time, create_time, url)

    def set_vistrail(self, vistrail):
        self.vistrail = vistrail

        (self.name, self.size, self.user, self.mod_time, self.create_time, \
             self.url) = self.get_vistrail_info()
        self.description = ""
        self.was_updated = True

    def add_workflow_entity(self, version_id):
        if version_id not in self.vistrail.actionMap:
            return
        action = self.vistrail.actionMap[version_id]
        tag = None
        if self.vistrail.has_tag(version_id):
            tag = self.vistrail.get_tag(version_id)
        try:
            workflow = self.vistrail.getPipeline(version_id)
        except Exception, e:
            debug.unexpected_exception(e)
            debug.critical(
                "Failed to construct pipeline '%s'" %
                (tag if tag else version_id), debug.format_exc())
            workflow = self.vistrail.getPipeline(0)
        if tag:
            workflow.name = tag
        # if workflow already exists, we want to update it...
        # spin through self.children and look for matching
        # workflow entity?
        # self.children.append(WorkflowEntity(workflow))
        self.wf_entity_map[version_id] = \
            self.create_workflow_entity(workflow, action)

        # get thumbnail
        thumbnail = self.vistrail.get_thumbnail(version_id)
        if thumbnail is not None:
            cache = ThumbnailCache.getInstance()
            path = cache.get_abs_name_entry(thumbnail)
            if path:
                entity = ThumbnailEntity(path)
                self.wf_entity_map[action.id].children.append(entity)
                entity.parent = self.wf_entity_map[action.id]
        return self.wf_entity_map[version_id]
Beispiel #31
0
        old_locator = controller.locator

        controller.flush_delayed_actions()
        try:
            controller.write_vistrail(locator, export=export)
        except Exception, e:
            debug.unexpected_exception(e)
            debug.critical("Failed to save vistrail", debug.format_exc())
            raise
        if export:
            return controller.locator

        self.update_locator(old_locator, controller.locator)
        # update collection
        try:
            thumb_cache = ThumbnailCache.getInstance()
            controller.vistrail.thumbnails = controller.find_thumbnails(
                tags_only=thumb_cache.conf.tagsOnly)
            controller.vistrail.abstractions = controller.find_abstractions(
                controller.vistrail, True)
            controller.vistrail.mashups = controller._mashups

            collection = Collection.getInstance()
            url = locator.to_url()
            entity = collection.updateVistrail(url, controller.vistrail)
            # add to relevant workspace categories
            collection.add_to_workspace(entity)
            collection.commit()
        except Exception, e:
            debug.critical('Failed to index vistrail', debug.format_exc())
        return controller.locator
Beispiel #32
0
        old_locator = controller.locator

        controller.flush_delayed_actions()
        try:
            controller.write_vistrail(locator, export=export)
        except Exception, e:
            debug.unexpected_exception(e)
            debug.critical("Failed to save vistrail", traceback.format_exc())
            raise
        if export:
            return controller.locator

        self.update_locator(old_locator, controller.locator)
        # update collection
        try:
            thumb_cache = ThumbnailCache.getInstance()
            controller.vistrail.thumbnails = controller.find_thumbnails(
                tags_only=thumb_cache.conf.tagsOnly)
            controller.vistrail.abstractions = controller.find_abstractions(
                controller.vistrail, True)
            controller.vistrail.mashups = controller._mashups

            collection = Collection.getInstance()
            url = locator.to_url()
            entity = collection.updateVistrail(url, controller.vistrail)
            # add to relevant workspace categories
            collection.add_to_workspace(entity)
            collection.commit()
        except Exception, e:
            debug.critical('Failed to index vistrail', traceback.format_exc())
        return controller.locator