Example #1
0
 def get_wsdl_from_namespace(m_namespace):
     try:
         wsdl = m_namespace.split("|")
         return wsdl[0]
     except Exception, e:
         debug.unexpected_exception(e)
         return None
Example #2
0
 def compute(self):
     # create dict of inputs
     cacheable = False
     if self.has_input('cacheable'):
         cacheable = self.get_input('cacheable')
     self.is_cacheable = lambda *args, **kwargs: cacheable            
     params = {}
     mname = self.wsmethod.qname[0]
     for name in self.wsmethod.inputs:
         name = str(name)
         if self.has_input(name):
             params[name] = self.get_input(name)
             if params[name].__class__.__name__ == 'UberClass':
                 params[name] = params[name].value
             params[name] = self.service.makeDictType(params[name])
     try:
         #import logging
         #logging.basicConfig(level=logging.INFO)
         #logging.getLogger('suds.client').setLevel(logging.DEBUG)
         #print "params:", str(params)[:400]
         #self.service.service.set_options(retxml = True)
         #result = getattr(self.service.service.service, mname)(**params)
         #print "result:", str(result)[:400]
         #self.service.service.set_options(retxml = False)
         result = getattr(self.service.service.service, mname)(**params)
     except Exception, e:
         debug.unexpected_exception(e)
         raise ModuleError(self, "Error invoking method %s: %s" % (
                 mname, debug.format_exception(e)))
Example #3
0
 def compute(self):
     # create dict of inputs
     cacheable = False
     if self.has_input('cacheable'):
         cacheable = self.get_input('cacheable')
     self.is_cacheable = lambda *args, **kwargs: cacheable
     params = {}
     mname = self.wsmethod.qname[0]
     for name in self.wsmethod.inputs:
         name = str(name)
         if self.has_input(name):
             params[name] = self.get_input(name)
             if params[name].__class__.__name__ == 'UberClass':
                 params[name] = params[name].value
             params[name] = self.service.makeDictType(params[name])
     try:
         #import logging
         #logging.basicConfig(level=logging.INFO)
         #logging.getLogger('suds.client').setLevel(logging.DEBUG)
         #print "params:", str(params)[:400]
         #self.service.service.set_options(retxml = True)
         #result = getattr(self.service.service.service, mname)(**params)
         #print "result:", str(result)[:400]
         #self.service.service.set_options(retxml = False)
         result = getattr(self.service.service.service,
                          mname)(**params)
     except Exception, e:
         debug.unexpected_exception(e)
         raise ModuleError(
             self, "Error invoking method %s: %s" %
             (mname, debug.format_exception(e)))
Example #4
0
 def get_wsdl_from_namespace(m_namespace):
     try:
         wsdl = m_namespace.split("|")
         return wsdl[0]
     except Exception, e:
         debug.unexpected_exception(e)
         return None
Example #5
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 as e:
            debug.unexpected_exception(e)
            debug.critical("Exception from the database: %s" % e,
                           debug.format_exc())
            return None

        controller.select_latest_version()
        controller.set_changed(True)
        return controller
Example #6
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 as e:
            debug.unexpected_exception(e)
            debug.critical("Exception from the database: %s" % e,
                           debug.format_exc())
            return None

        controller.select_latest_version()
        controller.set_changed(True)
        return controller
Example #7
0
 def convert_version(self, version):
     if isinstance(version, basestring):
         try:
             version = \
                 self.get_controller().vistrail.get_version_number(version)
         except Exception, e:
             debug.unexpected_exception(e)
             version = None
Example #8
0
 def convert_version(self, version):
     if isinstance(version, basestring):
         try:
             version = \
                 self.get_controller().vistrail.get_version_number(version)
         except Exception, e:
             debug.unexpected_exception(e)
             version = None
Example #9
0
 def _convert_version(self, version):
     if isinstance(version, basestring):
         try:
             version = \
                 self.controller.vistrail.get_version_number(version)
         except Exception, e:
             debug.unexpected_exception(e)
             raise ValueError('Cannot locate version "%s"' % version)
Example #10
0
 def _convert_version(self, version):
     if isinstance(version, basestring):
         try:
             version = \
                 self.controller.vistrail.get_version_number(version)
         except Exception, e:
             debug.unexpected_exception(e)
             raise ValueError('Cannot locate version "%s"' % version)
Example #11
0
 def get_used_packages(self):
     package_list = {}
     for action in self.actions:
         for op in action.operations:
             try:
                 if isinstance(op, AddOp) and op.what == 'module':
                     package_list[op.data.package] = op.data.package
             except AttributeError, e:
                 debug.unexpected_exception(e)
Example #12
0
 def evaluate(i):
     try:
         v = d['value'](i)
         if v is None:
             return module.default_value
         return v
     except Exception, e:
         debug.unexpected_exception(e)
         return debug.format_exception(e)
