Exemple #1
0
 def save(self):
     return (self.id,
             self.type_id,
             self.name,
             self.user,
             strftime(self.mod_time, self.DATE_FORMAT),
             strftime(self.create_time, self.DATE_FORMAT),
             self.size,
             self.description,
             self.url)
Exemple #2
0
 def update(self, workflow_exec):
     self.workflow_exec = workflow_exec
     if self.workflow_exec is not None:
         self.name = "%s" % self.workflow_exec.db_ts_start
         self.user = self.workflow_exec.user
         self.mod_time = (
             strftime(self.workflow_exec.ts_end, '%d %b %Y %H:%M:%S')
             if self.workflow_exec.ts_end else '1 Jan 0000 00:00:00')
         self.create_time = (
             strftime(self.workflow_exec.ts_start, '%d %b %Y %H:%M:%S')
             if self.workflow_exec.ts_start else '1 Jan 0000 00:00:00')
         self.size = len(self.workflow_exec.item_execs)
         self.description = ""
         self.url = 'test'
         self.was_updated = True
Exemple #3
0
 def convertToStr(self, value, type):
     if value is not None:
         if type == 'date':
             return value.isoformat()
         elif type == 'datetime':
             return strftime(value, '%Y-%m-%d %H:%M:%S')
         else:
             return str(value)
     return ''
Exemple #4
0
 def convertToStr(self, value, type):
     if value is not None:
         if type == 'date':
             return value.isoformat()
         elif type == 'datetime':
             return strftime(value, '%Y-%m-%d %H:%M:%S')
         else:
             return str(value)
     return ''
 def saveToHistory(self):
     """ saveToHistory() -> None
     Save the current contents to the history
     
     """
     # Generate filename
     current = datetime.datetime.now()
     tmpDir = tempfile.gettempdir()
     fn = "hist_" + strftime(current, "%Y_%m_%d__%H_%M_%S") + "_" + str(current.microsecond) + ".png"
     fn = os.path.join(tmpDir, fn)
     if self.saveToPNG(fn):
         self._historyImages.append(fn)
Exemple #6
0
 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
Exemple #7
0
    def saveToHistory(self):
        """ saveToHistory() -> None
        Save the current contents to the history

        """
        # Generate filename
        current = datetime.datetime.now()
        tmpDir = tempfile.gettempdir()
        fn = ("hist_" + strftime(current, "%Y_%m_%d__%H_%M_%S") + "_" +
              str(current.microsecond) + ".png")
        fn = os.path.join(tmpDir, fn)
        if self.saveToPNG(fn):
            self._historyImages.append(fn)
Exemple #8
0
 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
Exemple #9
0
    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 = { "'":"&apos;", '"':'&quot;', '\n':'&#xa;' }
        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=strftime(current_time(), '%Y-%m-%d %H:%M:%S'),
                      user=getuser(),
                      functions=functions)
        return pe
Exemple #10
0
    def saveSession(self):
        """saveSession() -> None
        Opens a File Save dialog and passes the filename to shell's saveSession.

        """
        default = 'visTrails' + '-' + strftime("%Y%m%d-%H%M.log")
        default = os.path.join(vistrails.core.system.vistrails_file_directory(),default)
        fileName = QtGui.QFileDialog.getSaveFileName(self,
                                                     "Save Session As..",
                                                     default,
                                                     "Log files (*.log)")
        if not fileName:
            return

        self.shell.saveSession(str(fileName))
Exemple #11
0
 def update(self, thumbnail):
     self.thumbnail = thumbnail
     if self.thumbnail is not None:
         # store in cache if not already there
         cache = ThumbnailCache.getInstance()
         cache._copy_thumbnails([thumbnail])
         self.name = os.path.basename(thumbnail)
         statinfo = os.stat(self.thumbnail)
         self.user = statinfo[stat.ST_UID]
         self.size = statinfo[stat.ST_SIZE]
         time = strftime(datetime(*localtime(statinfo[stat.ST_MTIME])[:6]),
                         '%d %b %Y %H:%M:%S')
         self.mod_time = ''
         self.create_time = time
         self.description = ""
         self.url = 'test'
         self.was_updated = True
