コード例 #1
0
ファイル: controller.py プロジェクト: cjh1/VisTrails
 def updateCurrentTag(self, name):
     if self.mshptrail.changeTag(self.currentVersion, name, current_user(),
                              current_time()):
         self.setChanged(True)
         return True
     else:
         return False
コード例 #2
0
ファイル: controller.py プロジェクト: hjanime/VisTrails
 def updateCurrentTag(self, name):
     if self.mshptrail.changeTag(self.currentVersion, name, current_user(),
                                 current_time()):
         self.setChanged(True)
         return True
     else:
         return False
コード例 #3
0
ファイル: pe_table.py プロジェクト: licode/VisTrails
    def getParameterExploration(self):
        """ getParameterExploration() -> ParameterExploration
        Generates a ParameterExploration object hat represents the current
        parameter exploration, and which can be loaded with
        setParameterExploration().
        
        """
        # Construct xml for persisting parameter exploration
        escape_dict = {"'": "'", '"': '"', '\n': '
'}
        palette = self.get_palette()
        id_scope = self.controller.id_scope
        functions = []
        for i in xrange(self.table.layout().count()):
            pEditor = self.table.layout().itemAt(i).widget()
            if pEditor and isinstance(pEditor, QParameterSetEditor):
                function = None
                firstParam = True
                for paramWidget in pEditor.paramWidgets:
                    paramInfo = paramWidget.param
                    interpolator = paramWidget.editor.stackedEditors.currentWidget(
                    )
                    intType = interpolator.exploration_name
                    # Write function tag prior to the first parameter of the function
                    if firstParam:
                        function = PEFunction(
                            id=id_scope.getNewId(PEFunction.vtType),
                            module_id=paramInfo.module_id,
                            port_name=paramInfo.name,
                            is_alias=1 if paramInfo.is_alias else 0)
                        firstParam = False

                    if intType in [
                            'Linear Interpolation', 'RGB Interpolation',
                            'HSV Interpolation'
                    ]:
                        value = '["%s", "%s"]' % (
                            interpolator.fromEdit.get_value(),
                            interpolator.toEdit.get_value())
                    elif intType == 'List':
                        value = '%s' % escape(str(interpolator._str_values),
                                              escape_dict)
                    elif intType == 'User-defined Function':
                        value = '%s' % escape(interpolator.function,
                                              escape_dict)
                    # Write parameter tag
                    param = PEParam(id=id_scope.getNewId(PEParam.vtType),
                                    pos=paramInfo.pos,
                                    interpolator=intType,
                                    value=value,
                                    dimension=paramWidget.getDimension())
                    function.addParameter(param)
                functions.append(function)
        pe = ParameterExploration(
            dims=str(self.table.label.getCounts()),
            layout=repr(palette.virtual_cell.getConfiguration()[2]),
            date=current_time(),
            user=getuser(),
            functions=functions)
        return pe
コード例 #4
0
ファイル: controller.py プロジェクト: hjanime/VisTrails
 def moveTag(self, from_version, to_version, name):
     tag = self.mshptrail.getTagForActionId(from_version)
     if tag:
         self.mshptrail.removeTagByActionId(from_version)
         self.mshptrail.addTag(to_version,
                               tag,
                               user=current_user(),
                               date=current_time())
コード例 #5
0
ファイル: pe_table.py プロジェクト: AnyarInc/VisTrails
    def getParameterExploration(self):
        """ getParameterExploration() -> ParameterExploration
        Generates a ParameterExploration object hat represents the current
        parameter exploration, and which can be loaded with
        setParameterExploration().
        
        """
        # Construct xml for persisting parameter exploration
        escape_dict = { "'":"'", '"':'"', '\n':'
' }
        palette = self.get_palette()
        id_scope = self.controller.id_scope
        functions = []
        for i in xrange(self.table.layout().count()):
            pEditor = self.table.layout().itemAt(i).widget()
            if pEditor and isinstance(pEditor, QParameterSetEditor):
                function = None
                firstParam = True
                for paramWidget in pEditor.paramWidgets:
                    paramInfo = paramWidget.param
                    interpolator = paramWidget.editor.stackedEditors.currentWidget()
                    intType = interpolator.exploration_name
                    # Write function tag prior to the first parameter of the function
                    if firstParam:
                        function = PEFunction(id=id_scope.getNewId(PEFunction.vtType),
                                              module_id=paramInfo.module_id,
                                              port_name=paramInfo.name,
                                              is_alias = 1 if paramInfo.is_alias else 0)
                        firstParam = False

                    if intType in ['Linear Interpolation', 'RGB Interpolation',
                                   'HSV Interpolation']:
                        value = '["%s", "%s"]' % (interpolator.fromEdit.get_value(),
                                                  interpolator.toEdit.get_value())
                    elif intType == 'List':
                        value = '%s' % escape(str(interpolator._str_values), escape_dict)
                    elif intType == 'User-defined Function':
                        value ='%s' % escape(interpolator.function, escape_dict)
                    else:
                        assert False
                    # Write parameter tag
                    param = PEParam(id=id_scope.getNewId(PEParam.vtType),
                                    pos=paramInfo.pos,
                                    interpolator=intType,
                                    value=value,
                                    dimension=paramWidget.getDimension())
                    function.addParameter(param)
                functions.append(function)
        pe = ParameterExploration(dims=str(self.table.label.getCounts()),
                      layout=repr(palette.virtual_cell.getConfiguration()[2]),
                      date=current_time(),
                      user=getuser(),
                      functions=functions)
        return pe
コード例 #6
0
ファイル: pe_tab.py プロジェクト: hjanime/VisTrails
 def getParameterExploration(self):
     """ getParameterExploration() -> string
     Generates an XML string that represents the current
     parameter exploration, and which can be loaded with
     setParameterExploration().
     
     """
     # Construct xml for persisting parameter exploration
     escape_dict = {"'": "'", '"': """, "\n": "
"}
     timestamp = strftime(current_time(), "%Y-%m-%d %H:%M:%S")
     # TODO: For now, we use the timestamp as the 'name' - Later, we should set 'name' based on a UI input field
     xml = '\t<paramexp dims="%s" layout="%s" date="%s" name="%s">' % (
         str(self.peWidget.table.label.getCounts()),
         str(self.virtualCell.getConfiguration()[2]),
         timestamp,
         timestamp,
     )
     for i in xrange(self.peWidget.table.layout().count()):
         pEditor = self.peWidget.table.layout().itemAt(i).widget()
         if pEditor and isinstance(pEditor, QParameterSetEditor):
             firstParam = True
             for paramWidget in pEditor.paramWidgets:
                 paramInfo = paramWidget.param
                 interpolator = paramWidget.editor.stackedEditors.currentWidget()
                 intType = interpolator.exploration_name
                 # Write function tag prior to the first parameter of the function
                 if firstParam:
                     xml += '\n\t\t<function id="%s" alias="%s" name="%s">' % (
                         paramInfo.parent_id,
                         paramInfo.is_alias,
                         pEditor.info[0],
                     )
                     firstParam = False
                 # Write parameter tag
                 xml += '\n\t\t\t<param id="%s" dim="%s" interp="%s"' % (
                     paramInfo.id,
                     paramWidget.getDimension(),
                     intType,
                 )
                 if intType == "Linear Interpolation":
                     xml += ' min="%s" max="%s"' % (
                         interpolator.fromEdit.get_value(),
                         interpolator.toEdit.get_value(),
                     )
                 elif intType == "List":
                     xml += ' values="%s"' % escape(str(interpolator._str_values), escape_dict)
                 elif intType == "User-defined Function":
                     xml += ' code="%s"' % escape(interpolator.function, escape_dict)
                 xml += "/>"
             xml += "\n\t\t</function>"
     xml += "\n\t</paramexp>"
     return xml
コード例 #7
0
ファイル: pe_table.py プロジェクト: licode/VisTrails
 def getParameterExplorationOld(self):
     """ getParameterExploration() -> string
     Generates an XML string that represents the current
     parameter exploration, and which can be loaded with
     setParameterExploration().
     
     """
     # Construct xml for persisting parameter exploration
     escape_dict = {"'": "&apos;", '"': '&quot;', '\n': '&#xa;'}
     timestamp = strftime(current_time(), '%Y-%m-%d %H:%M:%S')
     palette = self.get_palette()
     # TODO: For now, we use the timestamp as the 'name' - Later, we should set 'name' based on a UI input field
     xml = '\t<paramexp dims="%s" layout="%s" date="%s" name="%s">' % (
         str(self.table.label.getCounts()),
         str(palette.virtual_cell.getConfiguration()[2]), timestamp,
         timestamp)
     for i in xrange(self.table.layout().count()):
         pEditor = self.table.layout().itemAt(i).widget()
         if pEditor and isinstance(pEditor, QParameterSetEditor):
             firstParam = True
             for paramWidget in pEditor.paramWidgets:
                 paramInfo = paramWidget.param
                 interpolator = paramWidget.editor.stackedEditors.currentWidget(
                 )
                 intType = interpolator.exploration_name
                 # Write function tag prior to the first parameter of the function
                 if firstParam:
                     xml += '\n\t\t<function id="%s" alias="%s" name="%s">' % (
                         paramInfo.parent_id, paramInfo.is_alias,
                         pEditor.info[0])
                     firstParam = False
                 # Write parameter tag
                 xml += '\n\t\t\t<param id="%s" dim="%s" interp="%s"' % (
                     paramInfo.id, paramWidget.getDimension(), intType)
                 if intType in [
                         'Linear Interpolation', 'RGB Interpolation',
                         'HSV Interpolation'
                 ]:
                     xml += ' min="%s" max="%s"' % (
                         interpolator.fromEdit.get_value(),
                         interpolator.toEdit.get_value())
                 elif intType == 'List':
                     xml += ' values="%s"' % escape(
                         str(interpolator._str_values), escape_dict)
                 elif intType == 'User-defined Function':
                     xml += ' code="%s"' % escape(interpolator.function,
                                                  escape_dict)
                 xml += '/>'
             xml += '\n\t\t</function>'
     xml += '\n\t</paramexp>'
     return xml
コード例 #8
0
ファイル: controller.py プロジェクト: cjh1/VisTrails
 def createMashupVersion(self, alias_list, quiet=False):
     id = self.id_scope.getNewId('mashup')
     mashup = Mashup(id=id, name="mashup%s"%id, 
                     vtid=self.currentMashup.vtid, 
                     version=self.currentMashup.version, 
                     alias_list=alias_list)
     currVersion = self.mshptrail.addVersion(parent_id=self.currentVersion,
                                             mashup=mashup, 
                                             user=current_user(),
                                             date=current_time())
     self.mshptrail.currentVersion = currVersion
     self.currentMashup = mashup
     #print "created new mashup ", currVersion
     self.setCurrentVersion(currVersion, quiet)
     self.setChanged(True)
     return currVersion
コード例 #9
0
ファイル: controller.py プロジェクト: hjanime/VisTrails
 def createMashupVersion(self, alias_list, quiet=False):
     id = self.id_scope.getNewId('mashup')
     mashup = Mashup(id=id,
                     name="mashup%s" % id,
                     vtid=self.currentMashup.vtid,
                     version=self.currentMashup.version,
                     alias_list=alias_list)
     currVersion = self.mshptrail.addVersion(parent_id=self.currentVersion,
                                             mashup=mashup,
                                             user=current_user(),
                                             date=current_time())
     self.mshptrail.currentVersion = currVersion
     self.currentMashup = mashup
     #print "created new mashup ", currVersion
     self.setCurrentVersion(currVersion, quiet)
     self.setChanged(True)
     return currVersion
コード例 #10
0
    def compute(self, is_input=None, path_type=None):
        global db_access
        if not self.hasInputFromPort('value') and \
                not self.hasInputFromPort('ref'):
            raise ModuleError(self, "Need to specify path or reference")

        if self.persistent_path is not None:
            debug_print('using persistent path')
            ref = self.persistent_ref
            path = self.persistent_path
        elif self.hasInputFromPort('ref'):
            ref = self.getInputFromPort('ref')
            if ref.id is None:
                ref.id = str(uuid.uuid1())
        else:
            # create a new reference
            ref = PersistentRef()
            ref.id = str(uuid.uuid1())

        if self.hasInputFromPort('localPath'):
            ref.local_path = self.getInputFromPort('localPath').name
            if self.hasInputFromPort('readLocal'):
                ref.local_read = self.getInputFromPort('readLocal')
            if self.hasInputFromPort('writeLocal'):
                ref.local_writeback = self.getInputFromPort('writeLocal')

        if is_input is None:
            is_input = False
            if not self.hasInputFromPort('value'):
                is_input = True
            else:
                if ref.local_path and ref.local_read:
                    debug_print('found local path with local read')
                    is_input = True
                # FIXME: check if the signature is the signature of
                # the value if so we know that it's an input...

        # if just reference, pull path from repository (get latest
        # version unless specified as specific version)
        if self.persistent_path is None and not self.hasInputFromPort('value') \
                and is_input and not (ref.local_path and ref.local_read):
            _, suffix = os.path.splitext(ref.name)
            if not db_access.ref_exists(ref.id, ref.version):
                raise ModuleError(self, "Persistent entity '%s' does not "
                                  "exist in the local repository." % ref.id)
            if ref.version is None:
                ref.version = repo.get_current_repo().get_latest_version(ref.id)

            # get specific ref.uuid, ref.version combo
            path = repo.get_current_repo().get_path(ref.id, ref.version, 
                                                    out_suffix=suffix)
            
        elif self.persistent_path is None:
            # copy path to persistent directory with uuid as name
            if is_input and ref.local_path and ref.local_read:
                debug_print('using local_path')
                path = ref.local_path
            else:
                path = self.getInputFromPort('value').name
            # this is a static method so we need to add module ourselves
            try:
                new_hash = repo.get_current_repo().compute_hash(path)
            except ModuleError, e:
                e.module = self
                raise e
            rep_path = os.path.join(local_db, ref.id)
            do_update = True
            if os.path.exists(rep_path):
                if os.path.isdir(rep_path):
                    actual_type = 'tree'
                elif os.path.isfile(rep_path):
                    actual_type = 'blob'
                else:
                    raise ModuleError(self, "Path is something not a file or "
                                      "a directory")
                if path_type is None:
                    path_type = actual_type
                else:
                    if path_type != actual_type:
                        def show_type(t):
                            if t == 'tree': return "directory"
                            elif t == 'blob': return "file"
                            else: return '"%s"' % t
                        raise ModuleError(self, "Path is not a %s but a %s" % (
                                          show_type(path_type),
                                          show_type(actual_type)))

                old_hash = repo.get_current_repo().get_hash(ref.id, 
                                                            path_type=path_type)
                debug_print('old_hash:', old_hash)
                debug_print('new_hash:', new_hash)
                if old_hash == new_hash:
                    do_update = False
                    
            if do_update:
                debug_print('doing update')

                if path_type == 'tree':
                    if (not os.path.exists(path) or
                            not os.listdir(path)):
                        raise ModuleError(self, "This directory is empty")

                self.copypath(path, os.path.join(local_db, ref.id))

                # commit (and add to) repository
                # get commit id as version id
                # persist object-hash, commit-version to repository
                version = repo.get_current_repo().add_commit(ref.id)
                ref.version = version

                # write object-hash, commit-version to provenance
                if is_input:
                    signature = new_hash
                else:
                    signature = self.signature
                db_access.write_database({'id': ref.id, 
                                          'name': ref.name, 
                                          'tags': ref.tags, 
                                          'user': current_user(),
                                          'date_created': current_time(),
                                          'date_modified': current_time(),
                                          'content_hash': new_hash,
                                          'version': version, 
                                          'signature': signature,
                                          'type': path_type})
コード例 #11
0
ファイル: controller.py プロジェクト: cjh1/VisTrails
 def moveTag(self, from_version, to_version, name):
     tag = self.mshptrail.getTagForActionId(from_version)
     if tag:
         self.mshptrail.removeTagByActionId(from_version)
         self.mshptrail.addTag(to_version, tag, user=current_user(),
                               date=current_time())
コード例 #12
0
ファイル: init.py プロジェクト: vistrails-ufrj/VisTrails
    def compute(self, is_input=None, path_type=None):
        global db_access
        if not self.has_input('value') and \
                not self.has_input('ref'):
            raise ModuleError(self, "Need to specify path or reference")

        if self.persistent_path is not None:
            debug_print('using persistent path')
            ref = self.persistent_ref
            path = self.persistent_path
        elif self.has_input('ref'):
            ref = self.get_input('ref')
            if ref.id is None:
                ref.id = str(uuid.uuid1())
        else:
            # create a new reference
            ref = PersistentRef()
            ref.id = str(uuid.uuid1())

        if self.has_input('localPath'):
            ref.local_path = self.get_input('localPath').name
            if self.has_input('readLocal'):
                ref.local_read = self.get_input('readLocal')
            if self.has_input('writeLocal'):
                ref.local_writeback = self.get_input('writeLocal')

        if is_input is None:
            is_input = False
            if not self.has_input('value'):
                is_input = True
            else:
                if ref.local_path and ref.local_read:
                    debug_print('found local path with local read')
                    is_input = True
                # FIXME: check if the signature is the signature of
                # the value if so we know that it's an input...

        # if just reference, pull path from repository (get latest
        # version unless specified as specific version)
        if self.persistent_path is None and not self.has_input('value') \
                and is_input and not (ref.local_path and ref.local_read):
            _, suffix = os.path.splitext(ref.name)
            if not db_access.ref_exists(ref.id, ref.version):
                raise ModuleError(
                    self, "Persistent entity '%s' does not "
                    "exist in the local repository." % ref.id)
            if ref.version is None:
                ref.version = repo.get_current_repo().get_latest_version(
                    ref.id)

            # get specific ref.uuid, ref.version combo
            path = repo.get_current_repo().get_path(ref.id,
                                                    ref.version,
                                                    out_suffix=suffix)

        elif self.persistent_path is None:
            # copy path to persistent directory with uuid as name
            if is_input and ref.local_path and ref.local_read:
                debug_print('using local_path')
                path = ref.local_path
            else:
                path = self.get_input('value').name
            # this is a static method so we need to add module ourselves
            try:
                new_hash = repo.get_current_repo().compute_hash(path)
            except ModuleError, e:
                e.module = self
                raise e
            rep_path = os.path.join(local_db, ref.id)
            do_update = True
            if os.path.exists(rep_path):
                if os.path.isdir(rep_path):
                    actual_type = 'tree'
                elif os.path.isfile(rep_path):
                    actual_type = 'blob'
                else:
                    raise ModuleError(
                        self, "Path is something not a file or "
                        "a directory")
                if path_type is None:
                    path_type = actual_type
                else:
                    if path_type != actual_type:

                        def show_type(t):
                            if t == 'tree': return "directory"
                            elif t == 'blob': return "file"
                            else: return '"%s"' % t

                        raise ModuleError(
                            self, "Path is not a %s but a %s" %
                            (show_type(path_type), show_type(actual_type)))

                old_hash = repo.get_current_repo().get_hash(
                    ref.id, path_type=path_type)
                debug_print('old_hash:', old_hash)
                debug_print('new_hash:', new_hash)
                if old_hash == new_hash:
                    do_update = False

            if do_update:
                debug_print('doing update')

                if path_type == 'tree':
                    if (not os.path.exists(path) or not os.listdir(path)):
                        raise ModuleError(self, "This directory is empty")

                self.copypath(path, os.path.join(local_db, ref.id))

                # commit (and add to) repository
                # get commit id as version id
                # persist object-hash, commit-version to repository
                version = repo.get_current_repo().add_commit(ref.id)
                ref.version = version

                # write object-hash, commit-version to provenance
                if is_input:
                    signature = new_hash
                else:
                    signature = self.signature
                db_access.write_database({
                    'id': ref.id,
                    'name': ref.name,
                    'tags': ref.tags,
                    'user': current_user(),
                    'date_created': current_time(),
                    'date_modified': current_time(),
                    'content_hash': new_hash,
                    'version': version,
                    'signature': signature,
                    'type': path_type
                })