Example #13
0
 def evaluate(i):
     try:
         v = d['value'](i)
         if v == None:
             return module.default_value
         return v
     except Exception, e:
         debug.unexpected_exception(e)
         return debug.format_exception(e)
Example #14
0
 def get_used_packages(self):
     package_list = {}
     for action in self.actions:
         for op in action.operations:
             try:
                 if isinstance(op, AddOp) and op.what == 'module':
                     package_list[op.data.package] = op.data.package
             except AttributeError, e:
                 debug.unexpected_exception(e)
Example #15
0
 def saveVistrailFileHook(self, vistrail, tmp_dir):
     if hasattr(self._init_module, 'saveVistrailFileHook'):
         try:
             self._init_module.saveVistrailFileHook(vistrail, tmp_dir)
         except Exception, e:
             debug.unexpected_exception(e)
             debug.critical("Got exception in %s's saveVistrailFileHook(): "
                            "%s\n%s" %
                            (self.name, debug.format_exception(e),
                             traceback.format_exc()))
Example #16
0
 def saveVistrailFileHook(self, vistrail, tmp_dir):
     if hasattr(self._init_module, 'saveVistrailFileHook'):
         try:
             self._init_module.saveVistrailFileHook(vistrail, tmp_dir)
         except Exception, e:
             debug.unexpected_exception(e)
             debug.critical("Got exception in %s's saveVistrailFileHook(): "
                            "%s\n%s" % (self.name,
                                        debug.format_exception(e),
                                        traceback.format_exc()))
Example #17
0
 def send_notification(self, notification_id, *args):
     # do global notifications
     if notification_id in self.notifications:
         # print 'global notification ', notification_id
         for m in self.notifications[notification_id]:
             try:
                 #print "  m: ", m
                 m(*args)
             except Exception, e:
                 debug.unexpected_exception(e)
                 traceback.print_exc()
Example #18
0
 def send_notification(self, notification_id, *args):
     # do global notifications
     if notification_id in self.notifications:
         # print 'global notification ', notification_id
         for m in self.notifications[notification_id]:
             try:
                 #print "  m: ", m
                 m(*args)
             except Exception, e:
                 debug.unexpected_exception(e)
                 debug.print_exc()
Example #19
0
 def runAndGetCellEvents(self, useDefaultValues=False):
     spreadsheetController.setEchoMode(True)
     #will run to get Spreadsheet Cell events
     cellEvents = []
     errors = []
     try:
         (res, errors) = self.run(useDefaultValues)
         if res:
             cellEvents = spreadsheetController.getEchoCellEvents()
     except Exception, e:
         debug.unexpected_exception(e)
         print "Executing pipeline failed:", debug.format_exc()
Example #20
0
 def runAndGetCellEvents(self, useDefaultValues=False):
     spreadsheetController.setEchoMode(True)
     # will run to get Spreadsheet Cell events
     cellEvents = []
     errors = []
     try:
         (res, errors) = self.run(useDefaultValues)
         if res:
             cellEvents = spreadsheetController.getEchoCellEvents()
     except Exception, e:
         debug.unexpected_exception(e)
         print "Executing pipeline failed:", debug.format_exc()
Example #21
0
 def can_handle_identifier(self, identifier):
     """ Asks package if it can handle this package
     """
     try:
         return (hasattr(self.init_module, 'can_handle_identifier') and
                 self.init_module.can_handle_identifier(identifier))
     except Exception, e:
         debug.unexpected_exception(e)
         debug.critical("Got exception calling %s's can_handle_identifier: "
                        "%s\n%s" % (self.name,
                                    debug.format_exception(e),
                                    traceback.format_exc()))
         return False
Example #22
0
 def menu_items(self):
     try:
         callable_ = self._module.menu_items
     except AttributeError:
         return None
     else:
         try:
             return callable_()
         except Exception, e:
             debug.unexpected_exception(e)
             debug.critical("Couldn't load menu items for %s: %s\n%s" % (
                            self.name, debug.format_exception(e),
                            traceback.format_exc()))
Example #23
0
 def can_handle_vt_file(self, name):
     """ Asks package if it can handle a file inside a zipped vt file
     """
     try:
         return (hasattr(self.init_module, 'can_handle_vt_file') and
                 self.init_module.can_handle_vt_file(name))
     except Exception, e:
         debug.unexpected_exception(e)
         debug.critical("Got exception calling %s's can_handle_vt_file: "
                        "%s\n%s" % (self.name,
                                    debug.format_exception(e),
                                    traceback.format_exc()))
         return False
