예제 #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
파일: SQLite.py 프로젝트: bartosh/pomni
 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