Пример #1
0
        def convert_from_str(value,type):
            def bool_conv(x):
                s = str(x).upper()
                if s == 'TRUE':
                    return True
                if s == 'FALSE':
                    return False

            if value is not None:
                if type == 'str':
                    return str(value)
                elif value.strip() != '':
                    if type == 'long':
                        return long(value)
                    elif type == 'float':
                        return float(value)
                    elif type == 'int':
                        return int(value)
                    elif type == 'bool':
                        return bool_conv(value)
                    elif type == 'date':
                        return date(*time_strptime(value, '%Y-%m-%d')[0:3])
                    elif type == 'datetime':
                        return datetime(*time_strptime(value, '%Y-%m-%d %H:%M:%S')[0:6])
            return None
Пример #2
0
        def convert_from_str(value,type):
            def bool_conv(x):
                s = str(x).upper()
                if s == 'TRUE':
                    return True
                if s == 'FALSE':
                    return False

            if value is not None:
                if type == 'str':
                    return str(value)
                elif value.strip() != '':
                    if type == 'long':
                        return long(value)
                    elif type == 'float':
                        return float(value)
                    elif type == 'int':
                        return int(value)
                    elif type == 'bool':
                        return bool_conv(value)
                    elif type == 'date':
                        return date(*time_strptime(value, '%Y-%m-%d')[0:3])
                    elif type == 'datetime':
                        return datetime(*time_strptime(value, '%Y-%m-%d %H:%M:%S')[0:6])
            return None
Пример #3
0
 def convertFromStr(self, value, type):
     if value is not None:
         if type == 'str':
             return str(value)
         elif value.strip() != '':
             if type == 'long':
                 try:
                     return long(value)
                 except ValueError:
                     return -1
             elif type == 'float':
                 return float(value)
             elif type == 'int':
                 try:
                     return int(value)
                 except ValueError:
                     if 'False' == value:
                         return -1
                     else:
                         return 0
             elif type == 'date':
                 return date(*time_strptime(value, '%Y-%m-%d')[0:3])
             elif type == 'datetime':
                 return datetime(*time_strptime(value, '%Y-%m-%d %H:%M:%S')[0:6])
     return None
Пример #4
0
 def convertFromStr(self, value, type):
     if value is not None:
         if type == 'str':
             return str(value)
         elif value.strip() != '':
             if type == 'long':
                 try:
                     return long(value)
                 except ValueError:
                     return -1
             elif type == 'float':
                 return float(value)
             elif type == 'int':
                 try:
                     return int(value)
                 except ValueError:
                     if 'False' == value:
                         return -1
                     else:
                         return 0
             elif type == 'date':
                 return date(*time_strptime(value, '%Y-%m-%d')[0:3])
             elif type == 'datetime':
                 return datetime(*time_strptime(value, '%Y-%m-%d %H:%M:%S')[0:6])
     return None
Пример #5
0
 def convertFromStr(self, value, type):
     if value is not None:
         if type == "str":
             return str(value)
         elif value.strip() != "":
             if type == "long":
                 return long(value)
             elif type == "float":
                 return float(value)
             elif type == "int":
                 return int(value)
             elif type == "date":
                 return date(*time_strptime(value, "%Y-%m-%d")[0:3])
             elif type == "datetime":
                 return datetime(*time_strptime(value, "%Y-%m-%d %H:%M:%S")[0:6])
     return None
Пример #6
0
 def convertFromDB(self, value, type, db_type):
     if value is not None:
         if type == "str":
             return str(value)
         elif type == "long":
             return long(value)
         elif type == "float":
             return float(value)
         elif type == "int":
             return int(value)
         elif type == "date":
             if db_type == "date":
                 return value
             else:
                 return date(*time_strptime(str(value), "%Y-%m-%d")[0:3])
         elif type == "datetime":
             if db_type == "datetime":
                 return value
             else:
                 return datetime(*time_strptime(str(value), "%Y-%m-%d %H:%M:%S")[0:6])
     return None
Пример #7
0
    def get_db_modification_time(self, obj_type=None):
        if obj_type is None:
            if self.obj_type is None:
                obj_type = DBVistrail.vtType 
            else:
                obj_type = self.obj_type

        ts = io.get_db_object_modification_time(self.get_connection(),
                                                self.obj_id,
                                                obj_type)
        ts = datetime(*time_strptime(str(ts).strip(), '%Y-%m-%d %H:%M:%S')[0:6])
        return ts