Example #24
0
 def can_handle_identifier(self, identifier):
     """ Asks package if it can handle this package
     """
     try:
         return (hasattr(self.init_module, 'can_handle_identifier')
                 and self.init_module.can_handle_identifier(identifier))
     except Exception, e:
         debug.unexpected_exception(e)
         debug.critical(
             "Got exception calling %s's can_handle_identifier: "
             "%s\n%s" %
             (self.name, debug.format_exception(e), traceback.format_exc()))
         return False
Example #25
0
 def menu_items(self):
     try:
         callable_ = self._module.menu_items
     except AttributeError:
         return None
     else:
         try:
             return callable_()
         except Exception, e:
             debug.unexpected_exception(e)
             debug.critical("Couldn't load menu items for %s: %s\n%s" %
                            (self.name, debug.format_exception(e),
                             traceback.format_exc()))
Example #26
0
 def can_handle_vt_file(self, name):
     """ Asks package if it can handle a file inside a zipped vt file
     """
     try:
         return (hasattr(self.init_module, 'can_handle_vt_file')
                 and self.init_module.can_handle_vt_file(name))
     except Exception, e:
         debug.unexpected_exception(e)
         debug.critical(
             "Got exception calling %s's can_handle_vt_file: "
             "%s\n%s" %
             (self.name, debug.format_exception(e), traceback.format_exc()))
         return False
Example #27
0
    def reload(self, vistrail):
        if vistrail is not None:
            self.set_vistrail(vistrail)

            for version_id in self.vistrail.get_tagMap():
                self.add_workflow_entity(version_id)
            
            #mashups
            if hasattr(self.vistrail, 'mashups'):
                self._mshp_tag_map = {}
                for mashuptrail in self.vistrail.mashups:
                    self._mshp_tag_map[mashuptrail.id] = \
                         self.add_mashup_entities_from_mashuptrail(mashuptrail)

            #parameter explorations
            if hasattr(self.vistrail, 'parameter_explorations'):
                self.pe_entity_map = {}
                # find named pe's
                #max_pe = {}
                for pe in self.vistrail.parameter_explorations:
                    if pe.name:
                        self.pe_entity_map[pe.name] = \
                             self.add_parameter_exploration_entity(pe)
                #    if pe.action_id not in max_pe or max_pe[pe.action_id]<pe.id:
                #        max_pe[pe.action_id] = pe

                #for pe in max_pe.values():
                #    if pe.id not in self.pe_entity_map:
                #        self.pe_entity_map[pe.id] = \
                #             self.add_parameter_exploration_entity(pe)
                
            # read persisted log entries
            log = None
            try:
                log = vistrail.get_persisted_log()
            except Exception, e:
                debug.unexpected_exception(e)
                import traceback
                debug.critical("Failed to read log", traceback.format_exc())
                
            if log is not None:
                for wf_exec in log.workflow_execs:
                    self.add_wf_exec_entity(wf_exec, False)

            # read unpersisted log entries
            if vistrail.log is not None:
                for wf_exec in self.vistrail.log.workflow_execs:
                    self.add_wf_exec_entity(wf_exec, True)

            self._vt_tag_map = copy.copy(self.vistrail.get_tagMap())
Example #28
0
def menu_items():
    """menu_items() -> tuple of (str,function)
    It returns a list of pairs containing text for the menu and a
    callback function that will be executed when that menu item is selected.
    
    """
    try:
        from wizard import QCLToolsWizardWindow
    except Exception, e: # pragma: no cover
        if "CLTools" == identifiers.name:
            debug.unexpected_exception(e)
            raise
        else:
            return
Example #29
0
def menu_items():
    """menu_items() -> tuple of (str,function)
    It returns a list of pairs containing text for the menu and a
    callback function that will be executed when that menu item is selected.
    
    """
    try:
        from wizard import QCLToolsWizardWindow
    except Exception, e:  # pragma: no cover
        if "CLTools" == identifiers.name:
            debug.unexpected_exception(e)
            raise
        else:
            return
Example #30
0
    def reload(self, vistrail):
        if vistrail is not None:
            self.set_vistrail(vistrail)

            for version_id in self.vistrail.get_tagMap():
                self.add_workflow_entity(version_id)

            #mashups
            if hasattr(self.vistrail, 'mashups'):
                self._mshp_tag_map = {}
                for mashuptrail in self.vistrail.mashups:
                    self._mshp_tag_map[mashuptrail.id] = \
                         self.add_mashup_entities_from_mashuptrail(mashuptrail)

            #parameter explorations
            if hasattr(self.vistrail, 'parameter_explorations'):
                self.pe_entity_map = {}
                # find named pe's
                #max_pe = {}
                for pe in self.vistrail.parameter_explorations:
                    if pe.name:
                        self.pe_entity_map[pe.name] = \
                             self.add_parameter_exploration_entity(pe)
                #    if pe.action_id not in max_pe or max_pe[pe.action_id]<pe.id:
                #        max_pe[pe.action_id] = pe

                #for pe in max_pe.values():
                #    if pe.id not in self.pe_entity_map:
                #        self.pe_entity_map[pe.id] = \
                #             self.add_parameter_exploration_entity(pe)

            # read persisted log entries
            log = None
            try:
                log = vistrail.get_persisted_log()
            except Exception, e:
                debug.unexpected_exception(e)
                debug.critical("Failed to read log", debug.format_exc())

            if log is not None:
                for wf_exec in log.workflow_execs:
                    self.add_wf_exec_entity(wf_exec, False)

            # read unpersisted log entries
            if vistrail.log is not None:
                for wf_exec in self.vistrail.log.workflow_execs:
                    self.add_wf_exec_entity(wf_exec, True)

            self._vt_tag_map = copy.copy(self.vistrail.get_tagMap())
