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
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
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
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
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
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
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
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)
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)
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
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
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
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