<commit_before>############################################################################
##
## Copyright (C) 2006-2007 University of Utah. All rights reserved.
##
## This file is part of VisTrails.
##
## This file may be used under the terms of the GNU General Public
## License version 2.0 as published by the Free Software Foundation
## and appearing in the file LICENSE.GPL included in the packaging of
## this file.  Please review the following to ensure GNU General Public
## Licensing requirements will be met:
## http://www.opensource.org/licenses/gpl-license.php
##
## If you are unsure which license is appropriate for your use (for
## instance, you are interested in developing a commercial derivative
## of VisTrails), please contact us at <EMAIL>.
##
## This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
## WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
##
############################################################################
from PyQt4 import QtCore, QtGui
from core.utils import VistrailsInternalError
from core.modules import module_registry
from core.vistrail.action import Action, AddModuleAction, DeleteModuleAction, \
    ChangeParameterAction, AddConnectionAction, DeleteConnectionAction, \
    DeleteFunctionAction, ChangeAnnotationAction, DeleteAnnotationAction,\
    AddModulePortAction, DeleteModulePortAction, MoveModuleAction
from core.query.version import TrueSearch
from core.query.visual import VisualQuery
from core.vistrail.module import Module
from core.vistrail.pipeline import Pipeline
from core.vistrail.module_param import VistrailModuleType
import copy
import os.path
import core.interpreter

################################################################################

class VistrailController(QtCore.QObject):
    """
    VistrailController is the class handling all action control in
    VisTrails. It updates pipeline, vistrail and emit signals to
    update the view
    
    """

    def __init__(self, vis=None, name=''):
        """ VistrailController(vis: Vistrail, name: str) -> VistrailController
        Create a controller from vis

        """
        QtCore.QObject.__init__(self)
        self.name = ''
        self.fileName = ''
        self.setFileName(name)
        self.vistrail = vis
        self.currentVersion = -1
        self.currentPipeline = None
        self.currentPipelineView = None
        self.previousModuleIds = []
        self.resetPipelineView = False
        self.resetVersionView = True
        self.quiet = False
        self.logger = None
        self.search = None
        self.refine = False
        self.changed = False
        self.fullTree = False
        self.interpreter = core.interpreter.CachedInterpreter()

    def cleanup(self):
        self.interpreter.clear()

    def setVistrail(self, vistrail, name):
        """ setVistrail(vistrail: Vistrail) -> None
        Start controlling a vistrail
        
        """
        self.vistrail = vistrail
        self.currentVersion = -1
        self.currentPipeline = None
        self.setFileName(name)
        
    def addModule(self, name, x, y):
        """ addModule(name: str, x: int, y: int) -> version id
        Add a new module into the current pipeline
        
        """
        self.emit(QtCore.SIGNAL("flushMoveActions()"))

        if self.currentPipeline:
            newModule = Module()
            newModule.id = self.currentPipeline.fresh_module_id()
            newModule.center.reset(x,y)
            newModule.name = str(name)
            newModule.cache = 0
            newAction = AddModuleAction()
            newAction.module = newModule
            self.performAction(newAction)
            return newModule
        else:
            return None

    def deleteModule(self, moduleId):
        """ deleteModule(moduleId: int) -> version id
        Delete a module from the current pipeline
        
        """
        self.emit(QtCore.SIGNAL("flushMoveActions()"))
        graph = self.currentPipeline.graph

        action = DeleteConnectionAction()

        for v, id in graph.edgesFrom(module_id):
            action.addId(id)

        for v, id in graph.edgesTo(module_id):
            action.addId(id)

        self.performAction(action)

        action2 = DeleteModuleAction()
        action2.addId(module_id)
        return self.performAction(action2)


    def deleteModuleList(self, mList):
        """ deleteModule(mList: [int]) -> [version id]
        Delete multiple modules from the current pipeline
        
        """
        self.emit(QtCore.SIGNAL("flushMoveActions()"))
        graph = self.currentPipeline.graph

        action = DeleteConnectionAction()
        action2 = DeleteModuleAction()

        for module_id in mList:
            for v, id in graph.edgesFrom(module_id):
                if id not in action.ids:
                    action.addId(id)

            for v, id in graph.edgesTo(module_id):
                if id not in action.ids:
                    action.addId(id)
            
            action2.addId(module_id)
        l = [action, action2]
        return self.performBulkActions(l)

    def moveModuleList(self, mList):
        """ moveModuleList(mList: [(id,dx,dy)]) -> [version id]        
        Move all modules to a new location. No flushMoveActions is
        allowed to to emit to avoid recursive actions
        
        """
        action = MoveModuleAction()
        action.moves = copy.copy(mList)
        return self.performAction(action)
            
    def addConnection(self, conn):
        """ addConnection(conn: Connection) -> version id
        Add a new connection 'conn' into Vistrail
        
        """
        self.emit(QtCore.SIGNAL("flushMoveActions()"))
        action = AddConnectionAction()
        action.connection = conn
        return self.performAction(action)
    
    def deleteConnection(self, id):
        """ deleteConnection(id: int) -> version id
        Delete a connection with id 'id'
        
        """
        self.emit(QtCore.SIGNAL("flushMoveActions()"))
        action = DeleteConnectionAction()
        action.addId(id)

        return self.performAction(action)

    def deleteConnectionList(self, cList):
        """ deleteConnections(cList: list) -> version id
        Delete a list of connections
        
        """
        self.emit(QtCore.SIGNAL("flushMoveActions()"))
        action = DeleteConnectionAction()
        for id in cList:
            action.addId(id)

        self.performAction(action)

    def executeWorkflowList(self, vistrails):
        interpreter = core.interpreter.Interpreter()
        for vis in vistrails:
            (name, version, pipeline, view, logger) = vis<commit_msg>Uses default interpreter instead of hardcoding the cached one.<commit_after>############################################################################
