Example #1
0
 def __init__(self, arg=None):
     initialize()
     if arg is None:
         # Copied from VistrailsApplicationInterface#open_vistrail()
         locator = UntitledLocator()
         loaded_objs = vistrails.core.db.io.load_vistrail(locator)
         self.controller = VistrailController(loaded_objs[0], locator,
                                              *loaded_objs[1:])
     elif isinstance(arg, (_Pipeline, Pipeline)):
         if isinstance(arg, Pipeline):
             pipeline = arg.pipeline
         else:
             pipeline = arg
         # Copied from VistrailsApplicationInterface#open_workflow()
         vistrail = _Vistrail()
         ops = []
         for module in pipeline.module_list:
             ops.append(('add', module))
         for connection in pipeline.connection_list:
             ops.append(('add', connection))
         action = vistrails.core.db.action.create_action(ops)
         vistrail.add_action(action, 0L)
         vistrail.update_id_scope()
         vistrail.change_description("Imported pipeline", 0L)
         self.controller = VistrailController(vistrail, UntitledLocator())
     elif isinstance(arg, VistrailController):
         self.controller = arg
     elif isinstance(arg, basestring):
         raise TypeError("Vistrail was constructed from %r.\n"
                         "Use load_vistrail() to get a Vistrail from a "
                         "file." % type(arg).__name__)
     else:
         raise TypeError("Vistrail was constructed from unexpected "
                         "argument type %r" % type(arg).__name__)
Example #2
0
    def open_workflow(self, locator):
        if isinstance(locator, basestring):
            locator = BaseLocator.from_url(locator)

        new_locator = UntitledLocator()
        controller = self.open_vistrail(new_locator)
        try:
            if locator is None:
                return False
            workflow = locator.load(Pipeline)
            action_list = []
            for module in workflow.module_list:
                action_list.append(('add', module))
            for connection in workflow.connection_list:
                action_list.append(('add', connection))
            action = vistrails.core.db.action.create_action(action_list)
            controller.add_new_action(action)
            controller.perform_action(action)
            controller.vistrail.set_tag(action.id, "Imported workflow")
            controller.change_selected_version(action.id)
        except VistrailsDBException:
            debug.critical("Exception from the database", debug.format_exc())
            return None

        controller.select_latest_version()
        controller.set_changed(True)
        return controller
Example #3
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
Example #4
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
Example #5
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