예제 #1
0
    def add_fact(self, fact, temporary_activity=False):
        """Add fact. activity name can use the
        `[-]start_time[-end_time] activity@category, description #tag1 #tag2`
        syntax, or params can be stated explicitly.
        Params will take precedence over the derived values.
        start_time defaults to current moment.
        """
        if not fact.activity:
            return None

        serialized = fact.serialized_name()

        start_timestamp = timegm((fact.start_time
                                  or hamster_now()).timetuple())

        end_timestamp = fact.end_time or 0
        if end_timestamp:
            end_timestamp = timegm(end_timestamp.timetuple())

        new_id = self.conn.AddFact(serialized, start_timestamp, end_timestamp,
                                   temporary_activity)

        # TODO - the parsing should happen just once and preferably here
        # we should feed (serialized_activity, start_time, end_time) into AddFact and others
        return new_id
예제 #2
0
    def add_fact(self, fact, temporary_activity=False):
        """Add fact (Fact)."""
        assert fact.activity, "missing activity"

        if not fact.start_time:
            logger.info("Adding fact without any start_time is deprecated")
            fact.start_time = hamster_now()

        dbus_fact = to_dbus_fact(fact)
        new_id = self.conn.AddFactVerbatim(dbus_fact)

        return new_id
예제 #3
0
    def update_fact(self, fact_id, fact, temporary_activity=False):
        """Update fact values. See add_fact for rules.
        Update is performed via remove/insert, so the
        fact_id after update should not be used anymore. Instead use the ID
        from the fact dict that is returned by this function"""

        start_time = timegm((fact.start_time or hamster_now()).timetuple())

        end_time = fact.end_time or 0
        if end_time:
            end_time = timegm(end_time.timetuple())

        new_id = self.conn.UpdateFact(fact_id, fact.serialized_name(),
                                      start_time, end_time, temporary_activity)
        return new_id
예제 #4
0
 def stop_tracking(self, end_time=None):
     """Stop tracking current activity. end_time can be passed in if the
     activity should have other end time than the current moment"""
     end_time = timegm((end_time or hamster_now()).timetuple())
     return self.conn.StopTracking(end_time)