Example #31
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 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)
Example #32
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 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)
Example #33
0
 def setParameterExplorationOld(self, xmlString):
     """ setParameterExploration(xmlString: string) -> None
     Sets the current parameter exploration to the one
     defined by 'xmlString'.
     
     """
     if not xmlString:
         return
     # Parse/validate the xml
     try:
         xmlDoc = parseString(xmlString).documentElement
     except Exception, e:
         debug.unexpected_exception(e)
         debug.critical("Parameter Exploration load failed because of "
                        "invalid XML:\n\n%s" % xmlString)
         return
Example #34
0
 def finalize(self):
     if not self._initialized:
         return
     debug.log("Finalizing %s" % self.name)
     try:
         callable_ = self._module.finalize
     except AttributeError:
         pass
     else:
         try:
             callable_()
         except Exception, e:
             debug.unexpected_exception(e)
             debug.critical("Couldn't finalize %s: %s\n%s" % (
                            self.name, debug.format_exception(e),
                            traceback.format_exc()))
Example #35
0
 def setParameterExplorationOld(self, xmlString):
     """ setParameterExploration(xmlString: string) -> None
     Sets the current parameter exploration to the one
     defined by 'xmlString'.
     
     """
     if not xmlString:
         return
     # Parse/validate the xml
     try:
         xmlDoc = parseString(xmlString).documentElement
     except Exception, e:
         debug.unexpected_exception(e)
         debug.critical("Parameter Exploration load failed because of "
                        "invalid XML:\n\n%s" % xmlString)
         return
Example #36
0
def current_ip():
    """ current_ip() -> str
    Gets current IP address trying to avoid the IPv6 interface """
    try:
        info = socket.getaddrinfo(socket.gethostname(), None)
        # Try to find an IPv4
        for i in info:
            if i[0] == socket.AF_INET:
                return i[4][0]
        # Return any address
        for i in info:
            if i[0] in (socket.AF_INET, socket.AF_INET6):
                return i[4][0]
    except Exception, e:
        debug.unexpected_exception(e)
        return ''
Example #37
0
 def finalize(self):
     if not self._initialized:
         return
     debug.log("Finalizing %s" % self.name)
     try:
         callable_ = self._module.finalize
     except AttributeError:
         pass
     else:
         try:
             callable_()
         except Exception, e:
             debug.unexpected_exception(e)
             debug.critical("Couldn't finalize %s: %s\n%s" %
                            (self.name, debug.format_exception(e),
                             traceback.format_exc()))
Example #38
0
def current_ip():
    """ current_ip() -> str
    Gets current IP address trying to avoid the IPv6 interface """
    try:
        info = socket.getaddrinfo(socket.gethostname(), None)
        # Try to find an IPv4
        for i in info:
            if i[0] == socket.AF_INET:
                return i[4][0]
        # Return any address
        for i in info:
            if i[0] in (socket.AF_INET, socket.AF_INET6):
                return i[4][0]
    except Exception, e:
        debug.unexpected_exception(e)
        return ''
Example #39
0
def load_from_signature(signature):
    """ Load wsdl from signature and return success status """
    wsdl = toAddress(signature)
    wsdlList = []
    if configuration.check('wsdlList'):
        wsdlList = configuration.wsdlList.split(";")
    if not wsdl in wsdlList:
        try:
            service = Service(wsdl)
        except Exception, e:
            debug.unexpected_exception(e)
            return False
        if not service.service:
            return False
        webServicesDict[wsdl] = service
        wsdlList.append(wsdl)
        configuration.wsdlList = ';'.join(wsdlList)
Example #40
0
def load_from_signature(signature):
    """ Load wsdl from signature and return success status """
    wsdl = toAddress(signature)
    wsdlList = []
    if configuration.check('wsdlList'):
        wsdlList = configuration.wsdlList.split(";")
    if not wsdl in wsdlList:
        try:
            service = Service(wsdl)
        except Exception, e:
            debug.unexpected_exception(e)
            return False
        if not service.service:
            return False
        webServicesDict[wsdl] = service
        wsdlList.append(wsdl)
        configuration.wsdlList = ';'.join(wsdlList)
