Пример #1
0
 def fact_from_log_entry(self, log_entry):
     # Get fact object to be deleted now.
     if log_entry["type"] == EventTypes.DELETED_FACT:
         return self.get_fact(log_entry["o_id"], id_is_internal=False)
     # Make sure we can create a fact object that will be deleted later
     # during this sync.
     if "card_t" not in log_entry:
         log_entry["card_t"] = "1"
         log_entry["c_time"] = "-1"
         log_entry["m_time"] = "-1"
     # Create fact object.
     data = {}
     for key, value in log_entry.iteritems():
         if key not in ["time", "type", "o_id", "c_time", "m_time",
             "card_t"]:
             data[key] = value
     if log_entry["card_t"] not in self.component_manager.card_type_by_id:
         self._activate_plugin_for_card_type(log_entry["card_t"])
     card_type = self.card_type_by_id(log_entry["card_t"])
     fact = Fact(data, card_type, log_entry["c_time"], log_entry["o_id"])
     fact.modification_time = log_entry["m_time"]
     if log_entry["type"] != EventTypes.ADDED_FACT:
         fact._id = self.con.execute("select _id from facts where id=?",
             (fact.id, )).fetchone()[0]
     return fact
Пример #2
0
 def fact(self, _id):
     # Create dictionary with fact.data.
     fact_data = {}
     query = QtSql.QSqlQuery(\
        "select key, value from data_for_fact where _fact_id=%d" % (_id, ))
     query.next()
     while query.isValid():
         fact_data[query.value(0)] = query.value(1)
         query.next()
     # Create fact.
     fact = Fact(fact_data, "dummy_id")
     fact._id = _id
     return fact
Пример #3
0
 def fact_from_log_entry(self, log_entry):
     # Work around legacy logs which contain duplicate deletion events.
     # Leftover from old bug, should not reoccur.
     if log_entry["type"] != EventTypes.ADDED_FACT and \
        not self.has_fact_with_id(log_entry["o_id"]):
         self.main_widget().show_information(\
     _("Deleting same fact twice during sync. Inform the developpers."))
         fact = Fact({}, log_entry["o_id"])
         fact._id = -1
         return fact
     # Get fact object to be deleted now.
     if log_entry["type"] == EventTypes.DELETED_FACT:
         return self.fact(log_entry["o_id"], is_id_internal=False)
     # Create fact object.
     fact_data = {}
     for key, value in log_entry.items():
         if key not in ["time", "type", "o_id"]:
             fact_data[key] = value
     fact = Fact(fact_data, log_entry["o_id"])
     if log_entry["type"] != EventTypes.ADDED_FACT:
         fact._id = self.con.execute("select _id from facts where id=?",
                                     (fact.id, )).fetchone()[0]
     return fact
Пример #4
0
 def fact(self, _id):
     # Create dictionary with fact.data.
     fact_data = {}
     query = QtSql.QSqlQuery(\
        "select key, value from data_for_fact where _fact_id=%d" % (_id, ))
     query.next()
     while query.isValid():
         fact_data[unicode(query.value(0).toString())] = \
             unicode(query.value(1).toString())
         query.next()
     # Create fact.
     fact = Fact(fact_data, "dummy_id")
     fact._id = _id
     return fact
Пример #5
0
 def fact_from_log_entry(self, log_entry):
     # Work around legacy logs which contain duplicate deletion events.
     # Leftover from old bug, should not reoccur.
     if log_entry["type"] != EventTypes.ADDED_FACT and \
        not self.has_fact_with_id(log_entry["o_id"]):
         self.main_widget().show_information(\
     _("Deleting same fact twice during sync. Inform the developpers."))                
         fact = Fact({}, log_entry["o_id"])
         fact._id = -1
         return fact             
     # Get fact object to be deleted now.
     if log_entry["type"] == EventTypes.DELETED_FACT:
         return self.fact(log_entry["o_id"], is_id_internal=False)
     # Create fact object.
     fact_data = {}
     for key, value in log_entry.iteritems():
         if key not in ["time", "type", "o_id"]:
             fact_data[key] = value
     fact = Fact(fact_data, log_entry["o_id"])
     if log_entry["type"] != EventTypes.ADDED_FACT:
         fact._id = self.con.execute("select _id from facts where id=?",
             (fact.id, )).fetchone()[0]                
     return fact
Пример #6
0
 def get_fact(self, id, id_is_internal):
     if id_is_internal:
         sql_res = self.con.execute("select * from facts where _id=?",
                                    (id, )).fetchone()
     else:
         sql_res = self.con.execute("select * from facts where id=?",
                                    (id, )).fetchone()            
     # Create dictionary with fact.data.
     data = dict([(cursor["key"], cursor["value"]) for cursor in
         self.con.execute("select * from data_for_fact where _fact_id=?",
         (sql_res["_id"], ))])            
     # Create fact. Note that for the card type, we turn to the component
     # manager as opposed to this database, as we would otherwise miss the
     # built-in system card types.
     fact = Fact(data, self.card_type_by_id(sql_res["card_type_id"]),
         creation_time=sql_res["creation_time"], id=sql_res["id"])
     fact._id = sql_res["_id"]
     fact.modification_time = sql_res["modification_time"]
     self._get_extra_data(sql_res, fact)
     return fact