##
## Copyright (C) 2006-2007 University of Utah. All rights reserved.
##
## This file is part of VisTrails.
##
## This file may be used under the terms of the GNU General Public
## License version 2.0 as published by the Free Software Foundation
## and appearing in the file LICENSE.GPL included in the packaging of
## this file.  Please review the following to ensure GNU General Public
## Licensing requirements will be met:
## http://www.opensource.org/licenses/gpl-license.php
##
## If you are unsure which license is appropriate for your use (for
## instance, you are interested in developing a commercial derivative
## of VisTrails), please contact us at <EMAIL>.
##
## This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
## WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
##
############################################################################
from PyQt4 import QtCore, QtGui
from core.utils import VistrailsInternalError
from core.modules import module_registry
from core.vistrail.action import Action, AddModuleAction, DeleteModuleAction, \
    ChangeParameterAction, AddConnectionAction, DeleteConnectionAction, \
    DeleteFunctionAction, ChangeAnnotationAction, DeleteAnnotationAction,\
    AddModulePortAction, DeleteModulePortAction, MoveModuleAction
from core.query.version import TrueSearch
from core.query.visual import VisualQuery
from core.vistrail.module import Module
from core.vistrail.pipeline import Pipeline
from core.vistrail.module_param import VistrailModuleType
import copy
import os.path
from core.interpreter.default import default_interpreter

################################################################################