Example #41
0
    def contextMenuEvent(self, event):
        """Just dispatches the menu event to the widget item"""
        item = self.itemAt(event.pos())
        if item:
            # find top level
            p = item
            while p.parent():
                p = p.parent()
            # get package identifier
            assert isinstance(p, QPackageTreeWidgetItem)
            identifier = p.identifier
            registry = get_module_registry()
            package = registry.packages[identifier]
            try:
                if package.has_context_menu():
                    if isinstance(item, QPackageTreeWidgetItem):
                        text = None
                    elif isinstance(item, QNamespaceTreeWidgetItem):
                        return  # no context menu for namespaces
                    elif isinstance(item, QModuleTreeWidgetItem):
                        text = item.descriptor.name
                        if item.descriptor.namespace:
                            text = '%s|%s' % (item.descriptor.namespace, text)
                    else:
                        assert False, "fell through"
                    menu_items = package.context_menu(text)
                    if menu_items:
                        menu = QtGui.QMenu(self)
                        for text, callback in menu_items:
                            act = QtGui.QAction(text, self)
                            act.setStatusTip(text)
                            QtCore.QObject.connect(act,
                                                   QtCore.SIGNAL("triggered()"),
                                                   callback)
                            menu.addAction(act)
                        menu.exec_(event.globalPos())
                    return
            except Exception, e:
                debug.unexpected_exception(e)
                debug.warning("Got exception trying to display %s's "
                              "context menu in the palette: %s\n%s" % (
                                  package.name,
                                  debug.format_exception(e),
                                  traceback.format_exc()))

            item.contextMenuEvent(event, self)
Example #42
0
    def contextMenuEvent(self, event):
        """Just dispatches the menu event to the widget item"""
        item = self.itemAt(event.pos())
        if item:
            # find top level
            p = item
            while p.parent():
                p = p.parent()
            # get package identifier
            assert isinstance(p, QPackageTreeWidgetItem)
            identifier = p.identifier
            registry = get_module_registry()
            package = registry.packages[identifier]
            try:
                if package.has_context_menu():
                    if isinstance(item, QPackageTreeWidgetItem):
                        text = None
                    elif isinstance(item, QNamespaceTreeWidgetItem):
                        return  # no context menu for namespaces
                    elif isinstance(item, QModuleTreeWidgetItem):
                        text = item.descriptor.name
                        if item.descriptor.namespace:
                            text = '%s|%s' % (item.descriptor.namespace, text)
                    else:
                        assert False, "fell through"
                    menu_items = package.context_menu(text)
                    if menu_items:
                        menu = QtGui.QMenu(self)
                        for text, callback in menu_items:
                            act = QtGui.QAction(text, self)
                            act.setStatusTip(text)
                            QtCore.QObject.connect(
                                act, QtCore.SIGNAL("triggered()"), callback)
                            menu.addAction(act)
                        menu.exec_(event.globalPos())
                    return
            except Exception, e:
                debug.unexpected_exception(e)
                debug.warning("Got exception trying to display %s's "
                              "context menu in the palette: %s\n%s" %
                              (package.name, debug.format_exception(e),
                               traceback.format_exc()))

            item.contextMenuEvent(event, self)
Example #43
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 #44
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 #45
0
    def save_vistrail(self, locator=None, controller=None, export=False):
        if controller is None:
            controller = self.get_current_controller()
            if controller is None:
                return False
        if locator is None and controller is not None:
            locator = controller.locator
        elif isinstance(locator, basestring):
            locator = BaseLocator.from_url(locator)

        if not locator:
            return False
        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
Example #46
0
    def save_vistrail(self, locator=None, controller=None, export=False):
        if controller is None:
            controller = self.get_current_controller()
            if controller is None:
                return False
        if locator is None and controller is not None:
            locator = controller.locator
        elif isinstance(locator, basestring):
            locator = BaseLocator.from_url(locator)

        if not locator:
            return False
        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
Example #47
0
    def contextMenuEvent(self, event):
        # Just dispatches the menu event to the widget item
        item = self.itemAt(event.pos())
        if item:
            # find top level
            p = item
            while p.parent():
                p = p.parent()
            # get package identifier
            assert isinstance(p, QPackageTreeWidgetItem)
            identifier = p.identifier
            registry = get_module_registry()
            package = registry.packages[identifier]
            try:
                if package.has_contextMenuName():
                    name = package.contextMenuName(item.text(0))
                    if name:
                        act = QtGui.QAction(name, self)
                        act.setStatusTip(name)
                        def callMenu():
                            if package.has_callContextMenu():
                                name = package.callContextMenu(item.text(0))

                        QtCore.QObject.connect(act,
                                               QtCore.SIGNAL("triggered()"),
                                               callMenu)
                        menu = QtGui.QMenu(self)
                        menu.addAction(act)
                        menu.exec_(event.globalPos())
                    return
            except Exception, e:
                debug.unexpected_exception(e)
                debug.warning("Got exception trying to display %s's "
                              "context menu in the palette: %s\n%s" % (
                                  package.name,
                                  debug.format_exception(e),
                                  traceback.format_exc()))

            item.contextMenuEvent(event, self)