Пример #8
0
    def get_db_modification_time(self, obj_type=None):
        if obj_type is None:
            if self.obj_type is None:
                obj_type = DBVistrail.vtType 
            else:
                obj_type = self.obj_type

        ts = io.get_db_object_modification_time(self.get_connection(),
                                                self.obj_id,
                                                obj_type)
        ts = datetime(*time_strptime(str(ts).strip(), '%Y-%m-%d %H:%M:%S')[0:6])
        return ts
Пример #9
0
 def convertFromDB(self, value, type, db_type):
     if value is not None:
         if type == 'str':
             return str(value)
         elif type == 'long':
             return long(value)
         elif type == 'float':
             return float(value)
         elif type == 'int':
             return int(value)
         elif type == 'date':
             if db_type == 'date':
                 return value
             else:
                 return date(*time_strptime(str(value), '%Y-%m-%d')[0:3])
         elif type == 'datetime':
             if db_type == 'datetime':
                 return value
             else:
                 return datetime(
                     *time_strptime(str(value), '%Y-%m-%d %H:%M:%S')[0:6])
     return None
Пример #10
0
 def convertFromDB(self, value, type, db_type):
     if value is not None:
         if type == 'str':
             return str(value)
         elif type == 'long':
             return long(value)
         elif type == 'float':
             return float(value)
         elif type == 'int':
             return int(value)
         elif type == 'date':
             if db_type == 'date':
                 return value
             else:
                 return date(*time_strptime(str(value), '%Y-%m-%d')[0:3])
         elif type == 'datetime':
             if db_type == 'datetime':
                 return value
             else:
                 return datetime(*time_strptime(str(value),
                                                '%Y-%m-%d %H:%M:%S')[0:6])
     return None
Пример #11
0
 def _convert_value_node(self, node):
     """Convert a 'value' node (i.e. anything but 'key') into a Python data
     structure"""
     if node.tag == 'string':
         return self._content(node)
     elif node.tag == 'integer':
         return int(self._content(node))
     elif node.tag == 'real':
         return float(self._content(node))
     elif node.tag == 'date': #  <date>2004-07-05T13:29:29Z</date>
         return datetime.datetime(
             *time_strptime(self._content(node), '%Y-%m-%dT%H:%M:%SZ')[:5])
     elif node.tag == 'array':
         return [self._convert_value_node(n) for n in node.getchildren()]
     elif node.tag == 'dict':
         return dict([(self._content(n), self._convert_value_node(m))
             for n, m in group(node.getchildren(), 2)])
     else:
         raise ValueError(node.tag)
Пример #12
0
def convertDate(date):
    if date is not None and date != '':
        return datetime(*time_strptime(date, '%d %b %Y %H:%M:%S')[0:6])
    return datetime(1900, 1, 1)
Пример #13
0
def convertDate(date):
    if date is not None and date != '':
        return datetime(*time_strptime(date, '%d %b %Y %H:%M:%S')[0:6])
    return datetime(1900, 1, 1)
Пример #14
0
 def match(self, vistrail, action):
     if not action.date:
         return False
     t = time.mktime(time_strptime(action.date, "%d %b %Y %H:%M:%S"))
     return t >= self.date
Пример #15
0
 def match(self, entity):
     if not entity.mod_time:
         return False
     t = time.mktime(time_strptime(entity.mod_time, "%d %b %Y %H:%M:%S"))
     return t >= self.date
Пример #16
0
 def _set_date(self, date):
     if isinstance(date, datetime):
         self.db_date = date
     elif isinstance(date, basestring) and date.strip() != '':
         newDate = datetime(*time_strptime(date, '%d %b %Y %H:%M:%S')[0:6])
         self.db_date = newDate
Пример #17
0
 def _set_date(self, date):
     if isinstance(date, datetime):
         self.db_date = date
     elif isinstance(date, basestring) and date.strip() != '':
         newDate = datetime(*time_strptime(date, '%d %b %Y %H:%M:%S')[0:6])
         self.db_date = newDate
Пример #18
0
 def match(self, controller, action):
     if not action.date:
         return False
     t = time.mktime(time_strptime(action.date, "%d %b %Y %H:%M:%S"))
     return t <= self.date
Пример #19
0
 def match(self, vistrail, action):
     if not action.date:
         return False
     t = time.mktime(time_strptime(action.date, "%d %b %Y %H:%M:%S"))
     return t >= self.date
Пример #20
0
 def match(self, controller, action):
     if not action.date:
         return False
     t = time.mktime(time_strptime(action.date, "%d %b %Y %H:%M:%S"))
     return t <= self.date