class VistrailController(QtCore.QObject):
    """
    VistrailController is the class handling all action control in
    VisTrails. It updates pipeline, vistrail and emit signals to
    update the view
    
    """

    def __init__(self, vis=None, name=''):
        """ VistrailController(vis: Vistrail, name: str) -> VistrailController
        Create a controller from vis

        """
        QtCore.QObject.__init__(self)
        self.name = ''
        self.fileName = ''
        self.setFileName(name)
        self.vistrail = vis
        self.currentVersion = -1
        self.currentPipeline = None
        self.currentPipelineView = None
        self.previousModuleIds = []
        self.resetPipelineView = False
        self.resetVersionView = True
        self.quiet = False
        self.logger = None
        self.search = None
        self.refine = False
        self.changed = False
        self.fullTree = False

    def cleanup(self):
        pass

    def setVistrail(self, vistrail, name):
        """ setVistrail(vistrail: Vistrail) -> None
        Start controlling a vistrail
        
        """
        self.vistrail = vistrail
        self.currentVersion = -1
        self.currentPipeline = None
        self.setFileName(name)
        
    def addModule(self, name, x, y):
        """ addModule(name: str, x: int, y: int) -> version id
        Add a new module into the current pipeline
        
        """
        self.emit(QtCore.SIGNAL("flushMoveActions()"))

        if self.currentPipeline:
            newModule = Module()
            newModule.id = self.currentPipeline.fresh_module_id()
            newModule.center.reset(x,y)
            newModule.name = str(name)
            newModule.cache = 0
            newAction = AddModuleAction()
            newAction.module = newModule
            self.performAction(newAction)
            return newModule
        else:
            return None

    def deleteModule(self, moduleId):
        """ deleteModule(moduleId: int) -> version id
        Delete a module from the current pipeline
        
        """
        self.emit(QtCore.SIGNAL("flushMoveActions()"))
        graph = self.currentPipeline.graph

        action = DeleteConnectionAction()

        for v, id in graph.edgesFrom(module_id):
            action.addId(id)

        for v, id in graph.edgesTo(module_id):
            action.addId(id)

        self.performAction(action)

        action2 = DeleteModuleAction()
        action2.addId(module_id)
        return self.performAction(action2)


    def deleteModuleList(self, mList):
        """ deleteModule(mList: [int]) -> [version id]
        Delete multiple modules from the current pipeline
        
        """
        self.emit(QtCore.SIGNAL("flushMoveActions()"))
        graph = self.currentPipeline.graph

        action = DeleteConnectionAction()
        action2 = DeleteModuleAction()

        for module_id in mList:
            for v, id in graph.edgesFrom(module_id):
                if id not in action.ids:
                    action.addId(id)

            for v, id in graph.edgesTo(module_id):
                if id not in action.ids:
                    action.addId(id)
            
            action2.addId(module_id)
        l = [action, action2]
        return self.performBulkActions(l)

    def moveModuleList(self, mList):
        """ moveModuleList(mList: [(id,dx,dy)]) -> [version id]        
        Move all modules to a new location. No flushMoveActions is
        allowed to to emit to avoid recursive actions
        
        """
        action = MoveModuleAction()
        action.moves = copy.copy(mList)
        return self.performAction(action)
            
    def addConnection(self, conn):
        """ addConnection(conn: Connection) -> version id
        Add a new connection 'conn' into Vistrail
        
        """
        self.emit(QtCore.SIGNAL("flushMoveActions()"))
        action = AddConnectionAction()
        action.connection = conn
        return self.performAction(action)
    
    def deleteConnection(self, id):
        """ deleteConnection(id: int) -> version id
        Delete a connection with id 'id'
        
        """
        self.emit(QtCore.SIGNAL("flushMoveActions()"))
        action = DeleteConnectionAction()
        action.addId(id)

        return self.performAction(action)

    def deleteConnectionList(self, cList):
        """ deleteConnections(cList: list) -> version id
        Delete a list of connections
        
        """
        self.emit(QtCore.SIGNAL("flushMoveActions()"))
        action = DeleteConnectionAction()
        for id in cList:
            action.addId(id)

        self.performAction(action)

    def executeWorkflowList(self, vistrails):
        interpreter = default_interpreter.get()
        for vis in vistrails:
            (name, version, pipeline, view, logger) = vis
{'fraction_non_alphanumeric': 0.11777365491651207, 'fraction_numerical': 0.002968460111317254, 'mean_word_length': 2.509375, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3502438', 'n_tokens_mistral': 3552, 'n_tokens_neox': 3411, 'n_words': 1011}