Example #48
0
 def add_wf_exec_entity(self, wf_exec, add_to_map=False):
     version_id = wf_exec.parent_version
     is_new = False
     if version_id not in self.wf_entity_map:
         is_new = True
         # FIXME add new workflow entity for this version
         if version_id not in self.vistrail.actionMap:
             raise LookupError("Version %d does not occur in vistrail." %
                               version_id)
         action = self.vistrail.actionMap[version_id]
         try:
             workflow = self.vistrail.getPipeline(version_id)
         except Exception, e:
             debug.unexpected_exception(e)
             if self.vistrail.has_tag(version_id):
                 tag_str = self.vistrail.get_tag(version_id)
             else:
                 tag_str = str(version_id)
             debug.critical("Failed to construct pipeline '%s'" % tag_str,
                            debug.format_exc())
             workflow = self.vistrail.getPipeline(0)
         wf_entity = self.create_workflow_entity(workflow, action)
         self.wf_entity_map[version_id] = wf_entity
Example #49
0
    def cleanup(self):
        """cleanup() -> None

        Cleans up the file pool, by removing all temporary files and
        the directory they existed in. Module developers should never
        call this directly.

        """
        if not os.path.isdir(self.directory):
            # cleanup has already happened
            return
        try:
            for root, dirs, files in os.walk(self.directory, topdown=False):
                for name in files:
                    os.remove(os.path.join(root, name))
                for name in dirs:
                    os.rmdir(os.path.join(root, name))
            os.rmdir(self.directory)
        except OSError, e:
            debug.unexpected_exception(e)
            raise VistrailsInternalError("Can't remove %s: %s" %
                                         (self.directory,
                                          debug.format_exception(e)))
Example #50
0
 def add_wf_exec_entity(self, wf_exec, add_to_map=False):
     version_id = wf_exec.parent_version
     is_new = False
     if version_id not in self.wf_entity_map:
         is_new = True
         # FIXME add new workflow entity for this version
         if version_id not in self.vistrail.actionMap:
             raise LookupError("Version %d does not occur in vistrail." %
                               version_id)
         action = self.vistrail.actionMap[version_id]
         try:
             workflow = self.vistrail.getPipeline(version_id)
         except Exception, e:
             debug.unexpected_exception(e)
             if self.vistrail.has_tag(version_id):
                 tag_str = self.vistrail.get_tag(version_id)
             else:
                 tag_str = str(version_id)
             debug.critical("Failed to construct pipeline '%s'" % tag_str,
                            debug.format_exc())
             workflow = self.vistrail.getPipeline(0)
         wf_entity = self.create_workflow_entity(workflow, action)
         self.wf_entity_map[version_id] = wf_entity
Example #51
0
    def setup_pipeline(self, pipeline, **kwargs):
        """setup_pipeline(controller, pipeline, locator, currentVersion,
                          view, aliases, **kwargs)
        Matches a pipeline with the persistent pipeline and creates
        instances of modules that aren't in the cache.
        """
        def fetch(name, default):
            return kwargs.pop(name, default)
        controller = fetch('controller', None)
        locator = fetch('locator', None)
        current_version = fetch('current_version', None)
        view = fetch('view', DummyView())
        vistrail_variables = fetch('vistrail_variables', None)
        aliases = fetch('aliases', None)
        params = fetch('params', None)
        extra_info = fetch('extra_info', None)
        logger = fetch('logger', DummyLogController)
        sinks = fetch('sinks', None)
        reason = fetch('reason', None)
        actions = fetch('actions', None)
        done_summon_hooks = fetch('done_summon_hooks', [])
        module_executed_hook = fetch('module_executed_hook', [])
        stop_on_error = fetch('stop_on_error', True)
        parent_exec = fetch('parent_exec', None)

        reg = get_module_registry()

        if len(kwargs) > 0:
            raise VistrailsInternalError('Wrong parameters passed '
                                         'to setup_pipeline: %s' % kwargs)

        def create_null():
            """Creates a Null value"""
            getter = reg.get_descriptor_by_name
            descriptor = getter(basic_pkg, 'Null')
            return descriptor.module()
        
        def create_constant(param, module):
            """Creates a Constant from a parameter spec"""
            getter = reg.get_descriptor_by_name
            desc = getter(param.identifier, param.type, param.namespace)
            constant = desc.module()
            constant.id = module.id