Exemple #12
0
    def convertToDB(self, value, type, db_type):
        if value is not None:
            if type == 'str':
                return "'" + str(value) + "'"
            elif type == 'long':
                return str(value)
            elif type == 'float':
                return str(value)
            elif type == 'int':
                return str(value)
            elif type == 'date':
                return "'" + value.isoformat() + "'"
            elif type == 'datetime':
                return "'" + strftime(value, '%Y-%m-%d %H:%M:%S') + "'"
            else:
                return str(value)

        return "''"
Exemple #13
0
    def convertToDB(self, value, type, db_type):
        if value is not None:
            if type == 'str':
                return "'" + str(value).replace("'", "''") + "'"
            elif type == 'long':
                return str(value)
            elif type == 'float':
                return str(value)
            elif type == 'int':
                return str(value)
            elif type == 'date':
                return "'" + value.isoformat() + "'"
            elif type == 'datetime':
                return "'" + strftime(value, '%Y-%m-%d %H:%M:%S') + "'"
            else:
                return str(value)

        return "''"
Exemple #14
0
    def convertToDB(self, value, type, db_type):
        if value is not None:
            if type == "str":
                # return "'" + str(value).replace("'", "''") + "'"
                return str(value)
            elif type == "long":
                return str(value)
            elif type == "float":
                return str(value)
            elif type == "int":
                return str(value)
            elif type == "date":
                return value.isoformat()
            elif type == "datetime":
                return strftime(value, "%Y-%m-%d %H:%M:%S")
            else:
                return str(value)

        return None
Exemple #15
0
 def _get_date(self):
     if self.db_date is not None:
         return strftime(self.db_date, '%d %b %Y %H:%M:%S')
     return strftime(datetime(1900, 1, 1), '%d %b %Y %H:%M:%S')
Exemple #16
0
            elif type == 'int':
                # note: on 64-bit machines int:s are 64-bit
                MIN_INT = -2147483648
                MAX_INT =  2147483647
                if db_type == 'int':
                    if int(value) < MIN_INT:
                        self.convertWarning(value, MIN_INT, type, db_type)
                        value = MIN_INT
                    if int(value) > MAX_INT:
                        self.convertWarning(value, MAX_INT, type, db_type)
                        value = MAX_INT
                return str(value)
            elif type == 'date':
                return value.isoformat()
            elif type == 'datetime':
                return strftime(value, '%Y-%m-%d %H:%M:%S')
            else:
                return str(value)

        return None

    def createSQLSelect(self, table, columns, whereMap, orderBy=None, 
                        forUpdate=False):
        columnStr = ', '.join(columns)
        whereStr = ''
        whereClause = ''
        values = []
        for column, value in whereMap.iteritems():
            whereStr += '%s%s = %%s' % \
                        (whereClause, column)
            values.append(value)
Exemple #17
0
            elif type == 'int':
                # note: on 64-bit machines int:s are 64-bit
                MIN_INT = -2147483648
                MAX_INT =  2147483647
                if db_type == 'int':
                    if int(value) < MIN_INT:
                        self.convertWarning(value, MIN_INT, type, db_type)
                        value = MIN_INT
                    if int(value) > MAX_INT:
                        self.convertWarning(value, MAX_INT, type, db_type)
                        value = MAX_INT
                return str(value)
            elif type == 'date':
                return value.isoformat()
            elif type == 'datetime':
                return strftime(value, '%Y-%m-%d %H:%M:%S')
            else:
                return str(value)

        return None

    def createSQLSelect(self, table, columns, whereMap, orderBy=None, 
                        forUpdate=False):
        columnStr = ', '.join(columns)
        whereStr = ''
        whereClause = ''
        values = []
        for column, value in whereMap.iteritems():
            whereStr += '%s%s = %%s' % \
                        (whereClause, column)
            values.append(value)
Exemple #18
0
 def save(self):
     return (self.id, self.type_id, self.name, self.user,
             strftime(self.mod_time, self.DATE_FORMAT),
             strftime(self.create_time, self.DATE_FORMAT), self.size,
             self.description, self.url)
 def _get_date(self):
     if self.db_date is not None:
         return strftime(self.db_date, '%d %b %Y %H:%M:%S')
     return strftime(datetime(1900,1,1), '%d %b %Y %H:%M:%S')