#             if param.evaluatedStrValue:
#                 constant.setValue(param.evaluatedStrValue)
            if param.strValue != '':
                constant.setValue(param.strValue)
            else:
                constant.setValue( \
                    constant.translate_to_string(constant.default_value))
            return constant

        ### BEGIN METHOD ###

#         if self.debugger:
#             self.debugger.update()
        to_delete = []
        errors = {}

        if controller is not None:
            # Controller is none for sub_modules
            controller.validate(pipeline)
        else:
            pipeline.validate()

        self.resolve_aliases(pipeline, aliases)
        if vistrail_variables:
            self.resolve_variables(vistrail_variables,  pipeline)

        self.update_params(pipeline, params)
        
        (tmp_to_persistent_module_map,
         conn_map,
         module_added_set,
         conn_added_set) = self.add_to_persistent_pipeline(pipeline)

        # Create the new objects
        for i in module_added_set:
            persistent_id = tmp_to_persistent_module_map[i]
            module = self._persistent_pipeline.modules[persistent_id]
            obj = self._objects[persistent_id] = module.summon()
            obj.interpreter = self
            obj.id = persistent_id
            obj.signature = module._signature
            
            # Checking if output should be stored
            if module.has_annotation_with_key('annotate_output'):
                annotate_output = module.get_annotation_by_key('annotate_output')
                #print annotate_output
                if annotate_output:
                    obj.annotate_output = True

            for f in module.functions:
                connector = None
                if len(f.params) == 0:
                    connector = ModuleConnector(create_null(), 'value',
                                                f.get_spec('output'))
                elif len(f.params) == 1:
                    p = f.params[0]
                    try:
                        constant = create_constant(p, module)
                        connector = ModuleConnector(constant, 'value',
                                                    f.get_spec('output'))
                    except Exception, e:
                        debug.unexpected_exception(e)
                        err = ModuleError(
                                module,
                                "Uncaught exception creating Constant from "
                                "%r: %s" % (
                                p.strValue,
                                debug.format_exception(e)))
                        errors[i] = err
                        to_delete.append(obj.id)
                else:
                    tupleModule = vistrails.core.interpreter.base.InternalTuple()
                    tupleModule.length = len(f.params)
                    for (j,p) in enumerate(f.params):
                        try:
                            constant = create_constant(p, module)
                            constant.update()
                            connector = ModuleConnector(constant, 'value',
                                                        f.get_spec('output'))
                            tupleModule.set_input_port(j, connector)
                        except Exception, e:
                            debug.unexpected_exception(e)
                            err = ModuleError(
                                    module,
                                    "Uncaught exception creating Constant "
                                    "from %r: %s" % (
                                    p.strValue,
                                    debug.format_exception(e)))
                            errors[i] = err
                            to_delete.append(obj.id)
                    connector = ModuleConnector(tupleModule, 'value',
                                                f.get_spec('output'))
                if connector:
                    obj.set_input_port(f.name, connector, is_method=True)
Example #52
0
    def setup_pipeline(self, pipeline, **kwargs):
        """setup_pipeline(controller, pipeline, locator, currentVersion,
                          view, aliases, **kwargs)
        Matches a pipeline with the persistent pipeline and creates
        instances of modules that aren't in the cache.
        """
        def fetch(name, default):
            return kwargs.pop(name, default)

        controller = fetch('controller', None)
        locator = fetch('locator', None)
        current_version = fetch('current_version', None)
        view = fetch('view', DummyView())
        vistrail_variables = fetch('vistrail_variables', None)
        aliases = fetch('aliases', None)
        params = fetch('params', None)
        extra_info = fetch('extra_info', None)
        logger = fetch('logger', DummyLogController)
        sinks = fetch('sinks', None)
        reason = fetch('reason', None)
        actions = fetch('actions', None)
        done_summon_hooks = fetch('done_summon_hooks', [])
        module_executed_hook = fetch('module_executed_hook', [])
        stop_on_error = fetch('stop_on_error', True)
        parent_exec = fetch('parent_exec', None)
        job_monitor = fetch('job_monitor', None)

        reg = get_module_registry()

        if len(kwargs) > 0:
            raise VistrailsInternalError('Wrong parameters passed '
                                         'to setup_pipeline: %s' % kwargs)

        def create_null():
            """Creates a Null value"""
            getter = reg.get_descriptor_by_name
            descriptor = getter(basic_pkg, 'Null')
            return descriptor.module()

        def create_constant(param, module):
            """Creates a Constant from a parameter spec"""
            getter = reg.get_descriptor_by_name
            desc = getter(param.identifier, param.type, param.namespace)
            constant = desc.module()
            constant.id = module.id
            #             if param.evaluatedStrValue:
            #                 constant.setValue(param.evaluatedStrValue)
            if param.strValue != '':
                constant.setValue(param.strValue)
            else:
                constant.setValue(
                    constant.translate_to_string(constant.default_value))
            return constant

        ### BEGIN METHOD ###

#         if self.debugger:
#             self.debugger.update()
        to_delete = []
        errors = {}

        if controller is not None:
            # Controller is none for sub_modules
            controller.validate(pipeline)
        else:
            pipeline.validate()

        self.resolve_aliases(pipeline, aliases)
        if vistrail_variables:
            self.resolve_variables(vistrail_variables, pipeline)

        self.update_params(pipeline, params)

        (tmp_to_persistent_module_map, conn_map, module_added_set,
         conn_added_set) = self.add_to_persistent_pipeline(pipeline)

        # Create the new objects
        for i in module_added_set:
            persistent_id = tmp_to_persistent_module_map[i]
            module = self._persistent_pipeline.modules[persistent_id]
            obj = self._objects[persistent_id] = module.summon()
            obj.interpreter = self
            obj.id = persistent_id
            obj.signature = module._signature

            # Checking if output should be stored
            if module.has_annotation_with_key('annotate_output'):
                annotate_output = module.get_annotation_by_key(
                    'annotate_output')
                #print annotate_output
                if annotate_output:
                    obj.annotate_output = True

            for f in module.functions:
                connector = None
                if len(f.params) == 0:
                    connector = ModuleConnector(create_null(), 'value',
                                                f.get_spec('output'))
                elif len(f.params) == 1:
                    p = f.params[0]
                    try:
                        constant = create_constant(p, module)
                        connector = ModuleConnector(constant, 'value',
                                                    f.get_spec('output'))
                    except Exception, e:
                        debug.unexpected_exception(e)
                        err = ModuleError(
                            module,
                            "Uncaught exception creating Constant from "
                            "%r: %s" % (p.strValue, debug.format_exception(e)))
                        errors[i] = err
                        to_delete.append(obj.id)
                else:
                    tupleModule = vistrails.core.interpreter.base.InternalTuple(
                    )
                    tupleModule.length = len(f.params)
                    for (j, p) in enumerate(f.params):
                        try:
                            constant = create_constant(p, module)
                            constant.update()
                            connector = ModuleConnector(
                                constant, 'value', f.get_spec('output'))
                            tupleModule.set_input_port(j, connector)
                        except Exception, e:
                            debug.unexpected_exception(e)
                            err = ModuleError(
                                module, "Uncaught exception creating Constant "
                                "from %r: %s" %
                                (p.strValue, debug.format_exception(e)))
                            errors[i] = err
                            to_delete.append(obj.id)
                    connector = ModuleConnector(tupleModule, 'value',
                                                f.get_spec('output'))
                if connector:
                    obj.set_input_port(f.name, connector, is_method=True)
Example #53
0
                # Copy attributes (shallow) from _module into _init_module's namespace and point _module to _init_module
                module_attributes = ['identifier', 'name', 'version',
                                     'configuration', 'package_dependencies',
                                     'package_requirements',
                                     'can_handle_identifier',
                                     'can_handle_vt_file']
                for attr in module_attributes:
                    if (hasattr(self._module, attr) and
                            not hasattr(self._init_module, attr)):
                        setattr(self._init_module, attr, getattr(self._module, attr))
                self._module = self._init_module

            if hasattr(self._init_module, 'initialize'):
                self._init_module.initialize()
        except Exception, e:
            debug.unexpected_exception(e)
            self.unload()
            raise

    def unload(self):
        for path in self.py_dependencies:
            if path not in sys.modules:
                # print "skipping %s" % path
                pass
            else:
                # print 'deleting path:', path, path in sys.modules
                del sys.modules[path]
        self.py_dependencies.clear()
        self._loaded = False

    def set_properties(self):
Example #54
0
                module_attributes = [
                    'identifier', 'name', 'version', 'configuration',
                    'package_dependencies', 'package_requirements',
                    'can_handle_identifier', 'can_handle_vt_file'
                ]
                for attr in module_attributes:
                    if (hasattr(self._module, attr)
                            and not hasattr(self._init_module, attr)):
                        setattr(self._init_module, attr,
                                getattr(self._module, attr))
                self._module = self._init_module

            if hasattr(self._init_module, 'initialize'):
                self._init_module.initialize()
        except Exception, e:
            debug.unexpected_exception(e)
            self.unload()
            raise

    def unload(self):
        for path in self.py_dependencies:
            if path not in sys.modules:
                # print "skipping %s" % path
                pass
            else:
                # print 'deleting path:', path, path in sys.modules
                del sys.modules[path]
        self.py_dependencies.clear()
        self._loaded = False

    def set_properties(self):